class MongoMapper::Plugins::Querying::DecoratedPluckyQuery

Public Instance Methods

criteria_hash() click to toggle source
Calls superclass method
# File lib/mongo_mapper/plugins/querying/decorated_plucky_query.rb, line 32
def criteria_hash
  @model.dealias_keys super
end
delete(*ids) click to toggle source
# File lib/mongo_mapper/plugins/querying/decorated_plucky_query.rb, line 10
def delete(*ids)
  where(:_id => ids.flatten).remove
end
delete_all(options = {}) click to toggle source
# File lib/mongo_mapper/plugins/querying/decorated_plucky_query.rb, line 14
def delete_all(options = {})
  where(options).remove
end
destroy(*ids) click to toggle source
# File lib/mongo_mapper/plugins/querying/decorated_plucky_query.rb, line 18
def destroy(*ids)
  [find!(*ids.flatten.compact.uniq)].flatten.each { |doc| doc.destroy }
end
destroy_all(options={}) click to toggle source
# File lib/mongo_mapper/plugins/querying/decorated_plucky_query.rb, line 22
def destroy_all(options={})
  find_each(options) { |document| document.destroy }
end
find!(*ids) click to toggle source
# File lib/mongo_mapper/plugins/querying/decorated_plucky_query.rb, line 50
def find!(*ids)
  raise DocumentNotFound, "Couldn't find without an ID" if ids.flatten.size == 0

  find(*ids).tap do |result|
    ids = Array(ids).flatten.uniq
    if result.nil? || ids.size != Array(result).size
      raise DocumentNotFound, "Couldn't find all of the ids (#{ids.join(',')}). Found #{Array(result).size}, but was expecting #{ids.size}"
    end
  end
end
model(model=nil) click to toggle source
# File lib/mongo_mapper/plugins/querying/decorated_plucky_query.rb, line 26
def model(model=nil)
  return @model if model.nil?
  @model = model
  self
end
options_hash() click to toggle source
Calls superclass method
# File lib/mongo_mapper/plugins/querying/decorated_plucky_query.rb, line 36
def options_hash
  super.tap do |options|
    case options[:projection]
    when Hash
      options[:projection] = @model.dealias options[:projection]
    when Array
      options[:projection] = options[:projection].map do |field|
        key = keys[field.to_s]
        key && key.abbr || field
      end
    end
  end
end

Private Instance Methods

method_missing(method, *args, &block) click to toggle source
# File lib/mongo_mapper/plugins/querying/decorated_plucky_query.rb, line 63
def method_missing(method, *args, &block)
  return super unless model.respond_to?(method)

  result = model.with_scope(criteria_hash) do
    model.send(method, *args, &block)
  end

  case result
  when Plucky::Query
    merge(result)
  else
    result
  end
end