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_file ⇒ Object (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

#data ⇒ Object



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

def data
  @data ||= read
end

#default_config_file ⇒ Object



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

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

#default_dir ⇒ Object



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_dir ⇒ Object



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_config ⇒ Object

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
# 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 => {
          :bob => {
              :chef_server_url => 'https://bob.feedhenry.net:8443',
              :node_name => Etc.getlogin
          }
      }
  }
end

#fhcap_cookbook_archive_url ⇒ Object



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-0fa68747b476f7ee555a94483877969a30133e76.tgz'
end

#knife_dir ⇒ Object



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

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

#read ⇒ Object



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

#reload ⇒ Object



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

def reload
  @data = read
end

#repos_dir ⇒ Object



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

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

#tmp_dir ⇒ Object



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

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