Class: Clicoder::Config
- Inherits:
-
Object
- Object
- Clicoder::Config
- Defined in:
- lib/clicoder/config.rb
Instance Attribute Summary collapse
-
#global ⇒ Object
Returns the value of attribute global.
-
#local ⇒ Object
Returns the value of attribute local.
Instance Method Summary collapse
- #asset(asset_name) ⇒ Object
- #get(*keys) ⇒ Object
-
#global_config_dir ⇒ Object
NOTE: This is not a class variable in order to evaluate stubbed ENV on each RSpec run.
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #merged_config ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
7 8 9 10 11 12 |
# File 'lib/clicoder/config.rb', line 7 def initialize global_config_file = "#{global_config_dir}/config.yml" @global = File.exists?(global_config_file) ? YAML::load_file(global_config_file) : {} local_config_file = '.config.yml' @local = File.exists?(local_config_file) ? YAML::load_file(local_config_file) : {} end |
Instance Attribute Details
#global ⇒ Object
Returns the value of attribute global.
5 6 7 |
# File 'lib/clicoder/config.rb', line 5 def global @global end |
#local ⇒ Object
Returns the value of attribute local.
5 6 7 |
# File 'lib/clicoder/config.rb', line 5 def local @local end |
Instance Method Details
#asset(asset_name) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/clicoder/config.rb', line 19 def asset(asset_name) site_name = get('site') file_name = get(site_name, asset_name) if file_name.empty? file_name = get('default', asset_name) end unless file_name.empty? return File.(file_name, global_config_dir) else return '' end end |
#get(*keys) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/clicoder/config.rb', line 37 def get(*keys) conf = merged_config begin keys.each do |key| conf = conf[key] end return conf.nil? ? '' : conf rescue return '' end end |
#global_config_dir ⇒ Object
NOTE: This is not a class variable in order to evaluate stubbed ENV on each RSpec run
15 16 17 |
# File 'lib/clicoder/config.rb', line 15 def global_config_dir @global_config_dir ||= "#{ENV['HOME']}/.clicoder.d" end |
#merged_config ⇒ Object
33 34 35 |
# File 'lib/clicoder/config.rb', line 33 def merged_config @merged_config ||= global.merge(local) end |