Class: Acfs::SingletonResource
- Defined in:
- lib/acfs/singleton_resource.rb
Overview
Acfs SingletonResources
Usage explanation:
Single.find => sends GET request to http://service:port/single
my_single.save => sends POST request to http://service:port/single
if my_single is a new object
or sends PUT request to http://service:port/single
if my_single has been requested before
my_single.delete => sends DELETE request to http://service:port/single
SingletonResources do not support the Resource method :all, since always only a single instance of the resource is being returned
Constant Summary
Constants included from Resource::Attributes
Class Method Summary collapse
-
.all ⇒ Object
(also: find_by, find_by!)
Undefined, raises NoMethodError.
-
.find(id, opts = {}) {|resource| ... } ⇒ self
Find a singleton resource, optionally with params.
- .location_default_path(_, path) ⇒ Object private
Instance Method Summary collapse
-
#delete!(**opts) ⇒ undefined
Destroy resource by sending a DELETE request.
- #need_primary_key? ⇒ Boolean private
Methods included from Resource::Validation
#remote_errors, #remote_errors=, #save!, #valid?
Methods included from Resource::Dirty
#loaded!, #reset_changes, #save!, #write_raw_attribute
Methods included from Resource::Operational
Methods included from Resource::Locatable
Methods included from Resource::Persistence
#delete, #new?, #persisted?, #save, #save!, #update_attributes, #update_attributes!
Methods included from Resource::Loadable
Methods included from Resource::Attributes
#attributes, #attributes=, #initialize, #read_attribute, #write_attribute, #write_attributes, #write_local_attribute, #write_raw_attribute
Methods included from Resource::Initialization
Class Method Details
.all ⇒ Object Also known as: find_by, find_by!
Undefined, raises NoMethodError. A singleton always only returns one object, therefore the methods :all and :where are not defined. :find_by is not defined on singletons, use :find instead
73 74 75 |
# File 'lib/acfs/singleton_resource.rb', line 73 def all raise ::Acfs::UnsupportedOperation.new end |
.find(id, opts = {}) {|resource| ... } ⇒ self
62 63 64 |
# File 'lib/acfs/singleton_resource.rb', line 62 def find(*attrs, &) find_single(nil, params: attrs., &) end |
.location_default_path(_, path) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
80 81 82 |
# File 'lib/acfs/singleton_resource.rb', line 80 def location_default_path(_, path) path end |
Instance Method Details
#delete!(**opts) ⇒ undefined
Destroy resource by sending a DELETE request. Will raise an error in case something goes wrong.
Deleting a resource is a synchronous operation.
30 31 32 33 34 35 36 37 |
# File 'lib/acfs/singleton_resource.rb', line 30 def delete!(**opts) opts[:params] ||= {} operation(:delete, **opts) do |data| update_with data freeze end end |
#need_primary_key? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
40 41 42 |
# File 'lib/acfs/singleton_resource.rb', line 40 def need_primary_key? false end |