lib/symmetric_encryption/railtie.rb in symmetric-encryption-4.2.1 vs lib/symmetric_encryption/railtie.rb in symmetric-encryption-4.3.0

- old
+ new

@@ -27,29 +27,29 @@ # Loaded before Active Record initializes since database.yml can have encrypted # passwords in it config.before_configuration do # Check if already configured unless ::SymmetricEncryption.cipher? - app_name = Rails::Application.subclasses.first.parent.to_s.underscore - config_file = - if (env_var = ENV['SYMMETRIC_ENCRYPTION_CONFIG']) - Pathname.new File.expand_path(env_var) + app_name = Rails::Application.subclasses.first.parent.to_s.underscore + env_var = ENV['SYMMETRIC_ENCRYPTION_CONFIG'] + config_file = + if env_var + Pathname.new(File.expand_path(env_var)) else Rails.root.join('config', 'symmetric-encryption.yml') end + if config_file.file? begin ::SymmetricEncryption::Config.load!(file_name: config_file, env: ENV['SYMMETRIC_ENCRYPTION_ENV'] || Rails.env) rescue ArgumentError => exc puts "\nSymmetric Encryption not able to read keys." puts "#{exc.class.name} #{exc.message}" puts "To generate a new config file and key files: symmetric-encryption --generate --app-name #{app_name}\n\n" raise(exc) end - else - puts "\nSymmetric Encryption config not found." - puts "To generate a new config file and key files: symmetric-encryption --generate --app-name #{app_name}\n\n" end + end end end end