Class: Reactive::GemDependency
- Defined in:
- lib/reactive-core/gem_dependency.rb
Overview
:nodoc:
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
-
.missing_gems ⇒ Object
Returns an Array of missing gems.
- .report_gems_state(with_dependencies = true) ⇒ Object
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #dependencies ⇒ Object
- #embed ⇒ Object
- #embedded? ⇒ Boolean
- #hash ⇒ Object
- #init_plugin ⇒ Object
-
#initialize(name, options = {}) ⇒ GemDependency
constructor
A new instance of GemDependency.
- #install ⇒ Object
- #installed? ⇒ Boolean
- #load ⇒ Object
- #loaded? ⇒ Boolean
- #loaded_spec ⇒ Object
Constructor Details
#initialize(name, options = {}) ⇒ GemDependency
Returns a new instance of GemDependency.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/reactive-core/gem_dependency.rb', line 5 def initialize(name, = {}) require 'rubygems' unless Object.const_defined?(:Gem) = {:version => } if .is_a? String 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] @init = [:init] @loaded = false end |
Instance Attribute Details
#lib ⇒ Object
Returns the value of attribute lib.
3 4 5 |
# File 'lib/reactive-core/gem_dependency.rb', line 3 def lib @lib end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/reactive-core/gem_dependency.rb', line 3 def name @name end |
#requirement ⇒ Object
Returns the value of attribute requirement.
3 4 5 |
# File 'lib/reactive-core/gem_dependency.rb', line 3 def requirement @requirement end |
#source ⇒ Object
Returns the value of attribute source.
3 4 5 |
# File 'lib/reactive-core/gem_dependency.rb', line 3 def source @source end |
#version ⇒ Object
Returns the value of attribute version.
3 4 5 |
# File 'lib/reactive-core/gem_dependency.rb', line 3 def version @version end |
Class Method Details
.missing_gems ⇒ Object
Returns an Array of missing gems
223 224 225 226 227 228 |
# File 'lib/reactive-core/gem_dependency.rb', line 223 def self.missing_gems Reactive.configuration.gems.inject([]) do |missing, gem| missing << gem unless gem.installed? gem.dependencies.inject(missing) {|missing, dependency| dependency.installed? ? missing : missing << dependency} end.uniq end |
.report_gems_state(with_dependencies = true) ⇒ Object
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/reactive-core/gem_dependency.rb', line 201 def self.report_gems_state(with_dependencies = true) Reactive.configuration.gems.inject('') do |report, gem| installed_dependency_count = 0 dependencies_status = gem.dependencies.collect do |dependency| if dependency.installed? code = dependency. ? "E" : "I" installed_dependency_count += 1 else code = " " end " [#{code}] #{dependency.name} #{dependency.requirement.to_s}\n" end.uniq code = gem.installed? ? (gem. ? "E" : "I") : " " code.downcase! if installed_dependency_count != gem.dependencies.size report << "[#{code}] #{gem.name} #{gem.requirement.to_s}\n" report << dependencies_status.join('') if with_dependencies report end << "I = Installed, i = Installed but missing dependencies\nE = Embedded, e = Embedded but missing dependencies" end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
107 108 109 |
# File 'lib/reactive-core/gem_dependency.rb', line 107 def ==(other) self.name == other.name && self.requirement == other.requirement end |
#dependencies ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/reactive-core/gem_dependency.rb', line 24 def dependencies if spec = specification all_dependencies = spec.dependencies.map do |dependency| GemDependency.new(dependency.name, :requirement => dependency.version_requirements) end all_dependencies += all_dependencies.map(&:dependencies).flatten all_dependencies.uniq else [] end end |
#embed ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/reactive-core/gem_dependency.rb', line 89 def return "#{name} #{requirement} is already embedded." if # If the gem is already installed, use Gem::Installer to embed because we only need gem files and the spec if installed? require 'rubygems/installer' path = get_gem_path(name, requirement) basename = File.basename(path).sub(/\.gem$/, '') installer = Gem::Installer.new(path, :install_dir => Reactive.path_for('gems')) installer.unpack Reactive.path_for('gems', 'gems', basename) installer.write_spec @embedded = true "Successfully embedded #{name} #{installer.spec.version}" else cmd = "#{gem_command} #{install_command.join(' ')} -i #{Reactive.path_for('gems')} --ignore-dependencies" [cmd, %x(#{cmd})] end end |
#embedded? ⇒ Boolean
66 67 68 69 70 |
# File 'lib/reactive-core/gem_dependency.rb', line 66 def return true if @embedded return false unless specification File.(specification.installation_path) == File.(Reactive.path_for('gems')) end |
#hash ⇒ Object
111 112 113 |
# File 'lib/reactive-core/gem_dependency.rb', line 111 def hash "#{name}#{requirement}".hash end |
#init_plugin ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/reactive-core/gem_dependency.rb', line 46 def init_plugin if @init == :rails require(@lib) if @lib else require(@lib || @name) unless @lib == false end gem_path = File.(specification.full_gem_path) specification.require_paths.map {|path| File.join(gem_path, path) }.each do |path| begin require File.join(path, 'reactive', 'init.rb') return rescue LoadError # No reactive init code, let's try a Rails init code if @init == :rails return if load_rails_init(path) end end end end |
#install ⇒ Object
84 85 86 87 |
# File 'lib/reactive-core/gem_dependency.rb', line 84 def install cmd = "#{gem_command} #{install_command.join(' ')}" [cmd, %x(#{cmd})] end |
#installed? ⇒ Boolean
72 73 74 |
# File 'lib/reactive-core/gem_dependency.rb', line 72 def installed? loaded? || specification end |
#load ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/reactive-core/gem_dependency.rb', line 36 def load return if @loaded args = [@name] args << @requirement.to_s if @requirement gem *args # Now, run its reactive init code init_plugin @loaded = true end |
#loaded? ⇒ Boolean
76 77 78 |
# File 'lib/reactive-core/gem_dependency.rb', line 76 def loaded? @loaded end |