Class: Puffer::FieldSet

Inherits:
Array
  • Object
show all
Defined in:
lib/puffer/field_set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil) ⇒ FieldSet

Returns a new instance of FieldSet.



6
7
8
9
# File 'lib/puffer/field_set.rb', line 6

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

Instance Attribute Details

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/puffer/field_set.rb', line 4

def name
  @name
end

Instance Method Details

#[](key) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/puffer/field_set.rb', line 20

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

#columnsObject



16
17
18
# File 'lib/puffer/field_set.rb', line 16

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

#copy_to(fieldset, model) ⇒ Object



28
29
30
31
32
33
# File 'lib/puffer/field_set.rb', line 28

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

#field(name, resource, options, &block) ⇒ Object



11
12
13
14
# File 'lib/puffer/field_set.rb', line 11

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