Class: Hotsheet::Sheet
Constant Summary collapse
- CONFIG =
{ per: { allowed_classes: [Integer], default: 100 } }.freeze
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
- #cells_for(columns, params) ⇒ Object
- #columns ⇒ Object
-
#initialize(name, config, &columns) ⇒ Sheet
constructor
A new instance of Sheet.
Methods included from Config
Constructor Details
#initialize(name, config, &columns) ⇒ Sheet
Returns a new instance of Sheet.
12 13 14 15 16 17 18 19 |
# File 'lib/hotsheet/sheet.rb', line 12 def initialize(name, config, &columns) @config = merge_config! CONFIG, config @model = name.to_s.constantize @columns = {} column :id, editable: false columns ? instance_eval(&columns) : use_default_configuration end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
6 7 8 |
# File 'lib/hotsheet/sheet.rb', line 6 def config @config end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
6 7 8 |
# File 'lib/hotsheet/sheet.rb', line 6 def model @model end |
Instance Method Details
#cells_for(columns, params) ⇒ Object
25 26 27 28 29 |
# File 'lib/hotsheet/sheet.rb', line 25 def cells_for(columns, params) page = page_info params[:page] [@model.order(:id).limit(page[:limit]).offset(page[:offset]).pluck(*columns.keys).transpose, page] end |
#columns ⇒ Object
21 22 23 |
# File 'lib/hotsheet/sheet.rb', line 21 def columns @columns.select { |_name, column| column.visible? } end |