Sha256: 1b255d9526845905c2e2fa6fa9a02171899ae74b851e3c49151cdb85727b124d

Contents?: true

Size: 1.19 KB

Versions: 23

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

module Effective

  class DatatableDslTool
    attr_reader :datatable
    attr_reader :view

    attr_accessor :in_datatables_do_block

    include Effective::EffectiveDatatable::Dsl::BulkActions
    include Effective::EffectiveDatatable::Dsl::Charts
    include Effective::EffectiveDatatable::Dsl::Datatable
    include Effective::EffectiveDatatable::Dsl::Filters

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

    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

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

  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
effective_datatables-4.19.0 app/models/effective/datatable_dsl_tool.rb
effective_datatables-4.18.0 app/models/effective/datatable_dsl_tool.rb
effective_datatables-4.17.4 app/models/effective/datatable_dsl_tool.rb
effective_datatables-4.17.3 app/models/effective/datatable_dsl_tool.rb
effective_datatables-4.17.2 app/models/effective/datatable_dsl_tool.rb
effective_datatables-4.17.1 app/models/effective/datatable_dsl_tool.rb
effective_datatables-4.17.0 app/models/effective/datatable_dsl_tool.rb
effective_datatables-4.16.2 app/models/effective/datatable_dsl_tool.rb
effective_datatables-4.16.1 app/models/effective/datatable_dsl_tool.rb
effective_datatables-4.16.0 app/models/effective/datatable_dsl_tool.rb
effective_datatables-4.15.2 app/models/effective/datatable_dsl_tool.rb
effective_datatables-4.15.1 app/models/effective/datatable_dsl_tool.rb
effective_datatables-4.15.0 app/models/effective/datatable_dsl_tool.rb
effective_datatables-4.14.2 app/models/effective/datatable_dsl_tool.rb
effective_datatables-4.14.1 app/models/effective/datatable_dsl_tool.rb
effective_datatables-4.14.0 app/models/effective/datatable_dsl_tool.rb
effective_datatables-4.13.5 app/models/effective/datatable_dsl_tool.rb
effective_datatables-4.13.4 app/models/effective/datatable_dsl_tool.rb
effective_datatables-4.13.3 app/models/effective/datatable_dsl_tool.rb
effective_datatables-4.13.2 app/models/effective/datatable_dsl_tool.rb