Module: Ops::Helpers

Defined in:
lib/ops/server/helpers.rb

Constant Summary collapse

'https://github.com/primedia'

Instance Method Summary collapse

Instance Method Details

#app_nameObject



9
10
11
12
13
14
15
16
17
18
# File 'lib/ops/server/helpers.rb', line 9

def app_name
  @app_name ||= begin
                  dirs = Dir.pwd.split('/')
                  if dirs.last =~ /^\d+$/
                    dirs[-3]
                  else
                    dirs.last
                  end.sub(/\.com$/, '')
                end
end


24
25
26
# File 'lib/ops/server/helpers.rb', line 24

def commit_link(commit)
  github_link 'commit', commit
end


28
29
30
# File 'lib/ops/server/helpers.rb', line 28

def github_link(resource, subresource)
  "<a href='#{GITHUB_ORG_LINK}/#{app_name}/#{resource}/#{subresource}'>#{subresource}</a>" unless subresource =~ /^Unknown/
end

#hostnameObject



5
6
7
# File 'lib/ops/server/helpers.rb', line 5

def hostname
  @hostname ||= `/bin/hostname` || 'Unknown'
end


32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ops/server/helpers.rb', line 32

def print_detail(object, indent = 0)
  output = ""
  if object.kind_of? Hash
    output << "{\n"
    output << object.collect { |key, value|
      "  " * indent + "  #{print_detail key} => #{print_detail value, indent+1}"
    }.join(",\n") << "\n"
    output << "  " * indent + "}"
  else
    output << object.inspect
  end
  output
end


20
21
22
# File 'lib/ops/server/helpers.rb', line 20

def version_link(version)
  github_link 'tree', version
end