Class: Toppings::Config
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- Toppings::Config
- Defined in:
- lib/toppings/config.rb
Constant Summary collapse
- CONFIGS =
[]
Class Method Summary collapse
-
.app_config_path ⇒ Object
The app config path is based on the current directory, from where the toppings command is called.
- .custom_config ⇒ Object
- .custom_config_name ⇒ Object
- .custom_config_path ⇒ Object
- .default_config ⇒ Object
- .default_config_name ⇒ Object
- .default_config_path ⇒ Object
- .gem_config_path ⇒ Object
- .inject_config(config) ⇒ Object
- .joined_config ⇒ Object
- .load ⇒ Object
- .parsed_config(path) ⇒ Object
- .reload ⇒ Object
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Config
constructor
A new instance of Config.
Constructor Details
Class Method Details
.app_config_path ⇒ Object
The app config path is based on the current directory, from where the toppings command is called.
TODO: app_config path should be configurable by a thor param
75 76 77 |
# File 'lib/toppings/config.rb', line 75 def app_config_path Pathname.new('.').join('config') end |
.custom_config ⇒ Object
38 39 40 |
# File 'lib/toppings/config.rb', line 38 def custom_config @customs = parsed_config(custom_config_path) end |
.custom_config_name ⇒ Object
63 64 65 |
# File 'lib/toppings/config.rb', line 63 def custom_config_name 'toppings.json' end |
.custom_config_path ⇒ Object
55 56 57 |
# File 'lib/toppings/config.rb', line 55 def custom_config_path app_config_path.join custom_config_name end |
.default_config ⇒ Object
42 43 44 |
# File 'lib/toppings/config.rb', line 42 def default_config @defaults = parsed_config(default_config_path) end |
.default_config_name ⇒ Object
59 60 61 |
# File 'lib/toppings/config.rb', line 59 def default_config_name 'default.json' end |
.default_config_path ⇒ Object
51 52 53 |
# File 'lib/toppings/config.rb', line 51 def default_config_path gem_config_path.join default_config_name end |
.gem_config_path ⇒ Object
67 68 69 |
# File 'lib/toppings/config.rb', line 67 def gem_config_path Pathname.new(Toppings.gem_root).join('config') end |
.inject_config(config) ⇒ Object
33 34 35 36 |
# File 'lib/toppings/config.rb', line 33 def inject_config(config) CONFIGS << config reload end |
.joined_config ⇒ Object
27 28 29 30 31 |
# File 'lib/toppings/config.rb', line 27 def joined_config configs = CONFIGS.dup configs << custom_config configs.each_with_object({}) { |config, result_config| result_config.deep_merge!(config) } end |
.load ⇒ Object
19 20 21 |
# File 'lib/toppings/config.rb', line 19 def load @config ||= new(joined_config) end |
.parsed_config(path) ⇒ Object
46 47 48 49 |
# File 'lib/toppings/config.rb', line 46 def parsed_config(path) config_file = File.read(path) if File.exists?(path) JSON.parse(config_file || '{}') end |
.reload ⇒ Object
23 24 25 |
# File 'lib/toppings/config.rb', line 23 def reload @config = new(joined_config) end |