Class: Sprout::Index
- Inherits:
-
Object
- Object
- Sprout::Index
- Defined in:
- lib/sprout/bundle_resolver.rb
Class Method Summary collapse
Instance Method Summary collapse
- #<<(spec) ⇒ Object
- #each(&blk) ⇒ Object
- #empty? ⇒ Boolean
- #freeze ⇒ Object
-
#initialize ⇒ Index
constructor
A new instance of Index.
- #initialize_copy(o) ⇒ Object
- #merge(other) ⇒ Object
- #merge!(other) ⇒ Object
- #search(query) ⇒ Object (also: #[])
Constructor Details
#initialize ⇒ Index
Returns a new instance of Index.
38 39 40 41 |
# File 'lib/sprout/bundle_resolver.rb', line 38 def initialize @cache = {} @specs = Hash.new { |h,k| h[k] = [] } end |
Class Method Details
.from_cached_specs(path) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/sprout/bundle_resolver.rb', line 27 def self.from_cached_specs(path) # index = Index.new # Sprout::cache # Dir["#{path}/*.gem"].each do |gemfile| # spec = Gem::Format.from_file_by_path(gemfile).spec # index << spec # end # index end |
.from_installed_gems ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/sprout/bundle_resolver.rb', line 18 def self.from_installed_gems #Source::SystemGems.new.specs index = Index.new Gem::cache.each do |name, spec| index << spec end index end |
Instance Method Details
#<<(spec) ⇒ Object
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/sprout/bundle_resolver.rb', line 65 def <<(spec) arr = @specs[spec.name] arr.delete_if do |s| s.version == spec.version && s.platform == spec.platform end arr << spec spec end |
#each(&blk) ⇒ Object
76 77 78 79 80 |
# File 'lib/sprout/bundle_resolver.rb', line 76 def each(&blk) @specs.values.each do |specs| specs.each(&blk) end end |
#empty? ⇒ Boolean
50 51 52 53 |
# File 'lib/sprout/bundle_resolver.rb', line 50 def empty? each { return false } true end |
#freeze ⇒ Object
93 94 95 96 97 98 |
# File 'lib/sprout/bundle_resolver.rb', line 93 def freeze @specs.each do |k,v| v.freeze end super end |
#initialize_copy(o) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/sprout/bundle_resolver.rb', line 43 def initialize_copy(o) super @cache = {} @specs = Hash.new { |h,k| h[k] = [] } merge!(o) end |
#merge(other) ⇒ Object
89 90 91 |
# File 'lib/sprout/bundle_resolver.rb', line 89 def merge(other) dup.merge!(other) end |
#merge!(other) ⇒ Object
82 83 84 85 86 87 |
# File 'lib/sprout/bundle_resolver.rb', line 82 def merge!(other) other.each do |spec| self << spec end self end |
#search(query) ⇒ Object Also known as: []
55 56 57 58 59 60 61 |
# File 'lib/sprout/bundle_resolver.rb', line 55 def search(query) case query when Gem::Specification then search_by_spec(query) when String then @specs[query] else search_by_dependency(query) end end |