Class: Cell::Collection

Inherits:
Object
  • Object
show all
Extended by:
Gem::Deprecate
Includes:
Call, Layout
Defined in:
lib/cell/collection.rb

Defined Under Namespace

Modules: Call, Layout

Instance Method Summary collapse

Methods included from Layout

#call

Methods included from Call

#call

Constructor Details

#initialize(ary, options, cell_class) ⇒ Collection

Returns a new instance of Collection.



3
4
5
6
7
8
9
10
# File 'lib/cell/collection.rb', line 3

def initialize(ary, options, cell_class)
  options.delete(:collection)
  set_deprecated_options(options) # TODO: remove in 5.0.

  @ary        = ary
  @options    = options    # these options are "final" and will be identical for all collection cells.
  @cell_class = cell_class
end

Instance Method Details

#join(separator = "", &block) ⇒ Object

Iterate collection and build a cell for each item. The passed block receives that cell and the index. Its return value is captured and joined.



32
33
34
35
36
37
# File 'lib/cell/collection.rb', line 32

def join(separator="", &block)
  @ary.each_with_index.collect do |model, i|
    cell = @cell_class.build(model, @options)
    block_given? ? yield(cell, i) : cell
  end.join(separator)
end

#set_deprecated_options(options) ⇒ Object

TODO: remove in 5.0.



12
13
14
15
# File 'lib/cell/collection.rb', line 12

def set_deprecated_options(options) # TODO: remove in 5.0.
  self.method = options.delete(:method)                   if options.include?(:method)
  self.collection_join = options.delete(:collection_join) if options.include?(:collection_join)
end

#to_sObject



25
26
27
# File 'lib/cell/collection.rb', line 25

def to_s
  call
end