Class: TableGo::Table

Inherits:
Object
  • Object
show all
Defined in:
lib/table_go/table.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collection, model_klass, &block) ⇒ Table

Returns a new instance of Table.



6
7
8
9
10
11
# File 'lib/table_go/table.rb', line 6

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

Instance Attribute Details

#collectionObject

Returns the value of attribute collection.



4
5
6
# File 'lib/table_go/table.rb', line 4

def collection
  @collection
end

#columnsObject

Returns the value of attribute columns.



4
5
6
# File 'lib/table_go/table.rb', line 4

def columns
  @columns
end

#model_klassObject

Returns the value of attribute model_klass.



4
5
6
# File 'lib/table_go/table.rb', line 4

def model_klass
  @model_klass
end

Instance Method Details

#attribute_names_from_model_klassObject

def model_klass_reflection_keys

@model_klass_reflection_keys ||= model_klass.reflections.keys

end



27
28
29
# File 'lib/table_go/table.rb', line 27

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

#evaluate_dsl(block) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/table_go/table.rb', line 13

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