Class: ZAssets::Config

Inherits:
Object
  • Object
show all
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

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(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



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

Returns:

  • (Boolean)


42
43
44
# File 'lib/zassets/config.rb', line 42

def default_config_file?
  File.exist? DEFAULT_CONFIG_PATH
end

#default_optionsObject



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

def default_options
  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 load_options(filepath = DEFAULT_CONFIG_PATH)
  return {} unless options = YAML.load_file(filepath)
  options.keys.each do |key|
    options[(key.to_sym rescue key) || key] = options.delete(key)
  end
  options
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