Class: Daredevil::Responder

Inherits:
Object
  • Object
show all
Includes:
Actions, Responses, Sanitizers
Defined in:
lib/daredevil/responder.rb,
lib/daredevil/responder/actions.rb,
lib/daredevil/responder/responses.rb,
lib/daredevil/responder/sanitizers.rb

Defined Under Namespace

Modules: Actions, Responses, Sanitizers

Constant Summary

Constants included from Actions

Actions::ACTIONS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Sanitizers

status_symbol

Methods included from Responses

#not_found, #parameter_missing, #unauthorized

Methods included from Actions

#jbuilder_resource_render_options, #relation?, #render_resource, #resource_class, #resource_render_options, #respond_to_create_action, #respond_to_destroy_action, #respond_to_update_action, #responder_type, #serializer_class, #serializers_resource_render_options, #supported_responders

Constructor Details

#initialize(resource, options = {}) ⇒ Responder

Returns a new instance of Responder.



20
21
22
23
24
25
26
27
# File 'lib/daredevil/responder.rb', line 20

def initialize(resource, options = {})
  @resource = resource
  @options = options
  self.status = @options[:status]
  @params = @options[:params]
  @controller = @options[:controller]
  @namespace = @options[:namespace]
end

Instance Attribute Details

#controllerObject (readonly)

Returns the value of attribute controller.



17
18
19
# File 'lib/daredevil/responder.rb', line 17

def controller
  @controller
end

#errorsObject

Returns the value of attribute errors.



12
13
14
# File 'lib/daredevil/responder.rb', line 12

def errors
  @errors
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



18
19
20
# File 'lib/daredevil/responder.rb', line 18

def namespace
  @namespace
end

#optionsObject (readonly)

Returns the value of attribute options.



15
16
17
# File 'lib/daredevil/responder.rb', line 15

def options
  @options
end

#paramsObject (readonly)

Returns the value of attribute params.



16
17
18
# File 'lib/daredevil/responder.rb', line 16

def params
  @params
end

#resourceObject (readonly)

Returns the value of attribute resource.



14
15
16
# File 'lib/daredevil/responder.rb', line 14

def resource
  @resource
end

#statusObject

Returns the value of attribute status.



13
14
15
# File 'lib/daredevil/responder.rb', line 13

def status
  @status
end

Instance Method Details

#render_responseObject



33
34
35
36
# File 'lib/daredevil/responder.rb', line 33

def render_response
  return send("respond_to_#{action}_action") if action.in?(ACTIONS)
  raise(Daredevil::Errors::UnknownAction, action)
end

#respond!Object



29
30
31
# File 'lib/daredevil/responder.rb', line 29

def respond!
  render_response
end