Class: GridTable::Table
- Inherits:
-
Object
- Object
- GridTable::Table
- Defined in:
- lib/grid_table/table.rb
Instance Attribute Summary collapse
-
#records ⇒ Object
readonly
Returns the value of attribute records.
-
#total_rows ⇒ Object
readonly
Returns the value of attribute total_rows.
Instance Method Summary collapse
- #add_control(model, attribute, options) ⇒ Object
-
#initialize ⇒ Table
constructor
A new instance of Table.
- #populate!(resource, params, options) ⇒ Object
- #strong_params ⇒ Object
Constructor Details
#initialize ⇒ Table
Returns a new instance of Table.
4 5 6 |
# File 'lib/grid_table/table.rb', line 4 def initialize @controls = [] end |
Instance Attribute Details
#records ⇒ Object (readonly)
Returns the value of attribute records.
2 3 4 |
# File 'lib/grid_table/table.rb', line 2 def records @records end |
#total_rows ⇒ Object (readonly)
Returns the value of attribute total_rows.
2 3 4 |
# File 'lib/grid_table/table.rb', line 2 def total_rows @total_rows end |
Instance Method Details
#add_control(model, attribute, options) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/grid_table/table.rb', line 8 def add_control(model, attribute, ) @controls << GridTable::Control.new( model: model.name.underscore.to_sym, attribute: attribute, source: [:source], source_class: [:source_class], source_column: [:source_column], source_sql: [:source_sql], filter: [:filter], polymorphic: [:polymorphic] ) end |
#populate!(resource, params, options) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/grid_table/table.rb', line 21 def populate!(resource, params, ) # In Rails 5 ActionController::Parameters returns an object rather than a hash # It provides the to_h method in order to return a hash (with indifferent access) of safe parameters # Rails 4 and below returns a regular hash so we need to account for that @params = params.to_h.with_indifferent_access @records = resource aggregate = [:aggregate] || false select(aggregate: aggregate) filter! unless params[:skip_filtering] @total_rows = @records.length sort! unless params[:skip_sorting] page! unless params[:skip_paging] @records end |
#strong_params ⇒ Object
38 39 40 41 42 |
# File 'lib/grid_table/table.rb', line 38 def strong_params @controls.inject(common_strong_params) do |all_params, control| all_params << control.url_param end end |