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