Module: Decisive::DSL

Defined in:
lib/decisive/template_handler.rb

Defined Under Namespace

Classes: Column

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(object) ⇒ Object



25
26
27
# File 'lib/decisive/template_handler.rb', line 25

def self.extended object
  object.instance_variable_set :@columns, []
end

Instance Method Details

#bodyObject



40
41
42
43
44
45
46
# File 'lib/decisive/template_handler.rb', line 40

def body
  @records.map do |record|
    @columns.map do |column|
      column.block.call(record)
    end
  end
end

#column(field, label: field.to_s.humanize, &block) ⇒ Object



31
32
33
34
# File 'lib/decisive/template_handler.rb', line 31

def column field, label: field.to_s.humanize, &block
  block ||= ->(record) { record.send(field) }
  @columns << Column.new(field, label, block)
end

#headerObject



36
37
38
# File 'lib/decisive/template_handler.rb', line 36

def header
  @columns.map(&:label)
end

#rowsObject



48
49
50
# File 'lib/decisive/template_handler.rb', line 48

def rows
  [header] + body
end