Module: HCast::Caster::ClassMethods
- Defined in:
- lib/hcast/caster.rb
Instance Method Summary collapse
-
#attributes(&block) ⇒ Object
Defines casting rules.
-
#cast(hash, options = {}) ⇒ Object
Performs casting.
Instance Method Details
#attributes(&block) ⇒ Object
Defines casting rules
91 92 93 94 95 96 |
# File 'lib/hcast/caster.rb', line 91 def attributes(&block) raise ArgumentError, "You should provide block" unless block_given? attributes = HCast::AttributesParser.parse(&block) self.class_variable_set(:@@attributes, attributes) end |
#cast(hash, options = {}) ⇒ Object
Performs casting
101 102 103 104 105 106 107 108 109 |
# File 'lib/hcast/caster.rb', line 101 def cast(hash, = {}) check_attributes_defined! check_hash_given!(hash) () () attributes_caster = HCast::AttributesCaster.new(class_variable_get(:@@attributes), ) attributes_caster.cast(hash) end |