Class: Dock::MongoMapper

Inherits:
Base
  • Object
show all
Defined in:
lib/dock/adapters/mongomapper.rb

Instance Attribute Summary

Attributes inherited from Base

#model

Instance Method Summary collapse

Methods inherited from Base

#embedded, inherited, #initialize, #scoped, #supports_joins?

Constructor Details

This class inherits a constructor from Dock::Base

Instance Method Details

#all(conditions = {}) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/dock/adapters/mongomapper.rb', line 14

def all(conditions = {})
  conditions, order, limit, offset = extract_conditions!(conditions)
  conditions = conditions.merge(:sort => order) unless order.nil?
  conditions = conditions.merge(:limit => limit) unless limit.nil?
  conditions = conditions.merge(:offset => offset) unless limit.nil? || offset.nil?
  model.all(conditions_to_fields(conditions))
end

#associationsObject



37
38
39
# File 'lib/dock/adapters/mongomapper.rb', line 37

def associations()

end

#belongs_toObject



53
54
55
# File 'lib/dock/adapters/mongomapper.rb', line 53

def belongs_to()

end

#column_namesObject



43
44
45
# File 'lib/dock/adapters/mongomapper.rb', line 43

def column_names
  model.fields.keys
end

#count(conditions = {}) ⇒ Object

Checked



47
48
49
# File 'lib/dock/adapters/mongomapper.rb', line 47

def count(conditions = {})
  all(options).count
end

#create(attributes = {}) ⇒ Object



5
6
7
# File 'lib/dock/adapters/mongomapper.rb', line 5

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

#cyclic?Boolean

Checked

Returns:

  • (Boolean)


68
69
70
# File 'lib/dock/adapters/mongomapper.rb', line 68

def cyclic?
  model.cyclic?
end

#destroy(object) ⇒ Object



34
35
36
# File 'lib/dock/adapters/mongomapper.rb', line 34

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

#embedded?Boolean

Checked

Returns:

  • (Boolean)


64
65
66
# File 'lib/dock/adapters/mongomapper.rb', line 64

def embedded?
  model.relations.values.detect { |a| a.macro.to_sym == :embedded_in }
end

#encodingObject



50
51
52
# File 'lib/dock/adapters/mongomapper.rb', line 50

def encoding
  'UTF-8'
end

#find(id) ⇒ Object



8
9
10
# File 'lib/dock/adapters/mongomapper.rb', line 8

def find(id)
  model.find!(wrap_key(id))
end

#find!(id) ⇒ Object



11
12
13
# File 'lib/dock/adapters/mongomapper.rb', line 11

def find!(id)
  model.first({ :id => wrap_key(id) })
end

#first(conditions = {}) ⇒ Object



21
22
23
24
25
# File 'lib/dock/adapters/mongomapper.rb', line 21

def first(conditions = {})
  conditions, order = extract_conditions!(conditions)
  conditions = conditions.merge(:sort => order) unless order.nil?
  model.first(conditions_to_fields(conditions))
end

#has_manyObject



56
57
58
# File 'lib/dock/adapters/mongomapper.rb', line 56

def has_many()

end

#idObject



26
27
28
# File 'lib/dock/adapters/mongomapper.rb', line 26

def id
  '_id'
end

#model_nameObject



40
41
42
# File 'lib/dock/adapters/mongomapper.rb', line 40

def model_name
  model.class.name
end

#propertiesObject



75
76
77
# File 'lib/dock/adapters/mongomapper.rb', line 75

def properties()

end

#scoped?Boolean

Checked

Returns:

  • (Boolean)


60
61
62
# File 'lib/dock/adapters/mongomapper.rb', line 60

def scoped?
  model.scoped
end

#supports_joinsObject

Checked



72
73
74
# File 'lib/dock/adapters/mongomapper.rb', line 72

def supports_joins
  false
end

#update(search_key, find_by, update_key, by_value) ⇒ Object



29
30
31
32
33
# File 'lib/dock/adapters/mongomapper.rb', line 29

def update(search_key, find_by, update_key, by_value)
  entry = model.where(search_key find_by)
  entry.set(update_key => by_value)
  entry.reload
end