Class: Attrify::DSL::Engine

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEngine

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_attrObject (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

#compoundsObject (readonly)

Returns the value of attribute compounds.



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

def compounds
  @compounds
end

#defaultsObject (readonly)

Returns the value of attribute defaults.



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

def defaults
  @defaults
end

#variantsObject (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

#buildObject



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

#variant(name) ⇒ Object



34
35
36
# File 'lib/attrify/dsl/engine.rb', line 34

def variant(name, &)
  @variants[name] = Variant.new.build(&)
end