Class: DataMapper::Resource::OrmAdapter

Inherits:
OrmAdapter::Base show all
Defined in:
lib/orm_adapter/adapters/data_mapper.rb

Instance Attribute Summary

Attributes inherited from OrmAdapter::Base

#klass

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from OrmAdapter::Base

inherited, #initialize

Constructor Details

This class inherits a constructor from OrmAdapter::Base

Class Method Details

.except_classesObject

Do not consider these to be part of the class list



12
13
14
# File 'lib/orm_adapter/adapters/data_mapper.rb', line 12

def self.except_classes
  @@except_classes ||= []
end

.model_classesObject

Gets a list of the available models for this adapter



17
18
19
# File 'lib/orm_adapter/adapters/data_mapper.rb', line 17

def self.model_classes
  ::DataMapper::Model.descendants.to_a.select{|k| !except_classes.include?(k.name)}
end

Instance Method Details

#column_namesObject

get a list of column names for a given class



22
23
24
# File 'lib/orm_adapter/adapters/data_mapper.rb', line 22

def column_names
  klass.properties.map(&:name)
end

#create!(attributes = {}) ⇒ Object

See Also:

  • OrmAdapter::Base#create!


49
50
51
# File 'lib/orm_adapter/adapters/data_mapper.rb', line 49

def create!(attributes = {})
  klass.create(attributes)
end

#destroy(object) ⇒ Object

See Also:

  • OrmAdapter::Base#destroy


54
55
56
# File 'lib/orm_adapter/adapters/data_mapper.rb', line 54

def destroy(object)
  object.destroy if valid_object?(object)
end

#find_all(options = {}) ⇒ Object

See Also:

  • OrmAdapter::Base#find_all


43
44
45
46
# File 'lib/orm_adapter/adapters/data_mapper.rb', line 43

def find_all(options = {})
  conditions, order = extract_conditions_and_order!(options)
  klass.all :conditions => conditions, :order => order_clause(order)
end

#find_first(options = {}) ⇒ Object

See Also:

  • OrmAdapter::Base#find_first


37
38
39
40
# File 'lib/orm_adapter/adapters/data_mapper.rb', line 37

def find_first(options = {})
  conditions, order = extract_conditions_and_order!(options)
  klass.first :conditions => conditions, :order => order_clause(order)
end

#get(id) ⇒ Object

See Also:

  • OrmAdapter::Base#get


32
33
34
# File 'lib/orm_adapter/adapters/data_mapper.rb', line 32

def get(id)
  klass.get(id)
end

#get!(id) ⇒ Object

See Also:

  • OrmAdapter::Base#get!


27
28
29
# File 'lib/orm_adapter/adapters/data_mapper.rb', line 27

def get!(id)
  klass.get!(id)
end