Sha256: 1839856f33b8028b2efc007ee9d5b9f4d11388ea2271550be3320a330a413418

Contents?: true

Size: 1.23 KB

Versions: 7

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

class Serega
  module SeregaValidations
    #
    # Validations of serializer initialization options
    #
    class CheckInitiateParams
      #
      # Validations of serializer initialization options instance methods
      #
      module InstanceMethods
        # @return [Hash] validated initialization options
        attr_reader :opts

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

        #
        # Validates initiating params
        #
        def validate
          check_allowed_keys
          check_modifiers
        end

        private

        def check_allowed_keys
          Utils::CheckAllowedKeys.call(opts, serializer_class.config.initiate_keys, :initiate)
        end

        def check_modifiers
          Initiate::CheckModifiers.new.call(serializer_class, opts[:only], opts[:with], opts[:except])
        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_initiate_params.rb
serega-0.20.1 lib/serega/validations/check_initiate_params.rb
serega-0.20.0 lib/serega/validations/check_initiate_params.rb
serega-0.19.0 lib/serega/validations/check_initiate_params.rb
serega-0.18.0 lib/serega/validations/check_initiate_params.rb
serega-0.17.0 lib/serega/validations/check_initiate_params.rb
serega-0.16.0 lib/serega/validations/check_initiate_params.rb