Sha256: f9a059fce2a9fe27d02b4925284216816fe9311766ab80ad85d632399f867d51

Contents?: true

Size: 1.22 KB

Versions: 7

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

class Serega
  module SeregaValidations
    class CheckAttributeParams
      module InstanceMethods
        attr_reader :name, :opts, :block

        def initialize(name, opts, block)
          @name = name
          @opts = opts
          @block = block
        end

        def validate
          check_name
          check_opts
          check_block
        end

        private

        def check_name
          Attribute::CheckName.call(name)
        end

        def check_opts
          Utils::CheckAllowedKeys.call(opts, allowed_opts_keys)

          Attribute::CheckOptConst.call(opts, block)
          Attribute::CheckOptDelegate.call(opts, block)
          Attribute::CheckOptHide.call(opts)
          Attribute::CheckOptKey.call(opts, block)
          Attribute::CheckOptMany.call(opts)
          Attribute::CheckOptSerializer.call(opts)
          Attribute::CheckOptValue.call(opts, block)
        end

        def check_block
          Attribute::CheckBlock.call(block)
        end

        def allowed_opts_keys
          self.class.serializer_class.config.attribute_keys
        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.6.1 lib/serega/validations/check_attribute_params.rb
serega-0.6.0 lib/serega/validations/check_attribute_params.rb
serega-0.5.2 lib/serega/validations/check_attribute_params.rb
serega-0.5.1 lib/serega/validations/check_attribute_params.rb
serega-0.5.0 lib/serega/validations/check_attribute_params.rb
serega-0.4.0 lib/serega/validations/check_attribute_params.rb
serega-0.3.0 lib/serega/validations/check_attribute_params.rb