Class: Hubless::GemDescription

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ GemDescription

New GemDescription from a one-liner or options Hash Hubless::GemDescription.new(‘my-awesome_gem-3.4.5’) Hubless::GemDescription.new(:name => ‘my-awesome_gem’, :version => ‘3.4.5’)



20
21
22
23
24
25
26
27
28
# File 'lib/gem_description.rb', line 20

def initialize(*args)
  case args.first
  when String
    self.attributes_from_one_liner(args.first)
  when Hash
    self.name    = args.first[:name]
    self.version = args.first[:version]
  end
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



9
10
11
# File 'lib/gem_description.rb', line 9

def name
  @name
end

#versionObject

Returns the value of attribute version.



10
11
12
# File 'lib/gem_description.rb', line 10

def version
  @version
end

Class Method Details

.local_gemsObject

GemDescriptions of all gems installed locally



13
14
15
# File 'lib/gem_description.rb', line 13

def self.local_gems
  @@local_gems ||= Gem.cache.map {|g| new(g.first) }.sort!{|x,y| y.name <=> x.name }
end

Instance Method Details

#gemcutter?Boolean

Does a gem exist on Gemcutter that matches this gem

Returns:

  • (Boolean)


55
56
57
58
59
60
61
# File 'lib/gem_description.rb', line 55

def gemcutter?
  if @is_gemcutter.nil?
    @is_gemcutter = self.gemcutter_gem_exist?
  else
    @is_gemcutter
  end
end

#gemcutter_nameObject

Likely name of this gem on Gemcutter (without the GitHub username)



64
65
66
# File 'lib/gem_description.rb', line 64

def gemcutter_name
  self.github? ? self.github_repo_name : self.name
end

#github?Boolean

Does a repo exist on GitHub that matches this gem

Returns:

  • (Boolean)


37
38
39
40
41
42
43
# File 'lib/gem_description.rb', line 37

def github?
  if @is_github.nil?
    @is_github = (self.github_like? && self.github_repo_exist?)
  else
    @is_github
  end
end

#github_like?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/gem_description.rb', line 50

def github_like?
  self.github_user_name && self.github_repo_name
end

#github_nameObject

Full name of this gem including GitHub username



46
47
48
# File 'lib/gem_description.rb', line 46

def github_name
  self.name if self.github_user_name
end

#install_cmdObject

Command to install gem from Gemcutter



69
70
71
72
73
74
# File 'lib/gem_description.rb', line 69

def install_cmd
  cmd = ["gem install"]
  cmd << self.gemcutter_name
  cmd << "-v #{self.version}" if self.version
  cmd.join(' ')
end

#uninstall_cmdObject

Command to uninstall gem



77
78
79
80
81
82
# File 'lib/gem_description.rb', line 77

def uninstall_cmd
  cmd = ["gem uninstall"]
  cmd << self.name
  cmd << "-v #{self.version}" if self.version
  cmd.join(' ')
end