Sha256: a2f006c59d5890efb6254f6e57fa7c0c29c5d38c8910668bdd45137e3f70376b

Contents?: true

Size: 791 Bytes

Versions: 3

Compression:

Stored size: 791 Bytes

Contents

module Formulario
  class Field
    class Collection < Field
      include Enumerable

      def self.[](type)
        Class.new(self).tap { |typed_class|
          typed_class.fields_type = type
        }
      end

      def fields
        raw_value
      end

      def exceptional?
        fields.any?(&:exceptional?)
      end

      def each(&block)
        fields.each(&block)
      end

      def values
        map(&:value)
      end

      private

      def self.build(raw_values)
        new( Array(raw_values).map { |raw_value|
               fields_type.for(raw_value)
             }
           )
      end

      def self.fields_type
        @fields_type ||= Field
      end

      def self.fields_type=(type)
        @fields_type = type_for(type)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
formulario-0.1.12 lib/formulario/fields/collection.rb
formulario-0.1.11 lib/formulario/fields/collection.rb
formulario-0.1.10 lib/formulario/fields/collection.rb