Sha256: 7424946c3acb0e9e18cd4469681fe785d21d65209d7fd604c3ec45a135aa0583

Contents?: true

Size: 794 Bytes

Versions: 9

Compression:

Stored size: 794 Bytes

Contents

module Formulario
  class Field
    class Collection < Field
      include Enumerable

      def fields
        raw_value
      end

      def values
        fields.map(&:value)
      end
      alias :value :values

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

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

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

      private

      def self.build(raw_value)
        new Array(raw_value).map { |value|
          field_types.for(value)
        }
      end

      def self.field_types
        @field_types ||= Field
      end

      def self.field_types=(type)
        @field_types = type
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
formulario-0.1.8 lib/formulario/fields/collection.rb
formulario-0.1.6 lib/formulario/fields/collection.rb
formulario-0.1.5 lib/formulario/fields/collection.rb
formulario-0.1.4 lib/formulario/fields/collection.rb
formulario-0.1.3 lib/formulario/fields/collection.rb
formulario-0.1.2 lib/formulario/fields/collection.rb
formulario-0.1.1b lib/formulario/fields/collection.rb
formulario-0.1.1 lib/formulario/fields/collection.rb
formulario-0.1.0 lib/formulario/fields/collection.rb