Class: Intermodal::ResourceResponder

Inherits:
ActionController::Responder
  • Object
show all
Includes:
Let
Defined in:
lib/intermodal/responders/resource_responder.rb

Direct Known Subclasses

LinkingResourceResponder

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller, resources, options = {}) ⇒ ResourceResponder

Returns a new instance of ResourceResponder.



16
17
18
19
# File 'lib/intermodal/responders/resource_responder.rb', line 16

def initialize(controller, resources, options={})
  super(controller, resources, options)
  @options = options
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



8
9
10
# File 'lib/intermodal/responders/resource_responder.rb', line 8

def options
  @options
end

Instance Method Details

#respondObject

This is the common behavior for “API” requests, like :xml and :json.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/intermodal/responders/resource_responder.rb', line 22

def respond
  return head :status => 404 unless resource
  if get?
    display resource,
      root: presentation_root,
      presenter: presenter,
      scope: presentation_scope,
      always_nest_collections: always_nest_collections

  elsif has_errors?
    display resource.errors,
      root: presentation_root,
      status: :unprocessable_entity,
      presenter: presenter,
      scope: presentation_scope,
      always_nest_collections: always_nest_collections
  elsif put?
    display resource,
      root: presentation_root,
      presenter: presenter,
      scope: presentation_scope,
      always_nest_collections: always_nest_collections
  elsif post?
    display resource,
      root: presentation_root,
      status: :created,
      presenter: presenter,
      scope: presentation_scope,
      always_nest_collections: always_nest_collections
      #:location => api_location # Taken out because it requires some additional URL definitions
  else
    head status: 204
  end
end