Module: ErpIntegration::Fulfil::FinderMethods
- Included in:
- ApiResource
- Defined in:
- lib/erp_integration/fulfil/finder_methods.rb
Overview
The ‘FinderMethods` add various, simplistic lookup methods to find API resources. These methods should be the last method in the chain as it will invoke the HTTP request to Fulfil immediately.
If you need more attributes than the default ID attribute for an ApiResource to be returned, add the ‘select` method before the finder method is being called in your application code.
Instance Method Summary collapse
-
#find(id) ⇒ ApiResource
Looks up an individual resource based on resource’s ID.
-
#find_by(args) ⇒ ApiResource|nil
Looks up an individual resource based on the given attributes.
-
#find_by!(args) ⇒ ApiResource|nil
Looks up an individual resource based on the given attributes and raises an ‘ErpIntegration::ResourceNotFound` when the resource doesn’t exist.
Instance Method Details
#find(id) ⇒ ApiResource
Looks up an individual resource based on resource’s ID.
25 26 27 |
# File 'lib/erp_integration/fulfil/finder_methods.rb', line 25 def find(id) find_by!(id: id) || raise(ResourceNotFound) end |
#find_by(args) ⇒ ApiResource|nil
Looks up an individual resource based on the given attributes.
36 37 38 |
# File 'lib/erp_integration/fulfil/finder_methods.rb', line 36 def find_by(args) where(args).first end |
#find_by!(args) ⇒ ApiResource|nil
Looks up an individual resource based on the given attributes and raises an ‘ErpIntegration::ResourceNotFound` when the resource doesn’t exist.
48 49 50 |
# File 'lib/erp_integration/fulfil/finder_methods.rb', line 48 def find_by!(args) find_by(args) || raise(ResourceNotFound) end |