class Toppings::Config
Constants
- CONFIGS
Public Class Methods
app_config_path()
click to toggle source
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
# File lib/toppings/config.rb, line 75 def app_config_path Pathname.new('.').join('config') end
custom_config()
click to toggle source
# File lib/toppings/config.rb, line 38 def custom_config @customs = parsed_config(custom_config_path) end
custom_config_name()
click to toggle source
# File lib/toppings/config.rb, line 63 def custom_config_name 'toppings.json' end
custom_config_path()
click to toggle source
# File lib/toppings/config.rb, line 55 def custom_config_path app_config_path.join custom_config_name end
default_config()
click to toggle source
# File lib/toppings/config.rb, line 42 def default_config @defaults = parsed_config(default_config_path) end
default_config_name()
click to toggle source
# File lib/toppings/config.rb, line 59 def default_config_name 'default.json' end
default_config_path()
click to toggle source
# File lib/toppings/config.rb, line 51 def default_config_path gem_config_path.join default_config_name end
gem_config_path()
click to toggle source
# File lib/toppings/config.rb, line 67 def gem_config_path Pathname.new(Toppings.gem_root).join('config') end
inject_config(config)
click to toggle source
# File lib/toppings/config.rb, line 33 def inject_config(config) CONFIGS << config reload end
joined_config()
click to toggle source
# 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()
click to toggle source
# File lib/toppings/config.rb, line 19 def load @config ||= new(joined_config) end
new(options = {})
click to toggle source
Calls superclass method
# File lib/toppings/config.rb, line 10 def initialize(options = {}) super() options.each do |option, value| send "#{option}=", value.kind_of?(Hash) ? Toppings::Config.new(value) : value end end
parsed_config(path)
click to toggle source
# 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()
click to toggle source
# File lib/toppings/config.rb, line 23 def reload @config = new(joined_config) end