Module: Ops::Helpers

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

Instance Method Summary collapse

Instance Method Details

#app_nameObject



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

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


22
23
24
# File 'lib/ops/server/helpers.rb', line 22

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


26
27
28
# File 'lib/ops/server/helpers.rb', line 26

def github_link(resource, subresource)
  "https://github.com/primedia/#{app_name}/#{resource}/#{subresource}" unless subresource =~ /^Unknown/
end

#hostnameObject



3
4
5
# File 'lib/ops/server/helpers.rb', line 3

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


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

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


18
19
20
# File 'lib/ops/server/helpers.rb', line 18

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