Sha256: af5ba6f98893f968c08272366907a45f58e9b76ac1966ea6470f2e12203e7a82

Contents?: true

Size: 902 Bytes

Versions: 17

Compression:

Stored size: 902 Bytes

Contents

module NCore
  module Delete
    extend ActiveSupport::Concern

    module ClassMethods
      def delete!(id, params={})
        obj = delete(id, params)
        if obj.errors?
          raise module_parent::RecordInvalid, obj
        end
        obj
      end

      # always returns a new object; check .errors? or .valid? to see how it went
      def delete(id, params={})
        raise(module_parent::RecordNotFound, "Cannot delete id=nil") if id.blank?
        obj = new(id: id)
        obj.delete(params)
        obj
      end
    end

    def delete(params={})
      params = parse_request_params(params).reverse_merge credentials: api_creds
      parsed, @api_creds = request(:delete, resource_path, params)
      load(parsed)
      errors.empty? ? self : false
    end

    def delete!(params={})
      delete(params) || raise(self.class.module_parent::RecordInvalid, self)
    end

  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
ncore-3.5.2 lib/ncore/methods/delete.rb
ncore-3.5.1 lib/ncore/methods/delete.rb
ncore-3.5.0 lib/ncore/methods/delete.rb
ncore-3.4.4 lib/ncore/methods/delete.rb
ncore-3.4.3 lib/ncore/methods/delete.rb
ncore-3.4.2 lib/ncore/methods/delete.rb
ncore-3.4.1 lib/ncore/methods/delete.rb
ncore-3.4.0 lib/ncore/methods/delete.rb
ncore-3.3.4 lib/ncore/methods/delete.rb
ncore-3.3.3 lib/ncore/methods/delete.rb
ncore-3.3.2 lib/ncore/methods/delete.rb
ncore-3.3.1 lib/ncore/methods/delete.rb
ncore-3.3.0 lib/ncore/methods/delete.rb
ncore-3.2.1 lib/ncore/methods/delete.rb
ncore-3.2.0 lib/ncore/methods/delete.rb
ncore-3.1.0 lib/ncore/methods/delete.rb
ncore-3.0.0 lib/ncore/methods/delete.rb