Class: Hotsheet::Sheet

Inherits:
Object
  • Object
show all
Includes:
Config
Defined in:
lib/hotsheet/sheet.rb

Constant Summary collapse

CONFIG =
{
  per: { allowed_classes: [Integer], default: 100 }
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Config

#merge_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

#configObject (readonly)

Returns the value of attribute config.



6
7
8
# File 'lib/hotsheet/sheet.rb', line 6

def config
  @config
end

#modelObject (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

#columnsObject



21
22
23
# File 'lib/hotsheet/sheet.rb', line 21

def columns
  @columns.select { |_name, column| column.visible? }
end