小さなモジュールlib/encryption/encryption.rbを作成しました
module Encryption
def self.encrypt(value)
...
end
def self.decrypt(value)
...
end
end
Deviseのこれら2つのファイルでこのモジュールを使用/アクセスしたい、つまり:
- token_authenticatable.rb
- 認証可能.rb
2 つの新しいファイルを作成して /config/initilaizers に配置することで、両方を既に上書きしています (元のソース コードをコピーして変更しました)。
- /config/initializers/token_authenticable.rb
- /config/initializers/authenticatable.rb
たとえば、1 つのファイルは次のようになります。
require 'devise/strategies/token_authenticatable'
require './lib/encryption/encryption.rb' #TRIED THIS, BUT DOES NOT WORK
module Devise
module Models
# The TokenAuthenticatable module is responsible for generating an authentication token and
# validating the authenticity of the same while signing in.
...
変更は機能しますが、これらのファイル内の lib/Encryption.rb モジュールにアクセスするにはどうすればよいですか? この修正アプローチはベストプラクティスですか? そうでない場合、正しいアプローチは何ですか?