Sha256: 23f2a0a1d86195c836590ba6d6f986a971a127fc22bcbd11f59d2c51e53d25ec

Contents?: true

Size: 1.39 KB

Versions: 13

Compression:

Stored size: 1.39 KB

Contents

require 'dm-core'

module DataMapper
  module Model
    include OrmAdapter::ToAdapter
  end

  module Resource
    class OrmAdapter < ::OrmAdapter::Base
      # get a list of column names for a given class
      def column_names
        klass.properties.map(&:name)
      end

      # @see OrmAdapter::Base#get!
      def get!(id)
        klass.get!(id)
      end

      # @see OrmAdapter::Base#get
      def get(id)
        klass.get(id)
      end

      # @see OrmAdapter::Base#find_first
      def find_first(options = {})
        conditions, order = extract_conditions!(options)
        klass.first :conditions => conditions, :order => order_clause(order)
      end

      # @see OrmAdapter::Base#find_all
      def find_all(options = {})
        conditions, order, limit, offset = extract_conditions!(options)
        opts = { :conditions => conditions, :order => order_clause(order) }
        opts = opts.merge({ :limit => limit }) unless limit.nil?
        opts = opts.merge({ :offset => offset }) unless offset.nil?
        klass.all opts
      end

      # @see OrmAdapter::Base#create!
      def create!(attributes = {})
        klass.create(attributes)
      end

      # @see OrmAdapter::Base#destroy
      def destroy(object)
        object.destroy if valid_object?(object)
      end

    protected

      def order_clause(order)
        order.map {|pair| pair.first.send(pair.last)}
      end
    end
  end
end

Version data entries

13 entries across 12 versions & 9 rubygems

Version Path
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.1.0/gems/orm_adapter-0.5.0/lib/orm_adapter/adapters/data_mapper.rb
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/orm_adapter-0.5.0/lib/orm_adapter/adapters/data_mapper.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/orm_adapter-0.5.0/lib/orm_adapter/adapters/data_mapper.rb
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/orm_adapter-0.5.0/lib/orm_adapter/adapters/data_mapper.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/orm_adapter-0.5.0/lib/orm_adapter/adapters/data_mapper.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/orm_adapter-0.5.0/lib/orm_adapter/adapters/data_mapper.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/orm_adapter-0.5.0/lib/orm_adapter/adapters/data_mapper.rb
sc_core-0.0.7 test/dummy/vendor/bundle/ruby/2.2.0/gems/orm_adapter-0.5.0/lib/orm_adapter/adapters/data_mapper.rb
orm_adapter-0.5.0 lib/orm_adapter/adapters/data_mapper.rb
orm_adapter-0.4.1 lib/orm_adapter/adapters/data_mapper.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/orm_adapter-0.4.0/lib/orm_adapter/adapters/data_mapper.rb
orm_adapter_rails4_fix-0.4.1 lib/orm_adapter/adapters/data_mapper.rb
orm_adapter-0.4.0 lib/orm_adapter/adapters/data_mapper.rb