Sha256: 6362155f3693bde0eb5ed8e88f63d92c1c8248fb593c08a6189d0e6340693969

Contents?: true

Size: 1004 Bytes

Versions: 4

Compression:

Stored size: 1004 Bytes

Contents

require 'sequel'
require 'forwardable'

module Rack::Scaffold::Adapters
  class Sequel < Base
    extend Forwardable

    def_delegators :@klass, :count, :all, :find, :[], :update_timestamp_field
    def_delegator :@klass, :create, :create!
    def_delegator :@klass, :update, :update!
    def_delegator :@klass, :destroy, :destroy!

    class << self
      def ===(model)
        ::Sequel::Model === model
      end

      def resources(model, options = {})
        model
      end
    end

    def singular
      @klass.name.demodulize.downcase
    end

    def plural
      @klass.table_name
    end

    def paginate(limit, offset)
      @klass.limit(limit, offset)
    end

    def one_to_many_associations
      @klass.all_association_reflections.select{|association| association[:type] == :one_to_many}.collect{|association| association[:name]}
    end

    def timestamps?
      defined?(::Sequel::Plugins::Timestamps) and @klass.plugins.include?(::Sequel::Plugins::Timestamps)
    end
  end
end

Version data entries

4 entries across 4 versions & 3 rubygems

Version Path
rack-scaffold-0.2.0 ./lib/rack/scaffold/adapters/sequel.rb
rack-scaffold_aim-0.1.0 ./lib/rack/scaffold/adapters/sequel.rb
rack-scaffold-aim-0.1.0 ./lib/rack/scaffold/adapters/sequel.rb
rack-scaffold-0.1.0 ./lib/rack/scaffold/adapters/sequel.rb