module Resque::Reports::Extensions::TableBuilding::ClassMethods
Defines table building methods
External(DSL): - source - table - column Internal: - init_table - build_table_header - build_table_row(row_object) - data_each - data_size
Attributes
source[RW]
source_method[RW]
Public Instance Methods
add_column_cell(column_value, options = {})
click to toggle source
# File lib/resque/reports/extensions/table_building.rb, line 50 def add_column_cell(column_value, options = {}) return if @header_collecting if column_value.is_a? Symbol column_value = if @row_object.respond_to?(column_value) @row_object.public_send(column_value) else @row_object[column_value] end end if (formatter_name = options[:formatter]) column_value = @instance.send("#{formatter_name}_formatter".to_sym, column_value) end @table_row << encoded_string(column_value) end
add_column_header(column_name)
click to toggle source
# File lib/resque/reports/extensions/table_building.rb, line 46 def add_column_header(column_name) @table_header << encoded_string(column_name) if @header_collecting end
build_table_header()
click to toggle source
# File lib/resque/reports/extensions/table_building.rb, line 80 def build_table_header @header_collecting = true @table_block.call(Extensions::Dummy.new) end
build_table_row(row_object)
click to toggle source
# File lib/resque/reports/extensions/table_building.rb, line 68 def build_table_row(row_object) @header_collecting = false @row_object = row_object.is_a?(Hash) ? row_object.with_indifferent_access : row_object row = @table_block.call(@row_object) finish_row row end
column(name, value, options = {})
click to toggle source
# File lib/resque/reports/extensions/table_building.rb, line 30 def column(name, value, options = {}) if options[:skip_if].present? if options[:skip_if].is_a?(Symbol) return if @instance.send(options.delete(:skip_if)) elsif options[:skip_if].respond_to?(:call) return if options.delete(:skip_if).call end end add_column_header(name) || add_column_cell(value, options) end
data(force = false)
click to toggle source
# File lib/resque/reports/extensions/table_building.rb, line 94 def data(force = false) if force || @data.nil? @data = @instance.send(@source_method) else @data end end
data_each(force = false) { |element| ... }
click to toggle source
# File lib/resque/reports/extensions/table_building.rb, line 102 def data_each(force = false) data(force).each do |element| yield element end end
data_size()
click to toggle source
# File lib/resque/reports/extensions/table_building.rb, line 108 def data_size @data_size ||= data.count end
encoded_string(obj)
click to toggle source
you may override default string endcoding
# File lib/resque/reports/extensions/table_building.rb, line 86 def encoded_string(obj) obj.to_s.encode('utf-8', invalid: :replace, undef: :replace) end
finish_row()
click to toggle source
# File lib/resque/reports/extensions/table_building.rb, line 90 def finish_row @table_row = [] end
init_table()
click to toggle source
# File lib/resque/reports/extensions/table_building.rb, line 41 def init_table @table_header = [] @table_row = [] end
table(&block)
click to toggle source
# File lib/resque/reports/extensions/table_building.rb, line 26 def table(&block) @table_block = block end