Module: Traxis::ControllerActions
- Included in:
- Controller
- Defined in:
- lib/traxis/controller_actions.rb
Instance Method Summary collapse
- #create(**params) ⇒ Object
- #destroy(id:) ⇒ Object
- #index(**params) ⇒ Object
- #show(id:) ⇒ Object
- #update(id:, **params) ⇒ Object
Instance Method Details
#create(**params) ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/traxis/controller_actions.rb', line 3 def create(**params) if create_resource.errors.any? ::Traxis::Responses::ResourceError.new(:body => serialized_resource, :json_root => [:json_root], :errors => resource.errors) else ::Traxis::Responses::ResourceCreated.new(:body => serialized_resource, :json_root => [:json_root]) end end |
#destroy(id:) ⇒ Object
11 12 13 |
# File 'lib/traxis/controller_actions.rb', line 11 def destroy(id:) ::Traxis::Responses::ResourceDeleted.new(:body => serialized_resource, :json_root => [:json_root]) end |
#index(**params) ⇒ Object
15 16 17 |
# File 'lib/traxis/controller_actions.rb', line 15 def index(**params) ::Traxis::Responses::Collection.new(:body => serialized_collection, :json_root => [:json_root]) end |
#show(id:) ⇒ Object
19 20 21 |
# File 'lib/traxis/controller_actions.rb', line 19 def show(id:) ::Traxis::Responses::Resource.new(:body => serialized_resource, :json_root => [:json_root]) end |
#update(id:, **params) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/traxis/controller_actions.rb', line 23 def update(id:, **params) if update_resource.errors.any? ::Traxis::Responses::ResourceError.new(:body => serialized_resource, :json_root => [:json_root], :errors => resource.errors) else ::Traxis::Responses::Resource.new(:body => serialized_resource, :json_root => [:json_root]) end end |