Class: Gemtronics::Definition
- Inherits:
-
Hash
- Object
- Hash
- Gemtronics::Definition
- Defined in:
- lib/gemtronics/definition.rb
Overview
Represents the definition of a Gem.
Instance Attribute Summary collapse
-
#name ⇒ Object
Get/set the name of the gem.
-
#source ⇒ Object
Get/set the source of the gem.
-
#update_version ⇒ Object
:nodoc:.
-
#version ⇒ Object
Get/set the version of the gem.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #has_update? ⇒ Boolean
-
#install_command ⇒ Object
Generates an install command string.
-
#installed? ⇒ Boolean
Returns
true/false
depending on whether the gem is installed or not. -
#load=(x) ⇒ Object
Set whether the gem should be required.
-
#load? ⇒ Boolean
Returns true/false if the gem should be required.
-
#load_gem ⇒ Object
Calls the
gem
method withname
andversion
. -
#require_gem(options = {}) ⇒ Object
Calls the
load_gem
method and then requires each file in therequire_list
. -
#require_list ⇒ Object
Returns an Array of files that should be required.
-
#require_list=(x) ⇒ Object
Sets the names of the files that should be required.
-
#ri=(x) ⇒ Object
Set whether the gem should be installed with ri.
-
#ri? ⇒ Boolean
Returns true/false if the gem should be installed with ri.
-
#to_s ⇒ Object
Returns
<name>-<version>
.
Instance Attribute Details
#name ⇒ Object
Get/set the name of the gem.
6 7 8 |
# File 'lib/gemtronics/definition.rb', line 6 def name @name end |
#source ⇒ Object
Get/set the source of the gem. Defaults to http://gems.rubyforge.org
10 11 12 |
# File 'lib/gemtronics/definition.rb', line 10 def source @source end |
#update_version ⇒ Object
:nodoc:
12 13 14 |
# File 'lib/gemtronics/definition.rb', line 12 def update_version @update_version end |
#version ⇒ Object
Get/set the version of the gem. Defaults to >=0.0.0
8 9 10 |
# File 'lib/gemtronics/definition.rb', line 8 def version @version end |
Instance Method Details
#<=>(other) ⇒ Object
131 132 133 |
# File 'lib/gemtronics/definition.rb', line 131 def <=>(other) "#{self.name.downcase}-#{self.version}" <=> "#{other.name.downcase}-#{other.version}" end |
#has_update? ⇒ Boolean
118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/gemtronics/definition.rb', line 118 def has_update? cmd = "gem list --remote ^#{self.name}$" res = `#{cmd}` return false unless res.is_a?(String) res.match(/^#{self.name}\s\(([\d\.]+)/) ext_v = $1 return false if ext_v.nil? self.version.match(/[^\d]{0,2}(.+)$/) v = $1 self.update_version = ext_v return ext_v > v ? self : false end |
#install_command ⇒ Object
Generates an install command string.
Example:
gd = Gemtronics::Definition.new
gd.name = 'configatron'
gd.version = '2.3.0'
gd.install_command #=> 'gem install configatron --source=http://gems.rubyforge.org --version=2.3.0'
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/gemtronics/definition.rb', line 63 def install_command cmd = "gem install #{self.name}" if self.source cmd << " --source=#{self.source}" end unless self.ri? cmd << ' --no-ri' end unless self.rdoc? cmd << ' --no-rdoc' end unless self.version.match(/^(\>\=|\>)/) cmd << " --version=#{self.version}" end return cmd end |
#installed? ⇒ Boolean
Returns true/false
depending on whether the gem is installed or not.
86 87 88 89 90 91 92 93 94 |
# File 'lib/gemtronics/definition.rb', line 86 def installed? begin gem(self.name, self.version) return true rescue Gem::LoadError => e return true if e..match(/can't activate/) return false end end |
#load=(x) ⇒ Object
Set whether the gem should be required.
20 21 22 |
# File 'lib/gemtronics/definition.rb', line 20 def load=(x) # method built dynamically. This is just a stub for RDoc. end |
#load? ⇒ Boolean
Returns true/false if the gem should be required. Defaults to true
.
15 16 17 |
# File 'lib/gemtronics/definition.rb', line 15 def load? # method built dynamically. This is just a stub for RDoc. end |
#load_gem ⇒ Object
Calls the gem
method with name
and version
. It does NOT do any requiring!
Example:
gd = Gemtronics::Definition.new
gd.name = 'my_gem'
gd.version = '1.2.3'
gd.load_gem # => gem('my_gem', '1.2.3')
104 105 106 |
# File 'lib/gemtronics/definition.rb', line 104 def load_gem gem(self.name, self.version) end |
#require_gem(options = {}) ⇒ Object
Calls the load_gem
method and then requires each file in the require_list
110 111 112 113 114 115 116 |
# File 'lib/gemtronics/definition.rb', line 110 def require_gem( = {}) load_gem self.require_list.each do |f| puts "require #{f}" if [:verbose] require f end end |
#require_list ⇒ Object
Returns an Array of files that should be required. Defaults to [<name>]
35 36 37 38 |
# File 'lib/gemtronics/definition.rb', line 35 def require_list return [self.name] unless self.has_key?(:require) return [self.fetch(:require)].flatten end |
#require_list=(x) ⇒ Object
Sets the names of the files that should be required.
41 42 43 |
# File 'lib/gemtronics/definition.rb', line 41 def require_list=(x) self.store(:require, [x].flatten) end |
#ri=(x) ⇒ Object
Set whether the gem should be installed with ri.
30 31 32 |
# File 'lib/gemtronics/definition.rb', line 30 def ri=(x) # method built dynamically. This is just a stub for RDoc. end |
#ri? ⇒ Boolean
Returns true/false if the gem should be installed with ri. Defaults to false
.
25 26 27 |
# File 'lib/gemtronics/definition.rb', line 25 def ri? # method built dynamically. This is just a stub for RDoc. end |
#to_s ⇒ Object
Returns <name>-<version>
.
Example:
gd = Gemtronics::Definition.new
gd.name = 'configatron'
gd.version = '2.3.0'
gd.to_s #=> 'configatron-2.3.0'
52 53 54 |
# File 'lib/gemtronics/definition.rb', line 52 def to_s return "#{self.name}-#{self.version}" end |