Sha256: 76747643efa3baa0f65d4b8731e2a1f6a86ec12df148efe21c1db3d9ce0d83ac

Contents?: true

Size: 747 Bytes

Versions: 4

Compression:

Stored size: 747 Bytes

Contents

module TableGo
  class Table

    attr_accessor :collection, :model_klass, :columns

    def initialize(collection, model_klass, &block)
      @collection  = collection
      @model_klass = model_klass
      @columns     = Columns.new(self)
      evaluate_dsl(block)
    end

    def evaluate_dsl(block)
      if block
        block.call(@columns)
      else
        attribute_names_from_model_klass.each do |column_name|
          @columns.column(column_name)
        end
      end
    end

    # def model_klass_reflection_keys
    #   @model_klass_reflection_keys ||= model_klass.reflections.keys
    # end

    def attribute_names_from_model_klass
      model_klass.respond_to?(:column_names) ? model_klass.column_names : []
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
table_go-0.2.2 lib/table_go/table.rb
table_go-0.2.1 lib/table_go/table.rb
table_go-0.2.0 lib/table_go/table.rb
table_go-0.1.9 lib/table_go/table.rb