aglushkov/serega

View on GitHub
lib/serega/plugins/explicit_many_option/validations/check_opt_many.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
# frozen_string_literal: true

class Serega
  module SeregaPlugins
    module ExplicitManyOption
      #
      # Validator for attribute :many option
      #
      class CheckOptMany
        class << self
          #
          # Checks attribute :many option must be provided with relations
          #
          # @param opts [Hash] Attribute options
          #
          # @raise [SeregaError] Attribute validation error
          #
          # @return [void]
          #
          def call(opts)
            serializer = opts[:serializer]
            return unless serializer

            many_option_exists = opts.key?(:many)
            return if many_option_exists

            raise SeregaError,
              "Attribute option :many [Boolean] must be provided" \
              " for attributes with :serializer option"
          end
        end
      end
    end
  end
end