Class: Mactag::Indexer::Gem

Inherits:
Object
  • Object
show all
Defined in:
lib/mactag/indexer/gem.rb

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Gem) initialize(name, version = nil)

Returns a new instance of Gem



7
8
9
10
# File 'lib/mactag/indexer/gem.rb', line 7

def initialize(name, version = nil)
  @name = name
  @version = version
end

Instance Attribute Details

- (Object) name

Returns the value of attribute name



4
5
6
# File 'lib/mactag/indexer/gem.rb', line 4

def name
  @name
end

- (Object) version



24
25
26
# File 'lib/mactag/indexer/gem.rb', line 24

def version
  @version || most_recent
end

Class Method Details

+ (Object) all



48
49
50
51
52
53
# File 'lib/mactag/indexer/gem.rb', line 48

def all
  gems = Mactag::Bundler.gems
  gems.map do |name, version|
    new(name, version)
  end
end

+ (Boolean) exist?(name)

Returns:

  • (Boolean)


55
56
57
# File 'lib/mactag/indexer/gem.rb', line 55

def exist?(name)
  new(name).exist?
end

Instance Method Details

- (Object) dirs



43
44
45
# File 'lib/mactag/indexer/gem.rb', line 43

def dirs
  @dirs ||= Dir.glob(File.join(Mactag::Config.gem_home, "#{name}-*"))
end

- (Boolean) exist?

Returns:

  • (Boolean)


20
21
22
# File 'lib/mactag/indexer/gem.rb', line 20

def exist?
  dirs.size > 0
end

- (Object) most_recent



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/mactag/indexer/gem.rb', line 28

def most_recent
  unless dirs.empty?
    if dirs.size == 1
      gem = dirs.first
    else
      gem = dirs.sort.last
    end
    regex = /#{escaped_name}-([^\/]+)/

    if match = regex.match(gem)
      match[1]
    end
  end
end

- (Object) tag



12
13
14
15
16
17
18
# File 'lib/mactag/indexer/gem.rb', line 12

def tag
  if exist?
    File.join(Mactag::Config.gem_home, combo, 'lib', '**', '*.rb')
  else
    raise GemNotFoundError.new(self)
  end
end