Module: Ops

Defined in:
lib/version.rb,
lib/ops/common.rb,
lib/ops/console.rb

Defined Under Namespace

Modules: Console

Class Method Summary collapse

Class Method Details

.has_bash?Boolean

Returns:

  • (Boolean)


15
16
17
18
# File 'lib/ops/common.rb', line 15

def self.has_bash?
  `which bash`
  ( $? == 0 ) ? true : false
end

.pwd_dirObject



8
9
10
11
12
13
# File 'lib/ops/common.rb', line 8

def self.pwd_dir
  Pathname.new( Dir.pwd ).ascend do | p |
    return p if File.exists? File.join( p, 'config.json' )
  end 
  nil
end

.read_configObject



20
21
22
23
24
25
26
27
28
# File 'lib/ops/common.rb', line 20

def self.read_config
  config_file = File.join( self.pwd_dir, "config.json" )

  begin
    config = JSON.parse File.read( config_file )
  rescue JSON::ParserError
    raise IOError, "Error parsing config file: #{ config_file }."
  end
end

.read_hostsObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ops/common.rb', line 30

def self.read_hosts
  config = read_config

  hosts = {}

  hosts_files = [
    File.join( self.pwd_dir, "hosts.json" ),
    File.join( self.pwd_dir, 'tmp' ,"hosts.json" ), ]

  hosts_files.each do | file |
    if File.exists? file
      begin
        json = JSON.parse File.read( file )
        json.each do | n, i |
          hosts[ n ] =  Host::Default.new( n, i, config )
        end
      rescue JSON::ParserError => e
        raise( IOError,
          "Error parsing hosts file: #{ file }. #{ e.message }" )
      end
    end
  end

  hosts
end

.root_dirObject



3
4
5
6
# File 'lib/ops/common.rb', line 3

def self.root_dir
  File.expand_path(
    File.join( File.dirname( __FILE__ ), "..", ".." ) )
end

.versionObject



3
4
5
# File 'lib/version.rb', line 3

def self.version
  "0.0.7"
end