ruby on rails - Include or extend a class/module from a gem (e.g. devise) -
i have written small module lib/encryption/encryption.rb
module encryption def self.encrypt(value) ... end def self.decrypt(value) ... end end
i want use/access module in these 2 files devise, namely:
- token_authenticatable.rb
- authenticatable.rb
i have overwritten both of them creating 2 new files , putting them /config/initilaizers (copied original source code within them , modified them)
- /config/initializers/token_authenticable.rb
- /config/initializers/authenticatable.rb
one file looks instance:
require 'devise/strategies/token_authenticatable' require './lib/encryption/encryption.rb' #tried this, not work module devise module models # tokenauthenticatable module responsible generating authentication token , # validating authenticity of same while signing in. ...
my modifications work, how can access lib/encryption.rb module within these files? modification approach best practice? if not, right approach?
if have in application.rb:
config.autoload_paths += %w(#{config.root}/lib)
then '/lib' autoloaded. meaning can call
require 'encryption/encryption'
and should work.