Class: Coalla::TableFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/coalla/builders/table_formatter.rb

Defined Under Namespace

Classes: BooleanFormatter, DateFormatter, EnumerizeFormatter, MethodFormatter, ReflectionFormatter, SelfFormatter, SimpleFormatter

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model_class) ⇒ TableFormatter

Returns a new instance of TableFormatter.



96
97
98
99
100
101
# File 'lib/coalla/builders/table_formatter.rb', line 96

def initialize(model_class)
  @model_class = model_class
  @columns = model_class.columns.index_by(&:name).with_indifferent_access
  @reflections = model_class.reflections.dup.with_indifferent_access
  @helpers = {}
end

Class Method Details

.for(model_class) ⇒ Object



103
104
105
# File 'lib/coalla/builders/table_formatter.rb', line 103

def self.for(model_class)
  new(model_class)
end

Instance Method Details

#[](method) ⇒ Object



107
108
109
110
111
# File 'lib/coalla/builders/table_formatter.rb', line 107

def [](method)
  return @helpers[method] if @helpers[method]
  @helpers[method] = load_helper(method)
  @helpers[method]
end