Skip to content

Instantly share code, notes, and snippets.

@sinefunc
Created May 17, 2010 18:33
Show Gist options
  • Save sinefunc/404075 to your computer and use it in GitHub Desktop.
Save sinefunc/404075 to your computer and use it in GitHub Desktop.
class Post < Ohm::Model
include Ohm::Typecast
attribute :price, Decimal
end
post = Post.new(:price => "FooBar")
post.price == "FooBar"
# => true
post.valid?
# raises Ohm::Typecast::MissingValidation, with message to add an assert_type_decimal :price"
class Post
def validate
assert_type_decimal :price
end
end
post = Post.new(:price => "FooBar")
post.valid?
post.errors == [[:price, :not_decimal]]
# => true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment