Sha256: b1f7fd0a4e5729ecb331b4d2c332b97ec98d438bc3d61d93268d523e62253308
Contents?: true
Size: 1.44 KB
Versions: 4
Compression:
Stored size: 1.44 KB
Contents
module CsvRowModel module Export module Attributes extend ActiveSupport::Concern included do self.column_names.each { |*args| define_attribute_method(*args) } end # @return [Hash] a map of `column_name => self.class.format_cell()public_send(column_name))` def formatted_attributes formatted_attributes_from_column_names self.class.column_names end def formatted_attribute(column_name) self.class.format_cell( public_send(column_name), column_name, self.class.index(column_name) ) end protected def formatted_attributes_from_column_names(column_names) array_to_block_hash(column_names) { |column_name| formatted_attribute(column_name) } end class_methods do # See {Model#column} def column(column_name, options={}) super define_attribute_method(column_name) end # Define default attribute method for a column # @param column_name [Symbol] the cell's column_name def define_attribute_method(column_name) define_method(column_name) do source_model.public_send(column_name) end end # Safe to override. Method applied to each cell by default # # @param cell [Object] the cell's value def format_cell(cell, column_name, column_index) cell end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems