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

Version Path
super_tools-3.0.1 lib/super_table/tableable.rb
super_tools-2.1.0 lib/super_table/tableable.rb
super_tools-0.0.26 lib/super_table/tableable.rb
super_tools-0.0.25 lib/super_table/tableable.rb
super_tools-0.0.21 lib/super_table/tableable.rb
super_tools-0.0.20 lib/super_table/tableable.rb
super_tools-0.0.17 lib/super_table/tableable.rb
super_tools-0.0.15 lib/super_table/tableable.rb
super_tools-0.0.14 lib/super_table/tableable.rb
super_tools-0.0.13 lib/super_table/tableable.rb
super_tools-0.0.12 lib/super_table/tableable.rb
super_tools-0.0.11 lib/super_table/tableable.rb
super_tools-0.0.10 lib/super_table/tableable.rb
super_tools-0.0.9 lib/super_table/tableable.rb
super_tools-0.0.8 lib/super_table/tableable.rb
super_tools-0.0.7 lib/super_table/tableable.rb
super_tools-0.0.6 lib/super_table/tableable.rb
super_tools-0.0.5 lib/super_table/tableable.rb
super_tools-0.0.4 lib/super_table/tableable.rb
super_tools-0.0.3 lib/super_table/tableable.rb