Class: Toppings::Config
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- Toppings::Config
- Defined in:
- lib/toppings/config.rb
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
- .joined_config ⇒ Object
- .load ⇒ Object
- .parsed_config(path) ⇒ Object
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize(options = {}) ⇒ Config
Returns a new instance of Config.
8 9 10 11 12 13 14 |
# File 'lib/toppings/config.rb', line 8 def initialize( = {}) super() .each do |option, value| send "#{option}=", value.kind_of?(Hash) ? Toppings::Config.new(value) : value end end |
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
62 63 64 |
# File 'lib/toppings/config.rb', line 62 def app_config_path Pathname.new('.').join('config') end |
.custom_config ⇒ Object
25 26 27 |
# File 'lib/toppings/config.rb', line 25 def custom_config @customs = parsed_config(custom_config_path) end |
.custom_config_name ⇒ Object
50 51 52 |
# File 'lib/toppings/config.rb', line 50 def custom_config_name 'toppings.json' end |
.custom_config_path ⇒ Object
42 43 44 |
# File 'lib/toppings/config.rb', line 42 def custom_config_path app_config_path.join custom_config_name end |
.default_config ⇒ Object
29 30 31 |
# File 'lib/toppings/config.rb', line 29 def default_config @defaults = parsed_config(default_config_path) end |
.default_config_name ⇒ Object
46 47 48 |
# File 'lib/toppings/config.rb', line 46 def default_config_name 'default.json' end |
.default_config_path ⇒ Object
38 39 40 |
# File 'lib/toppings/config.rb', line 38 def default_config_path gem_config_path.join default_config_name end |
.gem_config_path ⇒ Object
54 55 56 |
# File 'lib/toppings/config.rb', line 54 def gem_config_path Pathname.new(Toppings.gem_root).join('config') end |
.joined_config ⇒ Object
21 22 23 |
# File 'lib/toppings/config.rb', line 21 def joined_config default_config.deep_merge(custom_config) end |
.load ⇒ Object
17 18 19 |
# File 'lib/toppings/config.rb', line 17 def load @config = new(joined_config) end |
.parsed_config(path) ⇒ Object
33 34 35 36 |
# File 'lib/toppings/config.rb', line 33 def parsed_config(path) config_file = File.read(path) if File.exists?(path) JSON.parse(config_file || '{}') end |