forked from zerohistory/toystore
-
Notifications
You must be signed in to change notification settings - Fork 12
Types
jnunemaker edited this page Nov 14, 2012
·
6 revisions
A Toystore type is anything with to_store and from_store class methods (also optionally a store_default).
Included with Toystore are several types (listed in lib/toy/extensions):
You can make your own types by just defining to_store and from_store class methods. For example, a downcased string:
class DowncasedString
def self.to_store(value, *)
return if value.nil?
value.to_s.downcase
end
def self.from_store(value, *)
to_store(value)
end
end
You could then use this type like so:
class User
include Toy::Store
adapter :memory, {}
attribute :email, DowncasedString
end