Sha256: 85f30bd4bd3c99be95053d69c771527173fc2fc9352107d582589e275d02c500

Contents?: true

Size: 1.14 KB

Versions: 2

Compression:

Stored size: 1.14 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

      # Get an instance by id of the model
      def get!(id)
        klass.get!(id)
      end

      # Get an instance by id of the model
      def get(id)
        klass.get(id)
      end

      # Find the first instance matching conditions
      def find_first(conditions)
        klass.first(conditions)
      end

      # Find all models matching conditions
      def find_all(conditions)
        klass.all(conditions)
      end
    
      # Create a model using attributes
      def create!(attributes)
        klass.create(attributes)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
orm_adapter-0.0.3 lib/orm_adapter/adapters/data_mapper.rb
orm_adapter-0.0.2 lib/orm_adapter/adapters/data_mapper.rb