Sha256: a14462d3d601ef291a7b46bb14e93a2f14c3e2611223031ce8bee71be46525f7

Contents?: true

Size: 1.49 KB

Versions: 8

Compression:

Stored size: 1.49 KB

Contents

# frozen_string_literal: true

module Yext
  module Api
    module Concerns
      # This module adds default scopes that will specify configurations to be overridden for a
      # particular call.
      #
      # If these scopes are used, the values passed in will be used in the API call, if the scope
      # is not used, then the DefaultParameters middleware will insert the default values.
      module DefaultScopes
        extend ActiveSupport::Concern

        included do
          scope(:version, ->(version) { where(v: version) })
          scope(:application, ->(app_id) { where(api_key: app_id) })
          scope(:yext_username, ->(username) { where(yext_username: username) })
          scope(:yext_user_id, ->(user_id) { where(yext_user_id: user_id) })

          scope(:validate, lambda do |validation = Yext::Api::Enumerations::Validation::STRICT|
            if validation.is_a?(String)
              validation = Yext::Api::Enumerations::Validation::STRICT unless Yext::Api::Enumerations::Validation.all.include?(validation)
            else
              validation = if validation
                             Yext::Api::Enumerations::Validation::STRICT
                           else
                             Yext::Api::Enumerations::Validation::LENIENT
                           end
            end

            where(validation: validation)
          end)
        end

        class_methods do
          def reset_uri
            # do nothing.
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
yext-api-0.1.11 lib/yext/api/concerns/default_scopes.rb
yext-api-0.1.10 lib/yext/api/concerns/default_scopes.rb
yext-api-0.1.9 lib/yext/api/concerns/default_scopes.rb
yext-api-0.1.8 lib/yext/api/concerns/default_scopes.rb
yext-api-0.1.7 lib/yext/api/concerns/default_scopes.rb
yext-api-0.1.5 lib/yext/api/concerns/default_scopes.rb
yext-api-0.1.4 lib/yext/api/concerns/default_scopes.rb
yext-api-0.1.3 lib/yext/api/concerns/default_scopes.rb