Sha256: b7331d9396dd3a9a334006ef169105c6e26eac27e42f60169cb68c6555bfbbb2

Contents?: true

Size: 718 Bytes

Versions: 3

Compression:

Stored size: 718 Bytes

Contents

module RiceBubble
  class Attributes
    class Array < Base
      attr_reader :members

      def initialize(members, &)
        super(&)
        @members = instantiate(members)
      end

      def valid?(value)
        return false unless value.respond_to?(:all?)

        value.all? do |child|
          members.valid?(child)
        end
      end

      def validate!(_value, coerced:, path:)
        coerced.each.with_index do |child, index|
          members.validate!(
            child,
            coerced: members.coerce(child),
            path: "#{path}[#{index}]"
          )
        end
      end

      def coerce(value)
        value.respond_to?(:to_a) ? value.to_a : value
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rice_bubble-0.1.2 lib/rice_bubble/attributes/array.rb
rice_bubble-0.1.1 lib/rice_bubble/attributes/array.rb
rice_bubble-0.1.0 lib/rice_bubble/attributes/array.rb