Sha256: 212f0c3b3f793a715fabb298ef5eabeef3f1b64a215e5d2178c362d590df170b

Contents?: true

Size: 1.03 KB

Versions: 3

Compression:

Stored size: 1.03 KB

Contents

module SinatraMore
  module SequelOrmGen

    SEQUEL = <<-SEQUEL
module SequelInitializer
  def self.registered(app)
    app.configure do
      Sequel::Model.plugin(:schema)
      Sequel.connect('your_db_here')
    end
  end
end
SEQUEL

    USER = <<-USER
class User < Sequel::Model(:users)
  unless table_exists?
    set_schema do
      primary_key :id
      string :name
      string :username
      string :email
      string :crypted_password
    end
    create_table
  end
  
  def self.authenticate(username, password)
    user = User.filter(:username => username).first
    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

    def setup_orm
      insert_require 'sequel', :path => "config/dependencies.rb", :indent => 2
      create_file("config/initializers/sequel.rb", SEQUEL)
      create_file("app/models/user.rb", USER)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sinatra_more-0.3.6 generators/components/orms/sequel_orm_gen.rb
sinatra_more-0.3.5 generators/components/orms/sequel_orm_gen.rb
sinatra_more-0.3.4 generators/components/orms/sequel_orm_gen.rb