Sha256: ffb5c12cd3b58fa4fc59964c84c168d2b486ec7a0fb3df649c9ac917fa0cd2d2

Contents?: true

Size: 880 Bytes

Versions: 1

Compression:

Stored size: 880 Bytes

Contents

# -*- encoding: utf-8 -*-

require 'aequitas/virtus_integration/inline_attribute_rule_extractor/object'

module Aequitas
  module VirtusIntegration
    module InlineAttributeRuleExtractor
      class Array < Object

        def extract
          rules = super
          rules.concat Array(extract_length_rules)
        end

        def extract_length_rules
          length = options.fetch(:length, false)

          case length
          when ::Integer; Rule::Length::Equal.new(attribute.name, :expected => length)
          when ::Range;   Rule::Length::Range.new(attribute.name, :range    => length)
          when ::FalseClass;
          else raise ArgumentError, "expected Integer or Range :length, got: #{length.inspect}"
          end
        end

      end # class Array
    end # module InlineAttributeRuleExtractor
  end # module VirtusIntegration
end # module Aequitas

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
aequitas-0.0.2 lib/aequitas/virtus_integration/inline_attribute_rule_extractor/array.rb