Class: Attrify::DSL::Engine
- Inherits:
-
Object
- Object
- Attrify::DSL::Engine
- Defined in:
- lib/attrify/dsl/engine.rb
Instance Attribute Summary collapse
-
#base_attr ⇒ Object
readonly
Returns the value of attribute base_attr.
-
#compounds ⇒ Object
readonly
Returns the value of attribute compounds.
-
#defaults ⇒ Object
readonly
Returns the value of attribute defaults.
-
#variants ⇒ Object
readonly
Returns the value of attribute variants.
Instance Method Summary collapse
- #base(input = nil, &block) ⇒ Object
- #build ⇒ Object
- #compound(variants) ⇒ Object
- #default(defaults) ⇒ Object
-
#initialize ⇒ Engine
constructor
A new instance of Engine.
- #variant(name) ⇒ Object
Constructor Details
#initialize ⇒ Engine
Returns a new instance of Engine.
12 13 14 15 16 17 |
# File 'lib/attrify/dsl/engine.rb', line 12 def initialize @base_attr = {} @variants = {} @defaults = {} @compounds = [] end |
Instance Attribute Details
#base_attr ⇒ Object (readonly)
Returns the value of attribute base_attr.
10 11 12 |
# File 'lib/attrify/dsl/engine.rb', line 10 def base_attr @base_attr end |
#compounds ⇒ Object (readonly)
Returns the value of attribute compounds.
10 11 12 |
# File 'lib/attrify/dsl/engine.rb', line 10 def compounds @compounds end |
#defaults ⇒ Object (readonly)
Returns the value of attribute defaults.
10 11 12 |
# File 'lib/attrify/dsl/engine.rb', line 10 def defaults @defaults end |
#variants ⇒ Object (readonly)
Returns the value of attribute variants.
10 11 12 |
# File 'lib/attrify/dsl/engine.rb', line 10 def variants @variants end |
Instance Method Details
#base(input = nil, &block) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/attrify/dsl/engine.rb', line 24 def base(input = nil, &block) if block @base_attr = Base.new.build(&block) elsif input.is_a?(Hash) @base_attr = input else raise ArgumentError, "Expected a block or a hash" end end |
#build ⇒ Object
19 20 21 22 |
# File 'lib/attrify/dsl/engine.rb', line 19 def build(&) instance_eval(&) self end |
#compound(variants) ⇒ Object
38 39 40 |
# File 'lib/attrify/dsl/engine.rb', line 38 def compound(variants, &) @compounds.concat([{variants: variants, attributes: Compound.new.build(&)}]) end |
#default(defaults) ⇒ Object
42 43 44 |
# File 'lib/attrify/dsl/engine.rb', line 42 def default(defaults) @defaults = defaults end |