Module: Ohm::Typecast
- Defined in:
- lib/ohm/contrib/typecast.rb
Overview
Provides unobtrusive, non-explosive typecasting.Instead of exploding on set of an invalid value, this module takes the approach of just taking in parameters and letting you do validation yourself. The only thing this module does for you is the boilerplate casting you might need to do.
The Typecasted way
class Item < Ohm::Model include Ohm::Typecast attribute :price, Decimal attribute :posted, Time end item = Item.create(:price => "299", :posted => Time.now.utc) item = Item[item.id] item.price.class == Ohm::Types::Decimal # => true item.price.to_s == "299" # => true item.price * 2 == 598 # => true item.posted.strftime('%m/%d/%Y') # => works!!!
Defined Under Namespace
Modules: ClassMethods