Module: DroidServices::Extensions::HasService
- Extended by:
- ActiveSupport::Concern
- Included in:
- BaseResource
- Defined in:
- lib/droid_services/extensions/has_service.rb
Instance Method Summary collapse
- #build ⇒ Object
- #collection ⇒ Object
- #create(custom_attributes = nil) ⇒ Object
- #destroy ⇒ Object
- #read ⇒ Object (also: #edit)
- #update(custom_attributes = nil) ⇒ Object
Instance Method Details
#build ⇒ Object
9 10 11 |
# File 'lib/droid_services/extensions/has_service.rb', line 9 def build respond_with build_resource(nil) end |
#collection ⇒ Object
5 6 7 |
# File 'lib/droid_services/extensions/has_service.rb', line 5 def collection respond_with decorated_collection, collection_name end |
#create(custom_attributes = nil) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/droid_services/extensions/has_service.rb', line 13 def create(custom_attributes=nil) resource = build_resource(nil, custom_attributes||resource_attributes) invoke_callback(:before_create, resource) invoke_callback(:before_save, resource) if resource.save invoke_callback(:after_create, resource) invoke_callback(:after_save, resource) ("#{resource_name.titleize} successfully created") else add_errors_from(resource) end respond_with(resource) end |
#destroy ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/droid_services/extensions/has_service.rb', line 47 def destroy resource = find_resource(params[:id]) invoke_callback(:before_destroy, resource) resource.destroy invoke_callback(:after_destroy, resource) respond_with(resource) end |
#read ⇒ Object Also known as: edit
27 28 29 |
# File 'lib/droid_services/extensions/has_service.rb', line 27 def read respond_with find_resource(params[:id]) end |
#update(custom_attributes = nil) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/droid_services/extensions/has_service.rb', line 33 def update(custom_attributes=nil) resource = build_resource(params[:id], custom_attributes||resource_attributes) invoke_callback(:before_update, resource) invoke_callback(:before_save, resource) if resource.save invoke_callback(:after_update, resource) invoke_callback(:after_save, resource) ("#{resource_name.titleize} successfully updated") else add_errors_from(resource) end respond_with(resource) end |