module EffectiveDatatables
Constants
- AVAILABLE_LOCALES
- VERSION
Public Class Methods
decrypt(payload)
click to toggle source
# File lib/effective_datatables.rb, line 74 def self.decrypt(payload) return unless payload.present? return payload if payload.kind_of?(Hash) attributes = message_encrypter.decrypt_and_verify(payload) raise 'invalid decoded inline payload' unless attributes.kind_of?(Hash) attributes end
encrypt(attributes)
click to toggle source
# File lib/effective_datatables.rb, line 70 def self.encrypt(attributes) payload = message_encrypter.encrypt_and_sign(attributes) end
find(id, attributes = nil)
click to toggle source
# File lib/effective_datatables.rb, line 49 def self.find(id, attributes = nil) id = id.to_s.gsub(/-\d+\z/, '').gsub('-', '/') klass = (id.classify.safe_constantize || id.classify.pluralize.safe_constantize) attributes = decrypt(attributes) || {} klass.try(:new, **attributes) || raise('unable to find datatable') end
language(locale)
click to toggle source
Locale is coming from view. I think it can be dynamic. We currently support: en, es, nl
# File lib/effective_datatables.rb, line 59 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
message_encrypter()
click to toggle source
# File lib/effective_datatables.rb, line 85 def self.message_encrypter key = (Rails.application.secrets.secret_key_base.presence rescue nil) key ||= (Rails.application.secret_key_base.presence rescue nil) key ||= 10.times.map { "".hash.to_s }.join ActiveSupport::MessageEncryptor.new(key.to_s.first(32)) end
setup() { |self| ... }
click to toggle source
# File lib/effective_datatables.rb, line 28 def self.setup yield self end