Module: HashCast::Caster::ClassMethods
- Defined in:
- lib/hash_cast/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/hash_cast/caster.rb', line 91 def attributes(&block) raise ArgumentError, "You should provide block" unless block_given? attributes = HashCast::AttributesParser.parse(&block) self.class_variable_set(:@@attributes, attributes) end |
#cast(hash, options = {}) ⇒ Object
Performs casting
101 102 103 |
# File 'lib/hash_cast/caster.rb', line 101 def cast(hash, = {}) cast_with_attributes(hash, get_attributes, ) end |