Sha256: 1335470d54057010a3223a42b4a89d27f8e2e2ffba93d7b259bab9606d20e564
Contents?: true
Size: 1.31 KB
Versions: 9
Compression:
Stored size: 1.31 KB
Contents
module SinatraMore module DatamapperOrmGen DM = <<-DM module DataMapperInitializer def self.registered(app) app.configure(:development) { DataMapper.setup(:default, 'sqlite3::memory:') } app.configure(:production) { DataMapper.setup(:default, 'sqlite3::memory:') } app.configure(:test) { DataMapper.setup(:default, 'sqlite3::memory:') } end end DM USER = <<-USER class User include DataMapper::Resource property :id, Serial property :name, String property :username, String property :email, String property :crypted_password, String attr_accessor :password, :password_confirmation before :save, :encrypt_password validates_present :password, :password_confirmation def self.authenticate(username, password) user = User.first(:username => username) user && user.has_password?(password) ? user : nil end def encrypt_password self.crypted_password = BCrypt::Password.create(password) end def has_password?(password) BCrypt::Password.new(crypted_password) == password end end User.auto_upgrade! USER def setup_orm require_dependencies 'data_objects', 'do_sqlite3', 'dm-core', 'dm-validations' create_file("config/initializers/data_mapper.rb", DM) create_file("app/models/user.rb", USER) end end end
Version data entries
9 entries across 9 versions & 1 rubygems