Существует два основных способа:
1) Вы можете загрузить ресурсы, относящиеся к файлу Ruby, в вашем геме, используя __FILE__
:
def path_to_resources
File.join(File.dirname(File.expand_path(__FILE__)), '../path/to/resources')
end
2) Вы можете добавить произвольные путииз вашего Gem в переменную $LOAD_PATH
, а затем пройдите по $LOAD_PATH
, чтобы найти ресурсы, например,
Gem::Specification.new do |spec|
spec.name = 'the-name-of-your-gem'
spec.version ='0.0.1'
# this is important - it specifies which files to include in the gem.
spec.files = Dir.glob("lib/**/*") + %w{History.txt Manifest.txt} +
Dir.glob("path/to/resources/**/*")
# If you have resources in other directories than 'lib'
spec.require_paths << 'path/to/resources'
# optional, but useful to your users
spec.summary = "A more longwinded description of your gem"
spec.author = 'Your Name'
spec.email = 'you@yourdomain.com'
spec.homepage = 'http://www.yourpage.com'
# you did document with RDoc, right?
spec.has_rdoc = true
# if you have any dependencies on other gems, list them thusly
spec.add_dependency('hpricot')
spec.add_dependency('log4r', '>= 1.0.5')
end
, а затем
$LOAD_PATH.each { |dir| ... look for resources relative to dir ... }