Class: Fhcap::Config
- Inherits:
-
Object
- Object
- Fhcap::Config
- Defined in:
- lib/fhcap/config.rb
Instance Attribute Summary collapse
-
#config_file ⇒ Object
readonly
Returns the value of attribute config_file.
Instance Method Summary collapse
- #[](attrib) ⇒ Object
- #[]=(attr, val) ⇒ Object
- #data ⇒ Object
- #default_config_file ⇒ Object
- #default_dir ⇒ Object
- #exists? ⇒ Boolean
- #fh_src_dir ⇒ Object
-
#fhcap_config ⇒ Object
Generates the immutable fhcap configuration and reasonable defaults.
- #fhcap_cookbook_archive_url ⇒ Object
- #fhcap_empty_config ⇒ Object
-
#initialize(options = {}) ⇒ Config
constructor
A new instance of Config.
- #knife_dir ⇒ Object
- #read ⇒ Object
- #reload ⇒ Object
- #repos_dir ⇒ Object
- #tmp_dir ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Config
Returns a new instance of Config.
11 12 13 |
# File 'lib/fhcap/config.rb', line 11 def initialize( = {}) @config_file = File.([: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
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 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_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/fhcap-cookbooks-39c5f7b38bb69ccf9fbd367b39a777b83f15d1de.tgz' end |
#fhcap_empty_config ⇒ Object
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_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 |