Я довольно новичок в Rails, поэтому извиняюсь, если мой вопрос не имеет особого смысла.Включая классы Rails в задачу рейка?
У меня есть класс с именем PaymentGatewayCipher
, который выглядит как:
require 'openssl'
# Encapsulates payment gateway encryption/decryption utility functions
class PaymentGatewayCipher
class << self
def encrypt(file, options = {})
cipher = create_cipher
cipher.encrypt(cipher_key)
data = cipher.update(File.read(file))
data << cipher.final
if to_file = options[:to]
# Write it out to a different file
File.open(to_file, 'wb') do |f|
f << data
end
end
data
end
# Decrypts the given file
def decrypt(file)
cipher = create_cipher
cipher.decrypt(cipher_key)
encrypted_data = File.open(file, 'rb') {|io| io.read}
data = cipher.update(encrypted_data)
data << cipher.final
end
# Generates the cipher to be used for encryption/decryption
def create_cipher
OpenSSL::Cipher::Cipher.new('aes-256-cbc')
end
# Loads the cipher key used for the symmetric algorithm
def cipher_key
File.open(File.join(Rails.root, 'config/mystuff/live/cipher.key'), 'rb') {|io| io.read}
end
end
end
Я хочу написать rake task
, чтобы запустить его, чтобы расшифровать файл. Я попытался положить файл в tasks/Rakefile
, который выглядит как:
directory "tasks"
task :decrypt_test do
puts "Decypting"
pay_pal_config = PaymentGatewayCipher.decrypt('hpa1')
end
Когда я запускаю его, однако, он говорит, что не может найти Class::Rails
Помощи?
Бит о «не забудьте включить среду рельсов на ваших задачах» ключ! –