Class: Attrify::VariantConfig

Inherits:
Hash
  • Object
show all
Includes:
MergeableAttributes
Defined in:
lib/attrify/variant_config.rb

Defined Under Namespace

Modules: MergeableAttributes

Instance Method Summary collapse

Methods included from MergeableAttributes

#<<

Constructor Details

#initialize(*args) ⇒ VariantConfig

Returns a new instance of VariantConfig.



17
18
19
20
21
# File 'lib/attrify/variant_config.rb', line 17

def initialize(*args)
  super
  # missing keys auto-initialize as new AttributeSet instances.
  self.default_proc = proc { |hash, key| hash[key] = self.class.new }
end

Instance Method Details

#[]=(key, value) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/attrify/variant_config.rb', line 23

def []=(key, value)
  # Convert plain hashes to AttributeSet instances.
  if value.is_a?(Hash) && !value.is_a?(self.class)
    value = self.class.new.merge(value)
  end
  super
end

#set(**args) ⇒ Object



31
32
33
34
35
# File 'lib/attrify/variant_config.rb', line 31

def set(**args)
  clear
  merge!(args)
  self
end