Class: MagicLamp::DefaultsManager
- Inherits:
-
Object
- Object
- MagicLamp::DefaultsManager
- Defined in:
- lib/magic_lamp/defaults_manager.rb
Instance Attribute Summary collapse
-
#configuration ⇒ Object
Returns the value of attribute configuration.
-
#defaults ⇒ Object
Returns the value of attribute defaults.
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
- #all_defaults(settings) ⇒ Object
- #branch(defaults_managers = [self]) ⇒ Object
- #define(new_defaults = {}, &block) ⇒ Object
-
#initialize(configuration, defaults, parent = nil) ⇒ DefaultsManager
constructor
A new instance of DefaultsManager.
- #merge_with_defaults(settings) ⇒ Object
- #register_fixture(options = {}, &block) ⇒ Object
Constructor Details
#initialize(configuration, defaults, parent = nil) ⇒ DefaultsManager
Returns a new instance of DefaultsManager.
5 6 7 8 9 |
# File 'lib/magic_lamp/defaults_manager.rb', line 5 def initialize(configuration, defaults, parent = nil) self.configuration = configuration self.defaults = defaults self.parent = parent end |
Instance Attribute Details
#configuration ⇒ Object
Returns the value of attribute configuration.
3 4 5 |
# File 'lib/magic_lamp/defaults_manager.rb', line 3 def configuration @configuration end |
#defaults ⇒ Object
Returns the value of attribute defaults.
3 4 5 |
# File 'lib/magic_lamp/defaults_manager.rb', line 3 def defaults @defaults end |
#parent ⇒ Object
Returns the value of attribute parent.
3 4 5 |
# File 'lib/magic_lamp/defaults_manager.rb', line 3 def parent @parent end |
Instance Method Details
#all_defaults(settings) ⇒ Object
20 21 22 |
# File 'lib/magic_lamp/defaults_manager.rb', line 20 def all_defaults(settings) [configuration.global_defaults, *branch.map(&:defaults), settings] end |
#branch(defaults_managers = [self]) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/magic_lamp/defaults_manager.rb', line 11 def branch(defaults_managers = [self]) ancestor = defaults_managers.first.parent if ancestor.nil? defaults_managers else branch([ancestor, *defaults_managers]) end end |
#define(new_defaults = {}, &block) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/magic_lamp/defaults_manager.rb', line 34 def define(new_defaults = {}, &block) raise ArgumentError, "`#{__method__}` requires a block" if block.nil? new_manager = self.class.new(configuration, new_defaults, self) new_manager.instance_eval(&block) new_manager end |
#merge_with_defaults(settings) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/magic_lamp/defaults_manager.rb', line 24 def merge_with_defaults(settings) all_defaults(settings).each_with_object({}) do |defaults_hash, merged_defaults_hash| merged_namespaces = merge_namespaces(merged_defaults_hash, defaults_hash) all_extensions = combine_extensions(merged_defaults_hash, defaults_hash) merged_defaults_hash.merge!(defaults_hash) merged_defaults_hash[:namespace] = merged_namespaces if merged_namespaces.present? merged_defaults_hash[:extend] = all_extensions end end |
#register_fixture(options = {}, &block) ⇒ Object
41 42 43 44 |
# File 'lib/magic_lamp/defaults_manager.rb', line 41 def register_fixture( = {}, &block) = merge_with_defaults() MagicLamp.register_fixture(, &block) end |