class Acfs::SingletonResource

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

Public Class Methods

all() click to toggle source

@api public

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

# File lib/acfs/singleton_resource.rb, line 73
def all
  raise ::Acfs::UnsupportedOperation.new
end
Also aliased as: find_by, find_by!
find(*attrs, &block) click to toggle source

@api public

@overload find(id, opts = {})

Find a singleton resource, optionally with params.

@example
  single = Singleton.find # Will query `http://base.url/singletons/`

@param [ Hash ] opts Additional options.
@option opts [ Hash ] :params Additional parameters added to request.

@yield [ resource ] Callback block to be executed after
  resource was fetched successfully.
@yieldparam resource [ self ] Fetched resources.

@return [ self ] Resource object.
# File lib/acfs/singleton_resource.rb, line 62
def find(*attrs, &block)
  find_single nil, params: attrs.extract_options!, &block
end
find_by()
Alias for: all
find_by!()
Alias for: all
location_default_path(_, path) click to toggle source

@api private

# File lib/acfs/singleton_resource.rb, line 80
def location_default_path(_, path)
  path
end

Public Instance Methods

delete!(**opts) click to toggle source

@api public

Destroy resource by sending a DELETE request. Will raise an error in case something goes wrong.

Deleting a resource is a synchronous operation.

@raise [Acfs::ErroneousResponse]

If remote service respond with not successful response.

@return [undefined] @see delete

# 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?() click to toggle source

@api private

# File lib/acfs/singleton_resource.rb, line 40
def need_primary_key?
  false
end