Class: Gearhead::GearsController

Inherits:
Object
  • Object
show all
Defined in:
lib/gearhead/gears_controller.rb

Instance Method Summary collapse

Instance Method Details

#collection_actionObject



52
53
54
55
56
57
# File 'lib/gearhead/gears_controller.rb', line 52

def collection_action
  action = @gear._gear_collection_actions[params[:collection_action]]
  if action&.verbs&.include?(request.request_method.to_sym.downcase)
    render json: instance_exec(&action.block)
  end
end

#createObject



14
15
16
17
18
19
20
21
# File 'lib/gearhead/gears_controller.rb', line 14

def create
  @resource = Gearhead::Actions::Create.build(@gear, request)
  if @resource.save
    render json: @gear.serializer_class.new(@resource)
  else
    render json: { errors: @resource.errors }, status: :unprocessable_entity
  end
end

#destroyObject



37
38
39
40
41
42
43
# File 'lib/gearhead/gears_controller.rb', line 37

def destroy
  if @resource.destroy
    render json: @gear.serializer_class.new(resource)
  else
    render json: { errors: @resource.errors }, status: :unprocessable_entity
  end
end

#indexObject



10
11
12
# File 'lib/gearhead/gears_controller.rb', line 10

def index
  render json: Gearhead::Actions::Index.build(@gear, request)
end

#member_actionObject



45
46
47
48
49
50
# File 'lib/gearhead/gears_controller.rb', line 45

def member_action
  action = @gear._gear_member_actions[params[:member_action].to_sym]
  if action&.verbs&.include?(request.request_method.to_sym.downcase)
    render json: instance_exec(&action.block)
  end
end

#showObject



23
24
25
26
# File 'lib/gearhead/gears_controller.rb', line 23

def show
  @resource = Gearhead::Actions::Show.build(@gear, request, resource: @resource)
  render json: @gear.serializer_class.new(@resource)
end

#updateObject



28
29
30
31
32
33
34
35
# File 'lib/gearhead/gears_controller.rb', line 28

def update
  @resource = Gearhead::Actions::Update.build(@gear, request, resource: @resource)
  if @resource.save
    render json: @gear.serializer_class.new(@resource)
  else
    render json: { errors: @resource.errors }, status: :unprocessable_entity
  end
end