Class: Effective::DatatableDslTool

Inherits:
Object
  • Object
show all
Includes:
EffectiveDatatable::Dsl::BulkActions, EffectiveDatatable::Dsl::Charts, EffectiveDatatable::Dsl::Datatable, EffectiveDatatable::Dsl::Filters
Defined in:
app/models/effective/datatable_dsl_tool.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from EffectiveDatatable::Dsl::Filters

#changes_columns_count, #filter, #form, #scope

Methods included from EffectiveDatatable::Dsl::Datatable

#actions_col, #aggregate, #bulk_actions_col, #col, #length, #order, #reorder, #reorder_col, #val

Methods included from EffectiveDatatable::Dsl::Charts

#chart

Methods included from EffectiveDatatable::Dsl::BulkActions

#bulk_action, #bulk_action_content, #bulk_action_divider, #bulk_download

Constructor Details

#initialize(datatable) ⇒ DatatableDslTool

Returns a new instance of DatatableDslTool.



14
15
16
17
# File 'app/models/effective/datatable_dsl_tool.rb', line 14

def initialize(datatable)
  @datatable = datatable
  @view = datatable.view
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/models/effective/datatable_dsl_tool.rb', line 19

def method_missing(method, *args, &block)
  # Catch a common error
  if [:bulk_actions, :charts, :collection, :filters].include?(method) && in_datatables_do_block
    raise "#{method} block must be declared outside the datatable do ... end block"
  end

  if datatable.respond_to?(method)
    if block_given?
      datatable.send(method, *args) { yield }
    else
      datatable.send(method, *args)
    end
  elsif view.respond_to?(method)
    if block_given?
      view.send(method, *args) { yield }
    else
      view.send(method, *args)
    end
  else
    super
  end
end

Instance Attribute Details

#datatableObject (readonly)

Returns the value of attribute datatable.



4
5
6
# File 'app/models/effective/datatable_dsl_tool.rb', line 4

def datatable
  @datatable
end

#in_datatables_do_blockObject

Returns the value of attribute in_datatables_do_block.



7
8
9
# File 'app/models/effective/datatable_dsl_tool.rb', line 7

def in_datatables_do_block
  @in_datatables_do_block
end

#viewObject (readonly)

Returns the value of attribute view.



5
6
7
# File 'app/models/effective/datatable_dsl_tool.rb', line 5

def view
  @view
end