Class: Cell::Collection
- Inherits:
-
Object
- Object
- Cell::Collection
- Extended by:
- Gem::Deprecate
- Defined in:
- lib/cell/collection.rb
Defined Under Namespace
Instance Method Summary collapse
-
#initialize(ary, options, cell_class) ⇒ Collection
constructor
A new instance of Collection.
-
#join(separator = "", &block) ⇒ Object
Iterate collection and build a cell for each item.
-
#set_deprecated_options(options) ⇒ Object
TODO: remove in 5.0.
- #to_s ⇒ Object
Methods included from Layout
Methods included from 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, , cell_class) .delete(:collection) () # TODO: remove in 5.0. @ary = ary = # 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, ) 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 () # TODO: remove in 5.0. self.method = .delete(:method) if .include?(:method) self.collection_join = .delete(:collection_join) if .include?(:collection_join) end |
#to_s ⇒ Object
25 26 27 |
# File 'lib/cell/collection.rb', line 25 def to_s call end |