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

Constant Summary

Constants included from EffectiveDatatable::Dsl::Filters

EffectiveDatatable::Dsl::Filters::DATE_RANGES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from EffectiveDatatable::Dsl::Filters

#changes_columns_count, #filter, #filter_date_range, #form, #scope

Methods included from EffectiveDatatable::Dsl::Datatable

#actions_col, #aggregate, #bulk_actions_col, #col, #download, #length, #order, #reorder, #reorder_col, #skip_save_state!, #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.



16
17
18
19
# File 'app/models/effective/datatable_dsl_tool.rb', line 16

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, **kwargs, &block) ⇒ Object



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

def method_missing(method, *args, **kwargs, &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

  subject = datatable if datatable.respond_to?(method)
  subject ||= view if view.respond_to?(method)
  subject ||= Tenant.helpers if defined?(Tenant) && Tenant.helpers.respond_to?(method)

  return super unless subject

  if block_given?
    subject.send(method, *args, **kwargs) { yield }
  else
    subject.send(method, *args, **kwargs)
  end
end

Instance Attribute Details

#datatableObject (readonly)

Returns the value of attribute datatable.



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

def datatable
  @datatable
end

#in_datatables_do_blockObject

Returns the value of attribute in_datatables_do_block.



9
10
11
# File 'app/models/effective/datatable_dsl_tool.rb', line 9

def in_datatables_do_block
  @in_datatables_do_block
end

#viewObject (readonly)

Returns the value of attribute view.



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

def view
  @view
end