Sha256: 9f2178354d1f216acc438a253f4a984cedbea483d7401b07c0e687ff65f5293b
Contents?: true
Size: 981 Bytes
Versions: 8
Compression:
Stored size: 981 Bytes
Contents
require 'pp' require 'pathname' require 'rubygems' require 'adapter/memory' root_path = Pathname(__FILE__).dirname.join('..').expand_path lib_path = root_path.join('lib') $:.unshift(lib_path) require 'toystore' class User include Toy::Store store :memory, {} attribute :email, String attribute :crypted_password, String attribute :password, String, :virtual => true attribute :password_confirmation, String, :virtual => true before_validation :encrypt_password private def encrypt_password self.crypted_password = encrypt(password) end def encrypt(password) password # do something magical here end end user = User.create({ :email => 'nunemaker@gmail.com', :password => 'testing', :password_confirmation => 'testing', }) pp Marshal.load(User.store.client[user.id]) # Virtual attributes are never persisted. In the data store, only email and crypted_password are stored. # {"crypted_password"=>"testing", "email"=>"nunemaker@gmail.com"}
Version data entries
8 entries across 8 versions & 1 rubygems