Class: Mack::Utils::GemManager

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/mack/utils/gem_manager.rb

Overview

This class is used to add gems to your application in an easy to use way.

require_gems do |gem|
  gem.add :redgreen, :version => "1.2.2", :libs => :redgreen
  gem.add :termios
  gem.add "rubyzip", :source => "http:// gems.rubyforge.org"
end

Defined Under Namespace

Classes: GemObject

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGemManager

:nodoc:



15
16
17
# File 'lib/mack/utils/gem_manager.rb', line 15

def initialize # :nodoc:
  @required_gem_list = []
end

Instance Attribute Details

#required_gem_listObject

Returns the value of attribute required_gem_list.



13
14
15
# File 'lib/mack/utils/gem_manager.rb', line 13

def required_gem_list
  @required_gem_list
end

Instance Method Details

#add(name, options = {}) ⇒ Object

Adds a new gem to the system. This does NOT actually require the gem or any of it’s ‘libs’. You need to call the do_requires method to actually require any of the ‘libs’ defined for this gem.

Options:

  • :source => "http:// gems.rubyforge.org"

  • :version => "1.2.3"

  • :libs => "file" or :libs => ["file1", "file2"]



27
28
29
# File 'lib/mack/utils/gem_manager.rb', line 27

def add(name, options = {})
  @required_gem_list << Mack::Utils::GemManager::GemObject.new(name, options)
end

#do_requiresObject

Requires the gem and any libs that you’ve specified.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/mack/utils/gem_manager.rb', line 32

def do_requires
  @required_gem_list.each do |g|
    begin
      if g.version?
        gem(g.name, g.version)
      else
        gem(g.name)
      end
      g.libs.each { |l| require l.to_s } if g.libs?
    rescue Gem::LoadError => er
      Mack.logger.warn "WARNING: gem #{g.name} [version: #{g.version}] is required, but is not installed"
      raise er
    end
  end
end

#do_task_requiresObject

Requires the gem and any libs that you’ve specified.



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/mack/utils/gem_manager.rb', line 49

def do_task_requires
  @required_gem_list.each do |g|
    begin
      if g.version?
        gem(g.name, g.version)
      else
        gem(g.name)
      end
      g.tasks.each { |l| require l.to_s } if g.tasks?
    rescue Exception => e
    end
  end
end