Class: Dock::Mongoid

Inherits:
Base
  • Object
show all
Defined in:
lib/dock/adapters/mongoid.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(options = {}) ⇒ Object

Checked



18
19
20
21
# File 'lib/dock/adapters/mongoid.rb', line 18

def all(options = {})
  conditions, order, limit, offset = extract_conditions!(options)
  model.where(conditions_to_fields(conditions)).order_by(order).limit(limit).offset(offset)
end

#associationsObject



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

def associations()

end

#belongs_toObject



59
60
61
# File 'lib/dock/adapters/mongoid.rb', line 59

def belongs_to()

end

#column_namesObject

Checked



48
49
50
# File 'lib/dock/adapters/mongoid.rb', line 48

def column_names
  model.fields.keys
end

#count(options = {}) ⇒ Object

Checked



52
53
54
# File 'lib/dock/adapters/mongoid.rb', line 52

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

#create(attributes = {}) ⇒ Object

Checked



6
7
8
# File 'lib/dock/adapters/mongoid.rb', line 6

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

#cyclic?Boolean

Checked

Returns:

  • (Boolean)


74
75
76
# File 'lib/dock/adapters/mongoid.rb', line 74

def cyclic?
  model.cyclic?
end

#destroy(object) ⇒ Object

Checked



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

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

#embedded?Boolean

Checked

Returns:

  • (Boolean)


70
71
72
# File 'lib/dock/adapters/mongoid.rb', line 70

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

#encodingObject

Checked



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

def encoding
  'UTF-8'
end

#find(id) ⇒ Object

Checked



10
11
12
# File 'lib/dock/adapters/mongoid.rb', line 10

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

#find!(id) ⇒ Object

Checked



14
15
16
# File 'lib/dock/adapters/mongoid.rb', line 14

def find!(id)
  model.where(:_id => wrap_key(id)).first
end

#first(options = {}) ⇒ Object

Checked



23
24
25
26
# File 'lib/dock/adapters/mongoid.rb', line 23

def first(options = {})
  conditions, order = extract_conditions!(options)
  model.limit(1).where(conditions_to_fields(conditions)).order_by(order).first
end

#has_manyObject



62
63
64
# File 'lib/dock/adapters/mongoid.rb', line 62

def has_many()

end

#idObject

Checked



28
29
30
# File 'lib/dock/adapters/mongoid.rb', line 28

def id
  '_id'
end

#model_nameObject

Checked



44
45
46
# File 'lib/dock/adapters/mongoid.rb', line 44

def model_name
  model.class.name
end

#propertiesObject



81
82
83
# File 'lib/dock/adapters/mongoid.rb', line 81

def properties()

end

#scoped?Boolean

Checked

Returns:

  • (Boolean)


66
67
68
# File 'lib/dock/adapters/mongoid.rb', line 66

def scoped?
  model.scoped
end

#supports_joinsObject

Checked



78
79
80
# File 'lib/dock/adapters/mongoid.rb', line 78

def supports_joins
  false
end

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

Checked



32
33
34
35
# File 'lib/dock/adapters/mongoid.rb', line 32

def update(search_key, find_by, update_key, by_value)
  entry = model.where(search_key, find_by)
  entry.update_attributes!(update_key, by_value)
end