Class: Fhcap::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/fhcap/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Config

Returns a new instance of Config.



11
12
13
# File 'lib/fhcap/config.rb', line 11

def initialize(options = {})
  @config_file = File.expand_path(options[:config_file] || default_config_file)
end

Instance Attribute Details

#config_fileObject (readonly)

Returns the value of attribute config_file.



9
10
11
# File 'lib/fhcap/config.rb', line 9

def config_file
  @config_file
end

Instance Method Details

#[](attrib) ⇒ Object



19
20
21
# File 'lib/fhcap/config.rb', line 19

def [](attrib)
  data[attrib]
end

#[]=(attr, val) ⇒ Object



23
24
25
# File 'lib/fhcap/config.rb', line 23

def []=(attr, val)
  data[attr] = val
end

#dataObject



27
28
29
# File 'lib/fhcap/config.rb', line 27

def data
  @data ||= read
end

#default_config_fileObject



46
47
48
# File 'lib/fhcap/config.rb', line 46

def default_config_file
  File.join(default_dir, 'fhcap.json')
end

#default_dirObject



42
43
44
# File 'lib/fhcap/config.rb', line 42

def default_dir
  File.join(Dir.home, 'fhcap')
end

#exists?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/fhcap/config.rb', line 15

def exists?
  File.exist?(@config_file)
end

#fh_src_dirObject



62
63
64
# File 'lib/fhcap/config.rb', line 62

def fh_src_dir
  data[:fh_src_dir] || File.join(default_dir, 'repos')
end

#fhcap_configObject

Generates the immutable fhcap configuration and reasonable defaults.



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/fhcap/config.rb', line 71

def fhcap_config
  @fhcap_config ||= {
      :repos_dir => File.join(default_dir, 'repos'),
      :fh_src_dir => File.join(default_dir, 'repos'),
      :repos => {
          :fhcap => {
              :url => '[email protected]:fheng/fhcap.git',
              :archives => {
                  :cookbooks => fhcap_cookbook_archive_url
              }
          },
          :"fhcap-dev" => {
              :clusters_dir => 'organisations',
              :url => '[email protected]:fheng/fhcap-dev.git'
          }
      },
      :knife_dir => File.join(default_dir, '.chef'),
      :knife => {
          :local => {
              :chef_server_url => 'http://127.0.0.1:7799',
              :node_name => Etc.getlogin
          },
          :bob => {
              :chef_server_url => 'https://bob.feedhenry.net:8443',
              :node_name => Etc.getlogin
          }
      }
  }
end

#fhcap_cookbook_archive_urlObject



66
67
68
# File 'lib/fhcap/config.rb', line 66

def fhcap_cookbook_archive_url
  'https://s3-eu-west-1.amazonaws.com/fhcap/fhcap-cookbooks/fhcap-cookbooks-39c5f7b38bb69ccf9fbd367b39a777b83f15d1de.tgz'
end

#fhcap_empty_configObject



101
102
103
104
105
106
107
108
109
110
111
# File 'lib/fhcap/config.rb', line 101

def fhcap_empty_config
  @fhcap_config ||= {
      :repos_dir => File.join(default_dir, 'repos'),
      :fh_src_dir => File.join(default_dir, 'repos'),
      :repos => {
      },
      :knife_dir => File.join(default_dir, '.chef'),
      :knife => {
      }
  }
end

#knife_dirObject



50
51
52
# File 'lib/fhcap/config.rb', line 50

def knife_dir
  data[:knife_dir] || File.join(default_dir, '.chef')
end

#readObject



35
36
37
38
39
40
# File 'lib/fhcap/config.rb', line 35

def read
  unless exists?
    raise "FHCAP Config file #{@config_file} does not exist."
  end
  symbolize_keys_deep(JSON.parse(IO.read(@config_file)))
end

#reloadObject



31
32
33
# File 'lib/fhcap/config.rb', line 31

def reload
  @data = read
end

#repos_dirObject



54
55
56
# File 'lib/fhcap/config.rb', line 54

def repos_dir
  data[:repos_dir] || File.join(default_dir, 'repos')
end

#tmp_dirObject



58
59
60
# File 'lib/fhcap/config.rb', line 58

def tmp_dir
  File.join(default_dir, 'tmp')
end