Class: Gemi::Gem

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

Defined Under Namespace

Classes: OptionNotSupported

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, version = nil, options = {}) ⇒ Gem

Returns a new instance of Gem.



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

def initialize(name, version=nil, options={})
  @name, @version, @options = name, version, options
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



28
29
30
# File 'lib/gemi/gem.rb', line 28

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



28
29
30
# File 'lib/gemi/gem.rb', line 28

def options
  @options
end

#versionObject (readonly)

Returns the value of attribute version.



28
29
30
# File 'lib/gemi/gem.rb', line 28

def version
  @version
end

Class Method Details

.from_yaml(yaml) ⇒ Object

Returns an array of Gem



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/gemi/gem.rb', line 7

def self.from_yaml(yaml)
  return [] unless yaml["gems"]

  yaml["gems"].map{|spec|
    options = {
      :install => spec["install_options"],
      :uninstall => spec["uninstall_options"],
    }
    %w(update_options clean_options).each do |key|
      if spec[key]
        raise OptionNotSupported, "you cannot specify #{key} in YAML file"
      end
    end
    new(spec["name"], spec["version"], options)
  }
end

Instance Method Details

#to_command(type) ⇒ Object



30
31
32
33
34
35
# File 'lib/gemi/gem.rb', line 30

def to_command(type)
  s = @name
  s << " -v #{@version}" if @version
  s << " #{@options[type]}" if @options[type]
  s
end