Class: Gearhead::GearsController
- Inherits:
-
Object
- Object
- Gearhead::GearsController
- Defined in:
- lib/gearhead/gears_controller.rb
Instance Method Summary collapse
- #collection_action ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #index ⇒ Object
- #member_action ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#collection_action ⇒ Object
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 |
#create ⇒ Object
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 |
#destroy ⇒ Object
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 |
#index ⇒ Object
10 11 12 |
# File 'lib/gearhead/gears_controller.rb', line 10 def index render json: Gearhead::Actions::Index.build(@gear, request) end |
#member_action ⇒ Object
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 |
#show ⇒ Object
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 |
#update ⇒ Object
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 |