Skip to content
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 Types

Included with Toystore are several types (listed in lib/toy/extensions):

Custom Types

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
Clone this wiki locally