Sha256: bdde2024d7cb1a6cf240d320703919e1ba503df5bc1215debb9ac50f9a8806be

Contents?: true

Size: 1.12 KB

Versions: 5

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

module FulfilApi
  class Resource
    class Relation
      # The {FulfilApi::Resource::Relation::Naming} extends the relation by
      #   adding methods to it that allow us to identify the type of resource that
      #   is being requested.
      module Naming
        extend ActiveSupport::Concern

        included do
          # Custom error class for missing model name. The model name is required to be
          #   able to build the API endpoint to perform the search/read HTTP request.
          class ModelNameMissing < Error; end # rubocop:disable Lint/ConstantDefinitionInBlock
        end

        # Sets the name of the resource model to be queried.
        #
        # @todo In the future, derive the {#name} from the @resource_klass automatically.
        #
        # @param model_name [String] The name of the resource model in Fulfil.
        # @return [FulfilApi::Resource::Relation] A new {Relation} instance with the model name set.
        def set(model_name:)
          clone.tap do |relation|
            relation.model_name = model_name
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
fulfil_api-0.1.4 lib/fulfil_api/resource/relation/naming.rb
fulfil_api-0.1.3 lib/fulfil_api/resource/relation/naming.rb
fulfil_api-0.1.2 lib/fulfil_api/resource/relation/naming.rb
fulfil_api-0.1.1 lib/fulfil_api/resource/relation/naming.rb
fulfil_api-0.1.0 lib/fulfil_api/resource/relation/naming.rb