Class: Attrify::DSL::Base
- Inherits:
-
Object
- Object
- Attrify::DSL::Base
- Defined in:
- lib/attrify/dsl/base.rb
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize ⇒ Base
constructor
A new instance of Base.
- #slot(name, attributes = nil, &block) ⇒ Object
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
6 7 8 |
# File 'lib/attrify/dsl/base.rb', line 6 def initialize @base = {} end |
Instance Method Details
#build ⇒ Object
10 11 12 13 |
# File 'lib/attrify/dsl/base.rb', line 10 def build(&) instance_eval(&) @base end |
#slot(name, attributes = nil, &block) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/attrify/dsl/base.rb', line 15 def slot(name, attributes = nil, &block) if block # If a block is provided, we need to create a nested structure @base[name] = self.class.new.build(&block) # Recursively build nested slots elsif attributes.is_a?(Hash) # If no block, but attributes are provided, add them directly @base[name] = attributes else raise ArgumentError, "Either attributes hash or a block is required" end end |