Class: ZAssets::Config
- Inherits:
-
Object
- Object
- ZAssets::Config
- Defined in:
- lib/zassets/config.rb
Constant Summary collapse
- DEFAULT_CONFIG_PATH =
'config/zassets.yaml'
- DEFAULT_OPTIONS =
{ verbose: false, host: '::1', port: 9292, server: :puma, plugins: [], engines: {}, base_url: '/assets', paths: %w[app], public_path: 'public', build_path: 'public/assets', build: [] }
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #default_config_file? ⇒ Boolean
- #default_options ⇒ Object
-
#initialize(options = {}) ⇒ Config
constructor
A new instance of Config.
- #load_options(filepath = DEFAULT_CONFIG_PATH) ⇒ Object
- #register_plugins! ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Config
Returns a new instance of Config.
21 22 23 24 25 26 27 28 |
# File 'lib/zassets/config.rb', line 21 def initialize( = {}) o = o.merge! if default_config_file? o.merge! ([:config_file]) if [:config_file] o.merge! @options = o register_plugins! end |
Instance Method Details
#[](key) ⇒ Object
55 56 57 |
# File 'lib/zassets/config.rb', line 55 def [](key) @options[key] end |
#[]=(key, value) ⇒ Object
59 60 61 |
# File 'lib/zassets/config.rb', line 59 def []=(key, value) @options[key] = value end |
#default_config_file? ⇒ Boolean
42 43 44 |
# File 'lib/zassets/config.rb', line 42 def default_config_file? File.exist? DEFAULT_CONFIG_PATH end |
#default_options ⇒ Object
30 31 32 |
# File 'lib/zassets/config.rb', line 30 def DEFAULT_OPTIONS.dup end |
#load_options(filepath = DEFAULT_CONFIG_PATH) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/zassets/config.rb', line 34 def (filepath = DEFAULT_CONFIG_PATH) return {} unless = YAML.load_file(filepath) .keys.each do |key| [(key.to_sym rescue key) || key] = .delete(key) end end |
#register_plugins! ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/zassets/config.rb', line 46 def register_plugins! return unless load_plugins! ::ZAssets::Plugins.constants.each do |plugin_module_name| plugin_module = ::ZAssets::Plugins.const_get(plugin_module_name) plugin_module::Registrant.new(self).register end end |