Class: Gem::AvailableSet
- Includes:
- Enumerable
- Defined in:
- lib/rubygems/available_set.rb
Defined Under Namespace
Classes: Tuple
Instance Attribute Summary collapse
-
#remote ⇒ Object
:nodoc:.
-
#set ⇒ Object
readonly
Returns the value of attribute set.
Instance Method Summary collapse
- #<<(o) ⇒ Object
- #add(spec, source) ⇒ Object
- #all_specs ⇒ Object
-
#each ⇒ Object
Yields each Tuple in this AvailableSet.
-
#each_spec ⇒ Object
Yields the Gem::Specification for each Tuple in this AvailableSet.
- #empty? ⇒ Boolean
-
#find_all(req) ⇒ Object
Used by the Resolver, the protocol to use a AvailableSet as a search Set.
-
#initialize ⇒ AvailableSet
constructor
A new instance of AvailableSet.
- #inject_into_list(dep_list) ⇒ Object
- #match_platform! ⇒ Object
- #pick_best! ⇒ Object
- #prefetch(reqs) ⇒ Object
- #remove_installed!(dep) ⇒ Object
- #size ⇒ Object
- #sorted ⇒ Object
- #source_for(spec) ⇒ Object
-
#to_request_set(development = :none) ⇒ Object
Converts this AvailableSet into a RequestSet that can be used to install gems.
Constructor Details
#initialize ⇒ AvailableSet
Returns a new instance of AvailableSet.
9 10 11 12 13 |
# File 'lib/rubygems/available_set.rb', line 9 def initialize @set = [] @sorted = nil @remote = true end |
Instance Attribute Details
#remote ⇒ Object
:nodoc:
7 8 9 |
# File 'lib/rubygems/available_set.rb', line 7 def remote @remote end |
#set ⇒ Object (readonly)
Returns the value of attribute set.
15 16 17 |
# File 'lib/rubygems/available_set.rb', line 15 def set @set end |
Instance Method Details
#<<(o) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rubygems/available_set.rb', line 23 def <<(o) case o when Gem::AvailableSet s = o.set when Array s = o.map do |sp,so| if !sp.kind_of?(Gem::Specification) or !so.kind_of?(Gem::Source) raise TypeError, "Array must be in [[spec, source], ...] form" end Tuple.new(sp,so) end else raise TypeError, "must be a Gem::AvailableSet" end @set += s @sorted = nil self end |
#add(spec, source) ⇒ Object
17 18 19 20 21 |
# File 'lib/rubygems/available_set.rb', line 17 def add(spec, source) @set << Tuple.new(spec, source) @sorted = nil self end |
#all_specs ⇒ Object
71 72 73 |
# File 'lib/rubygems/available_set.rb', line 71 def all_specs @set.map {|t| t.spec } end |
#each ⇒ Object
Yields each Tuple in this AvailableSet
48 49 50 51 52 53 54 |
# File 'lib/rubygems/available_set.rb', line 48 def each return enum_for __method__ unless block_given? @set.each do |tuple| yield tuple end end |
#each_spec ⇒ Object
Yields the Gem::Specification for each Tuple in this AvailableSet
59 60 61 62 63 64 65 |
# File 'lib/rubygems/available_set.rb', line 59 def each_spec return enum_for __method__ unless block_given? each do |tuple| yield tuple.spec end end |
#empty? ⇒ Boolean
67 68 69 |
# File 'lib/rubygems/available_set.rb', line 67 def empty? @set.empty? end |
#find_all(req) ⇒ Object
Used by the Resolver, the protocol to use a AvailableSet as a search Set.
125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/rubygems/available_set.rb', line 125 def find_all(req) dep = req.dependency match = @set.find_all do |t| dep.match? t.spec end match.map do |t| Gem::Resolver::LocalSpecification.new(self, t.spec, t.source) end end |
#inject_into_list(dep_list) ⇒ Object
161 162 163 |
# File 'lib/rubygems/available_set.rb', line 161 def inject_into_list(dep_list) @set.each {|t| dep_list.add t.spec } end |
#match_platform! ⇒ Object
75 76 77 78 79 |
# File 'lib/rubygems/available_set.rb', line 75 def match_platform! @set.reject! {|t| !Gem::Platform.match_spec?(t.spec) } @sorted = nil self end |
#pick_best! ⇒ Object
140 141 142 143 144 145 146 |
# File 'lib/rubygems/available_set.rb', line 140 def pick_best! return self if empty? @set = [sorted.first] @sorted = nil self end |
#prefetch(reqs) ⇒ Object
137 138 |
# File 'lib/rubygems/available_set.rb', line 137 def prefetch(reqs) end |
#remove_installed!(dep) ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/rubygems/available_set.rb', line 148 def remove_installed!(dep) @set.reject! do |t| # already locally installed Gem::Specification.any? do |installed_spec| dep.name == installed_spec.name and dep.requirement.satisfied_by? installed_spec.version end end @sorted = nil self end |
#size ⇒ Object
88 89 90 |
# File 'lib/rubygems/available_set.rb', line 88 def size @set.size end |
#sorted ⇒ Object
81 82 83 84 85 86 |
# File 'lib/rubygems/available_set.rb', line 81 def sorted @sorted ||= @set.sort do |a,b| i = b.spec <=> a.spec i != 0 ? i : (a.source <=> b.source) end end |
#source_for(spec) ⇒ Object
92 93 94 95 |
# File 'lib/rubygems/available_set.rb', line 92 def source_for(spec) f = @set.find {|t| t.spec == spec } f.source end |
#to_request_set(development = :none) ⇒ Object
Converts this AvailableSet into a RequestSet that can be used to install gems.
If development
is :none then no development dependencies are installed. Other options are :shallow for only direct development dependencies of the gems in this set or :all for all development dependencies.
105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/rubygems/available_set.rb', line 105 def to_request_set(development = :none) request_set = Gem::RequestSet.new request_set.development = :all == development each_spec do |spec| request_set.always_install << spec request_set.gem spec.name, spec.version request_set.import spec.development_dependencies if :shallow == development end request_set end |