Class: SuperTable::Tableable
- Inherits:
-
Object
- Object
- SuperTable::Tableable
- Includes:
- ViewHelpers
- Defined in:
- lib/super_table/tableable.rb
Instance Attribute Summary collapse
-
#records ⇒ Object
Returns the value of attribute records.
Class Method Summary collapse
- .collection(records_name, options = {}, &block) ⇒ Object
- .column(method_name, title, options = {}) ⇒ Object
Instance Method Summary collapse
-
#initialize(records) ⇒ Tableable
constructor
A new instance of Tableable.
- #placeholder ⇒ Object
Methods included from ViewHelpers
#del, #div, included, #small, #span, #strong, #td, #th, #tr
Constructor Details
#initialize(records) ⇒ Tableable
Returns a new instance of Tableable.
11 12 13 |
# File 'lib/super_table/tableable.rb', line 11 def initialize(records) self.records = records end |
Instance Attribute Details
#records ⇒ Object
Returns the value of attribute records.
5 6 7 |
# File 'lib/super_table/tableable.rb', line 5 def records @records end |
Class Method Details
.collection(records_name, options = {}, &block) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/super_table/tableable.rb', line 24 def collection(records_name, ={}, &block) parent_klass = ancestors.find { |klass| klass.respond_to?(:record_klass) && klass.record_klass.present? } self.record_klass = if parent_klass Class.new(parent_klass.record_klass, &block) else Class.new(SuperTable::Record, &block) end define_method(records_name) do @collection ||= self.records.map { |record| record_klass.new(record) } end define_method(:collection) do send(records_name) end end |
.column(method_name, title, options = {}) ⇒ Object
19 20 21 22 |
# File 'lib/super_table/tableable.rb', line 19 def column(method_name, title, ={}) self.columns ||= {} self.columns[method_name] = .merge(title: title) end |
Instance Method Details
#placeholder ⇒ Object
15 |
# File 'lib/super_table/tableable.rb', line 15 def placeholder; end |