Module: EffectiveDatatables

Defined in:
lib/effective_datatables.rb,
lib/effective_datatables/engine.rb,
lib/effective_datatables/version.rb,
lib/generators/effective_datatables/install_generator.rb

Defined Under Namespace

Modules: Generators Classes: Engine

Constant Summary collapse

AVAILABLE_LOCALES =
%w(en es nl)
VERSION =
'4.5.3'.freeze

Class Method Summary collapse

Class Method Details

.authorize!(controller, action, resource) ⇒ Object



41
42
43
# File 'lib/effective_datatables.rb', line 41

def self.authorize!(controller, action, resource)
  raise Effective::AccessDenied.new('Access Denied', action, resource) unless authorized?(controller, action, resource)
end

.authorized?(controller, action, resource) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/effective_datatables.rb', line 28

def self.authorized?(controller, action, resource)
  @_exceptions ||= [Effective::AccessDenied, (CanCan::AccessDenied if defined?(CanCan)), (Pundit::NotAuthorizedError if defined?(Pundit))].compact

  return !!authorization_method unless authorization_method.respond_to?(:call)
  controller = controller.controller if controller.respond_to?(:controller) # Do the right thing with a view

  begin
    !!(controller || self).instance_exec((controller || self), action, resource, &authorization_method)
  rescue *@_exceptions
    false
  end
end

.find(id) ⇒ Object



45
46
47
48
49
50
# File 'lib/effective_datatables.rb', line 45

def self.find(id)
  id = id.to_s.gsub(/-\d+\z/, '').gsub('-', '/')
  klass = (id.classify.safe_constantize || id.classify.pluralize.safe_constantize)

  klass.try(:new) || raise('unable to find datatable')
end

.language(locale) ⇒ Object

Locale is coming from view. I think it can be dynamic. We currently support: en, es, nl



54
55
56
57
58
59
60
61
62
63
# File 'lib/effective_datatables.rb', line 54

def self.language(locale)
  @_languages ||= {}

  locale = :en unless AVAILABLE_LOCALES.include?(locale.to_s)

  @_languages[locale] ||= begin
    path = Gem::Specification.find_by_name('effective_datatables').gem_dir + "/app/assets/javascripts/dataTables/locales/#{locale}.lang"
    JSON.parse(File.read(path)).to_json
  end
end

.setup {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



24
25
26
# File 'lib/effective_datatables.rb', line 24

def self.setup
  yield self
end