Module: Imperator::Command::RestHelper

Extended by:
ActiveSupport::Concern
Included in:
Rest, Mongoid::Command::Rest
Defined in:
lib/imperator/command/rest_helper.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#find_objectObject



76
77
78
79
80
# File 'lib/imperator/command/rest_helper.rb', line 76

def find_object
  object ||= object_class.find(self.id)
rescue
  find_object_error
end

#find_object_errorObject



82
83
84
# File 'lib/imperator/command/rest_helper.rb', line 82

def find_object_error
  raise Imperator::ResourceNotFoundError, "The resource #{self.id} could not be found" 
end

#object_classObject



68
69
70
# File 'lib/imperator/command/rest_helper.rb', line 68

def object_class
  self.class.object_class
end

#on_error(exception) ⇒ Object

Raises:

  • (Imperator::InvalidCommandError)


72
73
74
# File 'lib/imperator/command/rest_helper.rb', line 72

def on_error exception
  raise Imperator::InvalidCommandError, "The Command #{self} caused an error: #{exception}"
end