Sha256: a3426c5f229783ee19b807f31a08cd4003fa53e44fac1272368095a11690998b
Contents?: true
Size: 1.03 KB
Versions: 22
Compression:
Stored size: 1.03 KB
Contents
module SuperTable class Tableable include ViewHelpers attr_accessor :records class_attribute :columns class_attribute :record_klass delegate :columns, to: :class def initialize(records) self.records = records end def placeholder; end class << self def column(method_name, title, options={}) self.columns ||= {} self.columns[method_name] = options.merge(title: title) end def collection(records_name, options={}, &block) parent_klass = ancestors.find { |klass| klass.respond_to?(:record_klass) && klass.record_klass.present? } self.record_klass = if parent_klass Class.new(parent_klass.record_klass, &block) else Class.new(SuperTable::Record, &block) end define_method(records_name) do @collection ||= self.records.map { |record| record_klass.new(record) } end define_method(:collection) do send(records_name) end end end end end
Version data entries
22 entries across 22 versions & 1 rubygems