Sha256: 6c9fb211cd8787d57be5e1221fdb208117f3fa74cb9fdf699a886359f5d05339

Contents?: true

Size: 721 Bytes

Versions: 5

Compression:

Stored size: 721 Bytes

Contents

module Puffer
  class FieldSet < Array

    attr_accessor :name

    def initialize name = nil
      @name = name
      super()
    end

    def field name, resource, options, &block
      push Puffer::Field.new(name, resource, self, options, &block)
      last
    end

    def columns
      select {|f| f.column}.to_fieldset
    end

    def [] key
      if key.is_a?(String) || key.is_a?(Symbol)
        detect {|f| f.field_name == key.to_s}
      else
        super
      end
    end

    def copy_to fieldset, model
      each do |f|
        new_field = fieldset.field f.field_name, model, f.options
        f.children.copy_to new_field.children, swallow_nil{new_field.reflection.klass}
      end
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
puffer-0.1.1 lib/puffer/field_set.rb
puffer-0.1.0 lib/puffer/field_set.rb
puffer-0.0.32 lib/puffer/field_set.rb
puffer-0.0.31 lib/puffer/field_set.rb
puffer-0.0.30 lib/puffer/field_set.rb