Module: Wrest::Components::AttributesContainer::Typecaster
- Included in:
- Resource::Base
- Defined in:
- lib/wrest/components/attributes_container/typecaster.rb
Overview
An extension to AttributesContainer that adds support for specifying how the values associated with certain attribute keys should be typecast.
This extension can be used in situations where the attributes hash consists of just strings with no associated tup information. For example, params recieved from a web browser may contain attributes like
'id' => '4', 'dateofbirth' => '1984-04-05'
and we’d like to have these cast to an integer and a date respectively, rather than have to deal with them as strings.
Defined Under Namespace
Modules: ClassMethods, InstanceMethods
Class Method Summary collapse
-
.included(klass) ⇒ Object
:nodoc:.
Class Method Details
.included(klass) ⇒ Object
:nodoc:
24 25 26 27 28 |
# File 'lib/wrest/components/attributes_container/typecaster.rb', line 24 def self.included(klass) #:nodoc: klass.extend Typecaster::ClassMethods klass.class_eval{ include Typecaster::InstanceMethods } klass.alias_method_chain :initialize, :typecasting end |