Sha256: dace1e12766c5618610e0584b20c75572fb8b659569d7721c656464b78a445da

Contents?: true

Size: 1.09 KB

Versions: 6

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

class Serega
  module Plugins
    module Metadata
      class MetaAttribute
        class CheckOpts
          class << self
            #
            # Validates attribute options
            # Checks used options are allowed and then checks options values.
            #
            # @param opts [Hash] Attribute options
            # @param attribute_keys [Array<Symbol>] Allowed options keys
            #
            # @raise [Error] when attribute has invalid options
            #
            # @return [void]
            #
            def call(opts, attribute_keys)
              opts.each_key do |key|
                next if attribute_keys.include?(key.to_sym)

                raise Error, "Invalid option #{key.inspect}. Allowed options are: #{attribute_keys.map(&:inspect).join(", ")}"
              end

              check_each_opt(opts)
            end

            private

            def check_each_opt(opts)
              CheckOptHideEmpty.call(opts)
              CheckOptHideNil.call(opts)
            end
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
serega-0.1.5 lib/serega/plugins/metadata/validations/check_opts.rb
serega-0.1.4 lib/serega/plugins/metadata/validations/check_opts.rb
serega-0.1.3 lib/serega/plugins/metadata/validations/check_opts.rb
serega-0.1.2 lib/serega/plugins/metadata/validations/check_opts.rb
serega-0.1.1 lib/serega/plugins/metadata/validations/check_opts.rb
serega-0.1.0 lib/serega/plugins/metadata/validations/check_opts.rb