Files
redpotion/lib/project/pro_motion/data_table_screen.rb
David Larrabee 7eb232675f Modify implementation of how data tables define cells
* We want a clean, clear, but flexible interface for using data tables
  * We want the model to define our cell
  * We want to be informative to the user if they do not define the cell
2015-04-06 14:39:52 -04:00

40 lines
711 B
Ruby

module ProMotion
class DataTableScreen < TableScreen
class << self
def model(value, scope=nil)
if value.method_defined?(:cell)
@data_model = value
@data_scope = scope || :all
else
raise "#{value} must define the cell method"
end
end
def data_model; @data_model; end
def data_scope; @data_scope; end
end
def table_data
[{
cells: cell_data
}]
end
def cell_data
return [] if data_model.nil?
data_model.send(data_scope).collect(&:cell)
end
private
def data_model
self.class.data_model
end
def data_scope
self.class.data_scope
end
end
end