class Dock::MongoMapper

Public Instance Methods

all(conditions = {}) click to toggle source
# 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
associations() click to toggle source
# File lib/dock/adapters/mongomapper.rb, line 37
def associations()

end
belongs_to() click to toggle source
# File lib/dock/adapters/mongomapper.rb, line 53
def belongs_to()

end
column_names() click to toggle source
# File lib/dock/adapters/mongomapper.rb, line 43
def column_names
  model.fields.keys
end
count(conditions = {}) click to toggle source

Checked

# File lib/dock/adapters/mongomapper.rb, line 47
def count(conditions = {})
  all(options).count
end
create(attributes = {}) click to toggle source
# File lib/dock/adapters/mongomapper.rb, line 5
def create(attributes = {})
    model.create!(attributes)
end
cyclic?() click to toggle source

Checked

# File lib/dock/adapters/mongomapper.rb, line 68
def cyclic?
  model.cyclic?
end
destroy(object) click to toggle source
# File lib/dock/adapters/mongomapper.rb, line 34
def destroy(object)
    object.destroy if valid_object?(object)
end
embedded?() click to toggle source

Checked

# File lib/dock/adapters/mongomapper.rb, line 64
def embedded?
  model.relations.values.detect { |a| a.macro.to_sym == :embedded_in }
end
encoding() click to toggle source
# File lib/dock/adapters/mongomapper.rb, line 50
def encoding
  'UTF-8'
end
find(id) click to toggle source
# File lib/dock/adapters/mongomapper.rb, line 8
def find(id)
  model.find!(wrap_key(id))
end
find!(id) click to toggle source
# File lib/dock/adapters/mongomapper.rb, line 11
def find!(id)
  model.first({ :id => wrap_key(id) })
end
first(conditions = {}) click to toggle source
# 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_many() click to toggle source
# File lib/dock/adapters/mongomapper.rb, line 56
def has_many()

end
id() click to toggle source
# File lib/dock/adapters/mongomapper.rb, line 26
def id
  '_id'
end
model_name() click to toggle source
# File lib/dock/adapters/mongomapper.rb, line 40
def model_name
  model.class.name
end
properties() click to toggle source
# File lib/dock/adapters/mongomapper.rb, line 75
def properties()

end
scoped?() click to toggle source

Checked

# File lib/dock/adapters/mongomapper.rb, line 60
def scoped?
  model.scoped
end
supports_joins() click to toggle source

Checked

# File lib/dock/adapters/mongomapper.rb, line 72
def supports_joins
  false
end
update(search_key, find_by, update_key, by_value) click to toggle source
# 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

Protected Instance Methods

conditions_to_fields(conditions) click to toggle source

converts and documents to ids

# File lib/dock/adapters/mongomapper.rb, line 81
def conditions_to_fields(conditions)
  conditions.inject({}) do |fields, (key, value)|
    if value.is_a?(MongoMapper::Document) && model.key?("#{key}_id")
      fields.merge("#{key}_id" => value.id)
    else
      fields.merge(key => value)
    end
  end
end