Class: Rails::GemDependency
Instance Attribute Summary collapse
-
#lib ⇒ Object
Returns the value of attribute lib.
-
#name ⇒ Object
Returns the value of attribute name.
-
#requirement ⇒ Object
Returns the value of attribute requirement.
-
#source ⇒ Object
Returns the value of attribute source.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #add_load_paths ⇒ Object
- #dependencies ⇒ Object
- #frozen? ⇒ Boolean
- #gem_dir(base_directory) ⇒ Object
-
#initialize(name, options = {}) ⇒ GemDependency
constructor
A new instance of GemDependency.
- #install ⇒ Object
- #load ⇒ Object
- #load_paths_added? ⇒ Boolean
- #loaded? ⇒ Boolean
- #specification ⇒ Object
- #unpack_to(directory) ⇒ Object
- #unpacked_paths ⇒ Object
Constructor Details
#initialize(name, options = {}) ⇒ GemDependency
Returns a new instance of GemDependency.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/rails/gem_dependency.rb', line 9 def initialize(name, = {}) require 'rubygems' unless Object.const_defined?(:Gem) if [:requirement] @requirement = [:requirement] elsif [:version] @requirement = Gem::Requirement.create([:version]) end @version = @requirement.instance_variable_get("@requirements").first.last if @requirement @name = name.to_s @lib = [:lib] @source = [:source] @loaded = @frozen = @load_paths_added = false @unpack_directory = nil end |
Instance Attribute Details
#lib ⇒ Object
Returns the value of attribute lib.
3 4 5 |
# File 'lib/rails/gem_dependency.rb', line 3 def lib @lib end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/rails/gem_dependency.rb', line 3 def name @name end |
#requirement ⇒ Object
Returns the value of attribute requirement.
3 4 5 |
# File 'lib/rails/gem_dependency.rb', line 3 def requirement @requirement end |
#source ⇒ Object
Returns the value of attribute source.
3 4 5 |
# File 'lib/rails/gem_dependency.rb', line 3 def source @source end |
#version ⇒ Object
Returns the value of attribute version.
3 4 5 |
# File 'lib/rails/gem_dependency.rb', line 3 def version @version end |
Class Method Details
.unpacked_path ⇒ Object
5 6 7 |
# File 'lib/rails/gem_dependency.rb', line 5 def self.unpacked_path @unpacked_path ||= File.join(RAILS_ROOT, 'vendor', 'gems') end |
Instance Method Details
#==(other) ⇒ Object
101 102 103 |
# File 'lib/rails/gem_dependency.rb', line 101 def ==(other) self.name == other.name && self.requirement == other.requirement end |
#add_load_paths ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rails/gem_dependency.rb', line 30 def add_load_paths return if @loaded || @load_paths_added unpacked_paths = self.unpacked_paths if unpacked_paths.empty? args = [@name] args << @requirement.to_s if @requirement gem *args else $LOAD_PATH.unshift File.join(unpacked_paths.first, 'lib') ext = File.join(unpacked_paths.first, 'ext') $LOAD_PATH.unshift(ext) if File.exist?(ext) @frozen = true end @load_paths_added = true rescue Gem::LoadError end |
#dependencies ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/rails/gem_dependency.rb', line 47 def dependencies all_dependencies = specification.dependencies.map do |dependency| GemDependency.new(dependency.name, :requirement => dependency.version_requirements) end all_dependencies += all_dependencies.map(&:dependencies).flatten all_dependencies.uniq end |
#frozen? ⇒ Boolean
68 69 70 |
# File 'lib/rails/gem_dependency.rb', line 68 def frozen? @frozen end |
#gem_dir(base_directory) ⇒ Object
55 56 57 |
# File 'lib/rails/gem_dependency.rb', line 55 def gem_dir(base_directory) File.join(base_directory, specification.full_name) end |
#install ⇒ Object
80 81 82 83 84 |
# File 'lib/rails/gem_dependency.rb', line 80 def install cmd = "#{gem_command} #{install_command.join(' ')}" puts cmd puts %x(#{cmd}) end |
#load ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/rails/gem_dependency.rb', line 59 def load return if @loaded || @load_paths_added == false require(@lib || @name) unless @lib == false @loaded = true rescue LoadError puts $!.to_s $!.backtrace.each { |b| puts b } end |
#load_paths_added? ⇒ Boolean
76 77 78 |
# File 'lib/rails/gem_dependency.rb', line 76 def load_paths_added? @load_paths_added end |
#loaded? ⇒ Boolean
72 73 74 |
# File 'lib/rails/gem_dependency.rb', line 72 def loaded? @loaded end |
#specification ⇒ Object
105 106 107 |
# File 'lib/rails/gem_dependency.rb', line 105 def specification @spec ||= Gem.source_index.search(Gem::Dependency.new(@name, @requirement)).sort_by { |s| s.version }.last end |
#unpack_to(directory) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/rails/gem_dependency.rb', line 86 def unpack_to(directory) FileUtils.mkdir_p directory Dir.chdir directory do Gem::GemRunner.new.run(unpack_command) end # 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') File.open(spec_filename, 'w') do |file| file.puts specification.to_yaml end end |
#unpacked_paths ⇒ Object
26 27 28 |
# File 'lib/rails/gem_dependency.rb', line 26 def unpacked_paths Dir[File.join(self.class.unpacked_path, "#{@name}-#{@version || "*"}")] end |