我有一个unzipper.rb使用Rubyzip解压缩文件的类.
在我的本地环境中,我可以成功解压缩文件,而不会明确地包含依赖项 require 'zip'
但是在Heroku上,我得到了一个NameError (uninitialized constant Unzipper::Zip)我只能通过使用explict解决的问题require
问题:为什么在Heroku环境中这是必要的,而不是在localhost上?我的印象是Rails自动需要所有宝石.
应用程序/服务/ unzipper.rb
require 'zip' # Only required for Heroku. Works locally without!
class Unzipper
OVERRIDE_FILES = true
def initialize(file)
@file = file
end
def self.unzip(file, &block)
Unzipper.new(file).unzip(&block)
end
def unzip
open_zip do |zip|
yield extract_files(zip)
end
end
private
def open_zip(&block)
::Zip::File.open(@file.path, &block)
end
def extract_files(zip)
files = []
zip.each do |entry|
path = "#{rails_temp_directory}/#{entry.name}"
entry.extract(path) { OVERRIDE_FILES }
files << path
end
files
end
def …Run Code Online (Sandbox Code Playgroud)