Module: HashCast::Caster::ClassMethods
- Defined in:
- lib/hashcast/caster.rb
Constant Summary collapse
- ALLOWED_OPTIONS =
[:string, :symbol]
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
92 93 94 95 96 97 |
# File 'lib/hashcast/caster.rb', line 92 def attributes(&block) raise ArgumentError, "You should provide block" unless block_given? attributes = HashCast::AttributesParser.parse(&block) self.instance_variable_set(:@attributes, attributes) end |
#cast(hash, options = {}) ⇒ Object
Performs casting
102 103 104 105 106 107 108 109 110 |
# File 'lib/hashcast/caster.rb', line 102 def cast(hash, = {}) check_attributes_defined! check_hash_given!(hash) () = () attributes_caster = HashCast::AttributesCaster.new(instance_variable_get(:@attributes), ) attributes_caster.cast(hash) end |