Class: ZAssets::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/zassets/config.rb

Constant Summary collapse

DEFAULT_CONFIG_PATH =
'config/zassets.yaml'.freeze
DEFAULT_OPTIONS =
{
  verbose:      false,
  host:         '::1',
  port:         9292,
  plugins:      [],
  engines:      {},
  base_url:     '/assets',
  paths:        %w[app],
  public_path:  'public',
  build_path:   'public/assets',
  build:        []
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ Config

Returns a new instance of Config.



20
21
22
23
24
25
26
27
# File 'lib/zassets/config.rb', line 20

def initialize **options
  o = default_options
  o.merge! load_options if default_config_file?
  o.merge! load_options(options[:config_file]) if options[:config_file]
  o.merge! options
  @options = o
  register_plugins!
end

Instance Method Details

#[](key) ⇒ Object



50
51
52
# File 'lib/zassets/config.rb', line 50

def [] key
  @options[key]
end

#[]=(key, value) ⇒ Object



54
55
56
# File 'lib/zassets/config.rb', line 54

def []= key, value
  @options[key] = value
end

#default_config_file?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/zassets/config.rb', line 38

def default_config_file?
  File.exist?(DEFAULT_CONFIG_PATH)
end

#default_optionsObject



29
30
31
# File 'lib/zassets/config.rb', line 29

def default_options
  DEFAULT_OPTIONS.dup
end

#load_options(filepath = DEFAULT_CONFIG_PATH) ⇒ Object



33
34
35
36
# File 'lib/zassets/config.rb', line 33

def load_options filepath = DEFAULT_CONFIG_PATH
  return {} unless options = YAML.load_file(filepath)
  symbolize_keys options
end

#register_plugins!Object



42
43
44
45
46
47
48
# File 'lib/zassets/config.rb', line 42

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