Module: Wrest::Components::Container::Typecaster

Defined in:
lib/wrest/components/container/typecaster.rb

Overview

An extension to Container 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, Helpers, InstanceMethods

Class Method Summary collapse

Class Method Details

.included(klass) ⇒ Object

:nodoc:



24
25
26
27
28
# File 'lib/wrest/components/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