Module: Polyseerio::Resource::Routine
- Defined in:
- lib/resource/routine.rb
Overview
Reusable resource routines.
Constant Summary collapse
- DEFAULT_UPSERT_OPTIONS =
{ key: :name }.freeze
Class Method Summary collapse
-
.upsert(resource, attributes) ⇒ Object
Upsert a resource.
Class Method Details
.upsert(resource, attributes) ⇒ Object
Upsert a resource.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/resource/routine.rb', line 12 def self.upsert(resource, attributes) unless attributes.key? :name raise ArgumentError, 'Passed attributes must contain a name.' end resource.find_by_name(attributes[:name]) .then(proc do |reason| raise reason if reason.http_code != 404 resource.create(attributes).execute.value end) end |