Sha256: 61171af8952a7655f83fb0dea581ebb7504a71a726ef3f92eddee505879345e7

Contents?: true

Size: 1.07 KB

Versions: 7

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

class Serega
  module SeregaValidations
    #
    # Validations of serialization options
    #
    class CheckSerializeParams
      #
      # Validations of serialization options instance methods
      #
      module InstanceMethods
        attr_reader :opts

        #
        # Initializes validator for serialization options
        #
        # @param opts [Hash] serialization options
        #
        # @return [void]
        #
        def initialize(opts)
          @opts = opts
        end

        #
        # Validates serialization options
        #
        def validate
          check_opts
        end

        private

        def check_opts
          Utils::CheckAllowedKeys.call(opts, serializer_class.config.serialize_keys, :serialize)

          Utils::CheckOptIsHash.call(opts, :context)
          Utils::CheckOptIsBool.call(opts, :many)
        end

        def serializer_class
          self.class.serializer_class
        end
      end

      include InstanceMethods
      extend Serega::SeregaHelpers::SerializerClassHelper
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
serega-0.21.0 lib/serega/validations/check_serialize_params.rb
serega-0.20.1 lib/serega/validations/check_serialize_params.rb
serega-0.20.0 lib/serega/validations/check_serialize_params.rb
serega-0.19.0 lib/serega/validations/check_serialize_params.rb
serega-0.18.0 lib/serega/validations/check_serialize_params.rb
serega-0.17.0 lib/serega/validations/check_serialize_params.rb
serega-0.16.0 lib/serega/validations/check_serialize_params.rb