Methods
- ==
- add_frozen_gem_path
- add_load_paths
- build
- built?
- dependencies
- framework_gem?
- from_directory_name
- frozen?
- install
- installed?
- load
- load_paths_added?
- loaded?
- new
- refresh
- requirement
- requirement
- specification
- specification=
- unpack
- unpacked_path
- vendor_gem?
- vendor_rails?
- write_specification
Attributes
[RW] | dep | |
[RW] | lib | |
[RW] | source |
Public Class methods
[ show source ]
# File railties/lib/rails/gem_dependency.rb, line 19 19: def self.add_frozen_gem_path 20: @@paths_loaded ||= begin 21: source_index = Rails::VendorGemSourceIndex.new(Gem.source_index) 22: Gem.clear_paths 23: Gem.source_index = source_index 24: # loaded before us - we can't change them, so mark them 25: Gem.loaded_specs.each do |name, spec| 26: @@framework_gems[name] = spec 27: end 28: true 29: end 30: end
[ show source ]
# File railties/lib/rails/gem_dependency.rb, line 32 32: def self.from_directory_name(directory_name, load_spec=true) 33: directory_name_parts = File.basename(directory_name).split('-') 34: name = directory_name_parts[0..-2].join('-') 35: version = directory_name_parts.last 36: result = self.new(name, :version => version) 37: spec_filename = File.join(directory_name, '.specification') 38: if load_spec 39: raise "Missing specification file in #{File.dirname(spec_filename)}. Perhaps you need to do a 'rake gems:refresh_specs'?" unless File.exists?(spec_filename) 40: spec = YAML::load_file(spec_filename) 41: result.specification = spec 42: end 43: result 44: rescue ArgumentError => e 45: raise "Unable to determine gem name and version from '#{directory_name}'" 46: end
[ show source ]
# File railties/lib/rails/gem_dependency.rb, line 48 48: def initialize(name, options = {}) 49: require 'rubygems' unless Object.const_defined?(:Gem) 50: 51: if options[:requirement] 52: req = options[:requirement] 53: elsif options[:version] 54: req = Gem::Requirement.create(options[:version]) 55: else 56: req = Gem::Requirement.default 57: end 58: 59: @lib = options[:lib] 60: @source = options[:source] 61: @loaded = @frozen = @load_paths_added = false 62: 63: super(name, req) 64: end
[ show source ]
# File railties/lib/rails/gem_dependency.rb, line 13 13: def self.unpacked_path 14: @unpacked_path ||= File.join(RAILS_ROOT, 'vendor', 'gems') 15: end
Public Instance methods
[ show source ]
# File railties/lib/rails/gem_dependency.rb, line 274 274: def ==(other) 275: self.name == other.name && self.requirement == other.requirement 276: end
[ show source ]
# File railties/lib/rails/gem_dependency.rb, line 66 66: def add_load_paths 67: self.class.add_frozen_gem_path 68: return if @loaded || @load_paths_added 69: if framework_gem? 70: @load_paths_added = @loaded = @frozen = true 71: return 72: end 73: gem self 74: @spec = Gem.loaded_specs[name] 75: @frozen = @spec.loaded_from.include?(self.class.unpacked_path) if @spec 76: @load_paths_added = true 77: rescue Gem::LoadError 78: end
[ show source ]
# File railties/lib/rails/gem_dependency.rb, line 193 193: def build(options={}) 194: require 'rails/gem_builder' 195: return if specification.nil? 196: if options[:force] || !built? 197: return unless File.exists?(unpacked_specification_filename) 198: spec = YAML::load_file(unpacked_specification_filename) 199: Rails::GemBuilder.new(spec, unpacked_gem_directory).build_extensions 200: puts "Built gem: '#{unpacked_gem_directory}'" 201: end 202: dependencies.each { |dep| dep.build(options) } 203: end
[ show source ]
# File railties/lib/rails/gem_dependency.rb, line 130 130: def built? 131: return false unless frozen? 132: 133: if vendor_gem? 134: specification.extensions.each do |ext| 135: makefile = File.join(unpacked_gem_directory, File.dirname(ext), 'Makefile') 136: return false unless File.exists?(makefile) 137: end 138: end 139: 140: true 141: end
[ show source ]
# File railties/lib/rails/gem_dependency.rb, line 80 80: def dependencies 81: return [] if framework_gem? 82: return [] unless installed? 83: specification.dependencies.reject do |dependency| 84: dependency.type == :development 85: end.map do |dependency| 86: GemDependency.new(dependency.name, :requirement => (dependency.respond_to?(:requirement) ? dependency.requirement : dependency.version_requirements)) 87: end 88: end
[ show source ]
# File railties/lib/rails/gem_dependency.rb, line 143 143: def framework_gem? 144: @@framework_gems.has_key?(name) 145: end
[ show source ]
# File railties/lib/rails/gem_dependency.rb, line 147 147: def frozen? 148: @frozen ||= vendor_rails? || vendor_gem? 149: end
[ show source ]
# File railties/lib/rails/gem_dependency.rb, line 205 205: def install 206: unless installed? 207: cmd = "#{gem_command} #{install_command.join(' ')}" 208: puts cmd 209: puts %x(#{cmd}) 210: end 211: end
[ show source ]
# File railties/lib/rails/gem_dependency.rb, line 151 151: def installed? 152: Gem.loaded_specs.keys.include?(name) 153: end
[ show source ]
# File railties/lib/rails/gem_dependency.rb, line 213 213: def load 214: return if @loaded || @load_paths_added == false 215: require(@lib || name) unless @lib == false 216: @loaded = true 217: rescue LoadError 218: puts $!.to_s 219: $!.backtrace.each { |b| puts b } 220: end
[ show source ]
# File railties/lib/rails/gem_dependency.rb, line 155 155: def load_paths_added? 156: # always try to add load paths - even if a gem is loaded, it may not 157: # be a compatible version (ie random_gem 0.4 is loaded and a later spec 158: # needs >= 0.5 - gem 'random_gem' will catch this and error out) 159: @load_paths_added 160: end
[ show source ]
# File railties/lib/rails/gem_dependency.rb, line 162 162: def loaded? 163: @loaded ||= begin 164: if vendor_rails? 165: true 166: elsif specification.nil? 167: false 168: else 169: # check if the gem is loaded by inspecting $" 170: # specification.files lists all the files contained in the gem 171: gem_files = specification.files 172: # select only the files contained in require_paths - typically in bin and lib 173: require_paths_regexp = Regexp.new("^(#{specification.require_paths*'|'})/") 174: gem_lib_files = gem_files.select { |f| require_paths_regexp.match(f) } 175: # chop the leading directory off - a typical file might be in 176: # lib/gem_name/file_name.rb, but it will be 'require'd as gem_name/file_name.rb 177: gem_lib_files.map! { |f| f.split('/', 2)[1] } 178: # if any of the files from the above list appear in $", the gem is assumed to 179: # have been loaded 180: !(gem_lib_files & $").empty? 181: end 182: end 183: end
[ show source ]
# File railties/lib/rails/gem_dependency.rb, line 222 222: def refresh 223: Rails::VendorGemSourceIndex.silence_spec_warnings = true 224: real_gems = Gem.source_index.installed_source_index 225: exact_dep = Gem::Dependency.new(name, "= #{specification.version}") 226: matches = real_gems.search(exact_dep) 227: installed_spec = matches.first 228: if frozen? 229: if installed_spec 230: # we have a real copy 231: # get a fresh spec - matches should only have one element 232: # note that there is no reliable method to check that the loaded 233: # spec is the same as the copy from real_gems - Gem.activate changes 234: # some of the fields 235: real_spec = Gem::Specification.load(matches.first.loaded_from) 236: write_specification(real_spec) 237: puts "Reloaded specification for #{name} from installed gems." 238: else 239: # the gem isn't installed locally - write out our current specs 240: write_specification(specification) 241: puts "Gem #{name} not loaded locally - writing out current spec." 242: end 243: else 244: if framework_gem? 245: puts "Gem directory for #{name} not found - check if it's loading before rails." 246: else 247: puts "Something bad is going on - gem directory not found for #{name}." 248: end 249: end 250: end
[ show source ]
# File railties/lib/rails/gem_dependency.rb, line 119 119: def requirement 120: req = super 121: req unless req == Gem::Requirement.default 122: end
[ show source ]
# File railties/lib/rails/gem_dependency.rb, line 124 124: def requirement 125: req = version_requirements 126: req unless req == Gem::Requirement.default 127: end
[ show source ]
# File railties/lib/rails/gem_dependency.rb, line 90 90: def specification 91: # code repeated from Gem.activate. Find a matching spec, or the currently loaded version. 92: # error out if loaded version and requested version are incompatible. 93: @spec ||= begin 94: matches = Gem.source_index.search(self) 95: matches << @@framework_gems[name] if framework_gem? 96: if Gem.loaded_specs[name] then 97: # This gem is already loaded. If the currently loaded gem is not in the 98: # list of candidate gems, then we have a version conflict. 99: existing_spec = Gem.loaded_specs[name] 100: unless matches.any? { |spec| spec.version == existing_spec.version } then 101: raise Gem::Exception, 102: "can't activate #{@dep}, already activated #{existing_spec.full_name}" 103: end 104: # we're stuck with it, so change to match 105: version_requirements = Gem::Requirement.create("=#{existing_spec.version}") 106: existing_spec 107: else 108: # new load 109: matches.last 110: end 111: end 112: end
[ show source ]
# File railties/lib/rails/gem_dependency.rb, line 114 114: def specification=(s) 115: @spec = s 116: end
[ show source ]
# File railties/lib/rails/gem_dependency.rb, line 252 252: def unpack(options={}) 253: unless frozen? || framework_gem? 254: FileUtils.mkdir_p unpack_base 255: Dir.chdir unpack_base do 256: Gem::GemRunner.new.run(unpack_command) 257: end 258: # Gem.activate changes the spec - get the original 259: real_spec = Gem::Specification.load(specification.loaded_from) 260: write_specification(real_spec) 261: end 262: dependencies.each { |dep| dep.unpack(options) } if options[:recursive] 263: end
[ show source ]
# File railties/lib/rails/gem_dependency.rb, line 189 189: def vendor_gem? 190: specification && File.exists?(unpacked_gem_directory) 191: end
[ show source ]
# File railties/lib/rails/gem_dependency.rb, line 185 185: def vendor_rails? 186: Gem.loaded_specs.has_key?(name) && Gem.loaded_specs[name].loaded_from.empty? 187: end
[ show source ]
# File railties/lib/rails/gem_dependency.rb, line 265 265: def write_specification(spec) 266: # copy the gem's specification into GEMDIR/.specification so that 267: # we can access information about the gem on deployment systems 268: # without having the gem installed 269: File.open(unpacked_specification_filename, 'w') do |file| 270: file.puts spec.to_yaml 271: end 272: end