Class: Hermitage::Configurator
- Inherits:
-
Object
- Object
- Hermitage::Configurator
- Defined in:
- lib/hermitage/configurator.rb
Class Method Summary collapse
-
.options_for(objects, options = {}) ⇒ Object
Returns full options hash for specified objects and options.
Instance Method Summary collapse
-
#initialize(config_name, &block) ⇒ Configurator
constructor
A new instance of Configurator.
- #respond_to?(method_name) ⇒ Boolean
Constructor Details
#initialize(config_name, &block) ⇒ Configurator
Returns a new instance of Configurator.
15 16 17 18 19 |
# File 'lib/hermitage/configurator.rb', line 15 def initialize(config_name, &block) Hermitage.configs[config_name] ||= {} @config = Hermitage.configs[config_name] self.instance_eval(&block) if block_given? end |
Class Method Details
.options_for(objects, options = {}) ⇒ Object
Returns full options hash for specified objects and options. It chooses config accoring to the class name of objects in passed array and merges default options with the chosen config and with passed options hash.
24 25 26 27 28 |
# File 'lib/hermitage/configurator.rb', line 24 def self.(objects, = {}) config_name = objects.first.class.to_s.pluralize.underscore.to_sym if defined?(Rails) && !objects.empty? config = Hermitage.configs[config_name] || Hermitage.configs[:default] Hermitage.configs[:default].merge(config).merge() end |
Instance Method Details
#respond_to?(method_name) ⇒ Boolean
11 12 13 |
# File 'lib/hermitage/configurator.rb', line 11 def respond_to?(method_name) Defaults.constants.include? method_name.upcase.to_sym || super end |