Sha256: 1eb5f4705b20e3dd79a1c3b1f24779a5de8d306a4602a08a226bb1003cd854bc

Contents?: true

Size: 1.4 KB

Versions: 3

Compression:

Stored size: 1.4 KB

Contents

#encoding: utf-8

module Vanguard
  class Rule
    class Nullary
      class Attribute

        # Rule that tests for inclusion
        class Inclusion < self
          TYPE = :inclusion

          # Builder for inclusion rule
          class Builder < Nullary::Builder
            REQUIRED_OPTIONS = [:within]

          private

            # Return matcher
            #
            # @return [Matcher]
            #
            # @api private
            #
            def matcher
              Matcher::Nullary::Inclusion.build(options.fetch(:within))
            end
            memoize :matcher
          end

          register :validates_inclusion_of


          # Rule that tests for acceptance
          class Acceptance < self
            TYPE = :acceptance
            DEFAULT_ACCEPTED_VALUES = [ '1', 1, 'true', true, 't' ].to_set.deep_freeze

            # Builder for acceptance rule
            class Builder < Nullary::Builder
              OPTIONS = [:accept]

            private

              # Return matcher
              #
              # @return [Matcher]
              #
              # @api private
              #
              def matcher
                Matcher::Nullary::Inclusion.new(options.fetch(:acccept) { DEFAULT_ACCEPTED_VALUES })
              end
              memoize :matcher
            end

            register :validates_acceptance_of
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
vanguard-0.0.5 lib/vanguard/rule/nullary/attribute/inclusion.rb
vanguard-0.0.4 lib/vanguard/rule/nullary/attribute/inclusion.rb
vanguard-0.0.3 lib/vanguard/rule/nullary/attribute/inclusion.rb