Class: HCast::AttributesParser::DSL
- Inherits:
-
Object
- Object
- HCast::AttributesParser::DSL
- Defined in:
- lib/hcast/attributes_parser.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Instance Method Summary collapse
-
#hash(*args, &block) ⇒ Object
Redefined becase each class has the built in hash method.
-
#initialize ⇒ DSL
constructor
A new instance of DSL.
- #method_missing(caster_name, *args, &block) ⇒ Object
Constructor Details
#initialize ⇒ DSL
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] = args[1] || {} caster = HCast.casters[caster_name] check_caster_exists!(caster, caster_name) check_attr_name_valid!(attr_name) () attribute = HCast::Metadata::Attribute.new(attr_name, caster, ) if block_given? attribute.children = HCast::AttributesParser.parse(&block) end attributes << attribute end |
Instance Attribute Details
#attributes ⇒ Object (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 |