Class: HCast::AttributesParser::DSL

Inherits:
Object
  • Object
show all
Defined in:
lib/hcast/attributes_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDSL

Returns a new instance of DSL.



18
19
20
# File 'lib/hcast/attributes_parser.rb', line 18

def initialize
  @attributes = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/hcast/attributes_parser.rb', line 27

def method_missing(caster_name, *args, &block)
  attr_name = args[0]
  options   = args[1] || {}
  caster = HCast.casters[caster_name]

  check_caster_exists!(caster, caster_name)
  check_attr_name_valid!(attr_name)
  check_options_is_hash!(options)

  attribute = HCast::::Attribute.new(attr_name, caster, options)
  if block_given?
    attribute.children = HCast::AttributesParser.parse(&block)
  end
  attributes << attribute
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



16
17
18
# File 'lib/hcast/attributes_parser.rb', line 16

def attributes
  @attributes
end

Instance Method Details

#hash(*args, &block) ⇒ Object

Redefined becase each class has the built in hash method



23
24
25
# File 'lib/hcast/attributes_parser.rb', line 23

def hash(*args, &block)
  method_missing(:hash, *args, &block)
end