Sha256: 23abb8f1b1d4fbba4a439d8ff6248663f3627158a889122b013a263aba351baf

Contents?: true

Size: 1 KB

Versions: 3

Compression:

Stored size: 1 KB

Contents

module SinatraMore
  module SequelOrmGen

    SEQUEL = <<-SEQUEL
module SequelInitializer
  def self.registered(app)
    app.configure do
      Sequel.connect(ENV['DATABASE_URL'])
    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.2 generators/components/orms/sequel_orm_gen.rb
sinatra_more-0.3.1 generators/components/orms/sequel_orm_gen.rb
sinatra_more-0.3.0 generators/components/orms/sequel_orm_gen.rb