Sha256: d5f7607b4872a08daa1b731f76c9b8a58a6dcbf6fd3ffaaa2706abd7fbe76c81
Contents?: true
Size: 950 Bytes
Versions: 2
Compression:
Stored size: 950 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 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 User.adapter.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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
toystore-0.13.2 | examples/attributes_virtual.rb |
toystore-0.13.1 | examples/attributes_virtual.rb |