module Gizmo

Constants

VERSION

Attributes

logger[RW]

Public Instance Methods

delete(*args) click to toggle source

Delete an item

@param [Mongoid::Criteria] criteria @param [String, Moped::BSON::ObjecId] id

@return [Gizmo::Response]

# File lib/gizmo.rb, line 83
def delete(*args)
  context = create_context
  Delete.new(context).call(*args)
end
find(*args) click to toggle source

Find an item

@param [Mongoid::Criteria] criteria @param [String, Moped::BSON::ObjecId] id

@return [Gizmo::Response]

# File lib/gizmo.rb, line 41
def find(*args)
  context = create_context
  Find.new(context).call(*args)
end
find_all(*args) click to toggle source

Find all items

@param [Mongoid::Criteria] criteria

@return [Gizmo::Response]

# File lib/gizmo.rb, line 27
def find_all(*args)
  context = create_context
  operation = FindAll.new(context)
  response = operation.call(*args)
  operation.set_response_headers response
  response
end
make(*args) click to toggle source

Make a new instance of an item

@param [Mongoid::Criteria] criteria @param [Hash] attrs

@return [Gizmo::Response]

# File lib/gizmo.rb, line 57
def make(*args)
  context = create_context
  operation = Make.new(context)
  response = operation.call(*args)
  operation.set_response_headers response
  response
end
modify(*args) click to toggle source

Modify an item

@param [Mongoid::Criteria] criteria @param [String, Moped::BSON::ObjecId] id @param [Hash] attrs

@return [Gizmo::Response]

# File lib/gizmo.rb, line 72
def modify(*args)
  context = create_context
  Modify.new(context).call(*args)
end

Private Instance Methods

create_context() click to toggle source
# File lib/gizmo.rb, line 90
def create_context
  if defined?(ActionController) && self.kind_of?(ActionController::Base)
    Context.new(gizmo: self, format: request.format.to_sym, callback: params[:callback])
  else
    Context.new(gizmo: self, format: :json, callback: nil)
  end
end