Class: Gembox::Gems

Inherits:
Object
  • Object
show all
Defined in:
lib/gembox/gems.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.source_indexObject

Returns the value of attribute source_index.



4
5
6
# File 'lib/gembox/gems.rb', line 4

def source_index
  @source_index
end

Class Method Details

.loadObject



6
7
8
9
10
11
# File 'lib/gembox/gems.rb', line 6

def load
  if !@source_index || reload?
    @source_index = ::Gem.source_index
  end
  local_gems
end

.local_gemsObject



13
14
15
16
17
18
# File 'lib/gembox/gems.rb', line 13

def local_gems
  if !@local_gems || reload?
    @local_gems = group_gems(source_index.gems)
  end
  @local_gems
end

.search(search_term, version = nil, strict = false) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/gembox/gems.rb', line 20

def search(search_term, version = nil, strict = false)
  version = version ? Gem::Requirement.create(version) : Gem::Requirement.default
  escaped = Regexp.escape(search_term)
  regexp = strict ? /^#{escaped}$/ : /#{escaped}/
  gems = source_index.search Gem::Dependency.new(regexp, version)
  group_gems(gems)
end

.statsObject



28
29
30
31
32
33
# File 'lib/gembox/gems.rb', line 28

def stats
  num_versions = source_index.length
  num_gems     = local_gems.length
  newest_gem   = source_index.max {|a,b| a[1].date <=> b[1].date }.last
  {:num_versions => num_versions, :num_gems => num_gems, :newest_gem => newest_gem}
end