Module: PanStuff::ResourcesController

Extended by:
ActiveSupport::Concern
Defined in:
lib/pan_stuff/resources_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/pan_stuff/resources_controller.rb', line 26

def create
  @resource = resource_creator

  if @resource.errors.any?
    render resource_errors: @resource.errors, status: :unprocessable_entity
  else
    render resource:   @resource,
           serializer: create_resource_serializer,
           context:    context,
           meta:       meta,
           message:    create_message,
           location:   resource_location,
           status:     :created
  end
end

#destroyObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/pan_stuff/resources_controller.rb', line 57

def destroy
  @resource = resource_destroyer

  if @resource.errors.any?
    render resource_errors: @resource.errors, status: :unprocessable_entity
  else
    render resource:   @resource,
           serializer: destroy_resource_serializer,
           context:    context,
           meta:       meta,
           message:    destroy_message,
           location:   resource_location
  end
end

#indexObject



7
8
9
10
11
12
13
14
# File 'lib/pan_stuff/resources_controller.rb', line 7

def index
  @resource_collection = resource_collection_resolver

  render resource:   @resource_collection,
         serializer: index_resource_serializer,
         context:    context,
         meta:       meta
end

#showObject



16
17
18
19
20
21
22
23
24
# File 'lib/pan_stuff/resources_controller.rb', line 16

def show
  @resource = resource_finder

  render resource:   @resource,
         serializer: show_resource_serializer,
         context:    context,
         meta:       meta,
         location:   resource_location
end

#updateObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/pan_stuff/resources_controller.rb', line 42

def update
  @resource = resource_updater

  if @resource.errors.any?
    render resource_errors: @resource.errors, status: :unprocessable_entity
  else
    render resource:   @resource,
           serializer: update_resource_serializer,
           context:    context,
           meta:       meta,
           message:    update_message,
           location:   resource_location
  end
end