Class: Attrify::DSL::Compound

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

Instance Method Summary collapse

Constructor Details

#initializeCompound

Returns a new instance of Compound.



8
9
10
# File 'lib/attrify/dsl/compound.rb', line 8

def initialize
  @compounds = {}
end

Instance Method Details

#buildObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/attrify/dsl/compound.rb', line 12

def build(&)
  # Capture the result of the block execution
  result = instance_eval(&)

  # If the result is a hash and no slots were explicitly set, treat it as compound attributes
  if result.is_a?(Hash) && @compounds.empty?
    @compounds.merge!(result)
  end

  @compounds
end

#slot(name, attributes) ⇒ Object

Explicit slot handling



25
26
27
# File 'lib/attrify/dsl/compound.rb', line 25

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