Sha256: 77f91785364e3af3ef215917cba05707a0c29bb905cb9550955be0c5d85c1a05

Contents?: true

Size: 1.44 KB

Versions: 10

Compression:

Stored size: 1.44 KB

Contents

require 'dm-core'

module DataMapper
  module Model
    include OrmAdapter::ToAdapter
  end
  
  module Resource
    class OrmAdapter < ::OrmAdapter::Base

      # Do not consider these to be part of the class list
      def self.except_classes
        @@except_classes ||= []
      end

      # Gets a list of the available models for this adapter
      def self.model_classes
        ::DataMapper::Model.descendants.to_a.select{|k| !except_classes.include?(k.name)}
      end

      # 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_and_order!(options)
        klass.first :conditions => conditions, :order => order_clause(order)
      end

      # @see OrmAdapter::Base#find_all
      def find_all(options)
        conditions, order = extract_conditions_and_order!(options)
        klass.all :conditions => conditions, :order => order_clause(order)
      end
    
      # @see OrmAdapter::Base#create!
      def create!(attributes)
        klass.create(attributes)
      end
      
    protected
      
      def order_clause(order)
        order.map {|pair| pair.first.send(pair.last)}
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 3 rubygems

Version Path
devise_sociable-0.1.0 vendor/bundle/gems/orm_adapter-0.0.7/lib/orm_adapter/adapters/data_mapper.rb
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/orm_adapter-0.0.7/lib/orm_adapter/adapters/data_mapper.rb
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/orm_adapter-0.0.7/lib/orm_adapter/adapters/data_mapper.rb
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/orm_adapter-0.0.7/lib/orm_adapter/adapters/data_mapper.rb
sunrise-cms-0.3.0 vendor/bundle/ruby/1.9.1/gems/orm_adapter-0.0.7/lib/orm_adapter/adapters/data_mapper.rb
sunrise-cms-0.3.0.rc vendor/bundle/ruby/1.9.1/gems/orm_adapter-0.0.7/lib/orm_adapter/adapters/data_mapper.rb
orm_adapter-0.0.7 lib/orm_adapter/adapters/data_mapper.rb
orm_adapter-0.0.6 lib/orm_adapter/adapters/data_mapper.rb
orm_adapter-0.0.5 lib/orm_adapter/adapters/data_mapper.rb
orm_adapter-0.0.4 lib/orm_adapter/adapters/data_mapper.rb