Class: Attrify::DSL::NestedVariant

Inherits:
Object
  • Object
show all
Defined in:
lib/attrify/dsl/nested_variant.rb

Instance Method Summary collapse

Constructor Details

#initializeNestedVariant

Returns a new instance of NestedVariant.



6
7
8
# File 'lib/attrify/dsl/nested_variant.rb', line 6

def initialize
  @variants = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/attrify/dsl/nested_variant.rb', line 23

def method_missing(name, *args, &block)
  # Handle the case where the slot is provided as a block
  if block
    @variants[name] = instance_eval(&block)
  # Handle the case where the slot is provided directly as a hash
  elsif args.length == 1 && args[0].is_a?(Hash)
    @variants[name] = args[0]
  else
    super
  end
end

Instance Method Details

#buildObject



10
11
12
13
# File 'lib/attrify/dsl/nested_variant.rb', line 10

def build(&)
  instance_eval(&)
  @variants
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/attrify/dsl/nested_variant.rb', line 19

def respond_to_missing?(name, include_private = false)
  true
end

#slot(name, attributes) ⇒ Object



15
16
17
# File 'lib/attrify/dsl/nested_variant.rb', line 15

def slot(name, attributes)
  @variants[name] = attributes
end