module Polyseerio::Resource::Routine

Reusable resource routines.

Constants

DEFAULT_UPSERT_OPTIONS

Public Class Methods

upsert(resource, attributes) click to toggle source

Upsert a resource.

# 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