diff options
Diffstat (limited to 'railties/lib/rails/gem_dependency.rb')
-rw-r--r-- | railties/lib/rails/gem_dependency.rb | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/railties/lib/rails/gem_dependency.rb b/railties/lib/rails/gem_dependency.rb index ffdc403700..80481859e1 100644 --- a/railties/lib/rails/gem_dependency.rb +++ b/railties/lib/rails/gem_dependency.rb @@ -82,6 +82,10 @@ module Rails File.join(base_directory, specification.full_name) end + def spec_filename(base_directory) + File.join(gem_dir(base_directory), '.specification') + end + def load return if @loaded || @load_paths_added == false require(@lib || name) unless @lib == false @@ -146,17 +150,42 @@ module Rails Gem::GemRunner.new.run(unpack_command) end + # Gem.activate changes the spec - get the original + real_spec = Gem::Specification.load(spec.loaded_from) + write_spec(directory, real_spec) + + end + + def write_spec(directory, spec) # copy the gem's specification into GEMDIR/.specification so that # we can access information about the gem on deployment systems # without having the gem installed - spec_filename = File.join(gem_dir(directory), '.specification') - # Gem.activate changes the spec - get the original - spec = Gem::Specification.load(specification.loaded_from) - File.open(spec_filename, 'w') do |file| + File.open(spec_filename(directory), 'w') do |file| file.puts spec.to_yaml end end + def refresh_spec(directory) + real_gems = Gem.source_index.installed_source_index + exact_dep = Gem::Dependency.new(name, "= #{specification.version}") + matches = real_gems.search(exact_dep) + installed_spec = matches.first + if installed_spec + # we have a real copy + # get a fresh spec - matches should only have one element + # note that there is no reliable method to check that the loaded + # spec is the same as the copy from real_gems - Gem.activate changes + # some of the fields + real_spec = Gem::Specification.load(matches.first.loaded_from) + write_spec(directory, real_spec) + puts "Reloaded specification for #{name} from installed gems." + else + # the gem isn't installed locally - write out our current specs + write_spec(directory, specification) + puts "Gem #{name} not loaded locally - writing out current spec." + end + end + def ==(other) self.name == other.name && self.requirement == other.requirement end |