Class: Isolate::Entry
Overview
An isolated Gem, with requirement, environment restrictions, and installation options. Generally intended for internal use. This class exposes lifecycle events for extension, see Isolate::Events for more information.
Instance Attribute Summary collapse
-
#environments ⇒ Object
readonly
Which environments does this entry care about? Generally an Array of Strings.
-
#name ⇒ Object
readonly
What’s the name of this entry? Generally the name of a gem.
-
#options ⇒ Object
readonly
Extra information or hints for installation.
-
#requirement ⇒ Object
readonly
What version of this entry is required? Expressed as a Gem::Requirement, which see.
Instance Method Summary collapse
-
#activate ⇒ Object
Activate this entry.
-
#initialize(sandbox, name, *requirements) ⇒ Entry
constructor
Create a new entry.
-
#install ⇒ Object
Install this entry in the sandbox.
-
#matches?(environment) ⇒ Boolean
Is this entry interested in
environment
?. -
#matches_spec?(spec) ⇒ Boolean
Is this entry satisfied by
spec
(generally a Gem::Specification)?. -
#specification ⇒ Object
The Gem::Specification for this entry or nil if it isn’t resolveable.
- #to_s ⇒ Object (also: #inspect)
-
#update(*reqs) ⇒ Object
Updates this entry’s environments, options, and requirement.
Methods included from Events
Constructor Details
#initialize(sandbox, name, *requirements) ⇒ Entry
Create a new entry. Takes sandbox
(currently an instance of Isolate::Sandbox), name
(as above), and any number of optional version requirements (generally strings). Options can be passed as a trailing hash. Well-known keys:
- :args
-
Command-line build arguments. Passed to the gem at installation time.
- :source
-
An alternative RubyGems source for this gem.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/isolate/entry.rb', line 47 def initialize sandbox, name, *requirements @environments = [] @file = nil @name = name @options = {} @requirement = Gem::Requirement.default @sandbox = sandbox if /\.gem$/ =~ @name && File.file?(@name) @file = File. @name @name = File.basename(@file, ".gem"). gsub(/-#{Gem::Version::VERSION_PATTERN}$/, "") end update(*requirements) end |
Instance Attribute Details
#environments ⇒ Object (readonly)
Which environments does this entry care about? Generally an Array of Strings. An empty array means “all”, not “none”.
21 22 23 |
# File 'lib/isolate/entry.rb', line 21 def environments @environments end |
#name ⇒ Object (readonly)
What’s the name of this entry? Generally the name of a gem.
25 26 27 |
# File 'lib/isolate/entry.rb', line 25 def name @name end |
#options ⇒ Object (readonly)
Extra information or hints for installation. See initialize
for well-known keys.
30 31 32 |
# File 'lib/isolate/entry.rb', line 30 def @options end |
#requirement ⇒ Object (readonly)
What version of this entry is required? Expressed as a Gem::Requirement, which see.
35 36 37 |
# File 'lib/isolate/entry.rb', line 35 def requirement @requirement end |
Instance Method Details
#activate ⇒ Object
Activate this entry. Fires :activating
and :activated
.
68 69 70 71 72 73 74 |
# File 'lib/isolate/entry.rb', line 68 def activate fire :activating, :activated do spec = self.specification raise Gem::LoadError, "Couldn't resolve: #{self}" unless spec spec.activate end end |
#install ⇒ Object
Install this entry in the sandbox. Fires :installing
and :installed
.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/isolate/entry.rb', line 79 def install old = Gem.sources.dup begin fire :installing, :installed do installer = Gem::DependencyInstaller.new(:development => false, :document => [], :generate_rdoc => false, :generate_ri => false, :install_dir => @sandbox.path) Gem::Command.build_args = Array([:args]) if [:args] Gem.sources += Array([:source]) if [:source] installer.install @file || name, requirement end ensure Gem.sources = old Gem::Command.build_args = nil end end |
#matches?(environment) ⇒ Boolean
Is this entry interested in environment
?
105 106 107 |
# File 'lib/isolate/entry.rb', line 105 def matches? environment environments.empty? || environments.include?(environment) end |
#matches_spec?(spec) ⇒ Boolean
Is this entry satisfied by spec
(generally a Gem::Specification)?
112 113 114 |
# File 'lib/isolate/entry.rb', line 112 def matches_spec? spec name == spec.name and requirement.satisfied_by? spec.version end |
#specification ⇒ Object
The Gem::Specification for this entry or nil if it isn’t resolveable.
118 119 120 121 122 |
# File 'lib/isolate/entry.rb', line 118 def specification Gem::Specification.find_by_name(name, requirement) rescue Gem::LoadError nil end |
#to_s ⇒ Object Also known as: inspect
138 139 140 |
# File 'lib/isolate/entry.rb', line 138 def to_s "Entry[#{name.inspect}, #{requirement.to_s.inspect}]" end |
#update(*reqs) ⇒ Object
Updates this entry’s environments, options, and requirement. Environments and options are merged, requirement is replaced. Fires :updating
and :updated
.
128 129 130 131 132 133 134 135 136 |
# File 'lib/isolate/entry.rb', line 128 def update *reqs fire :updating, :updated do @environments |= @sandbox.environments @options.merge! reqs.pop if Hash === reqs.last @requirement = Gem::Requirement.new reqs unless reqs.empty? end self end |