Class: Gemsconfig::Entry

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, attrs) ⇒ Entry

Returns a new instance of Entry.



7
8
9
10
11
12
13
14
# File 'lib/gemsconfig/entry.rb', line 7

def initialize(name, attrs)
  attrs ||= {}
  @name = name
  @lib = attrs[:lib]
  @lib = attrs['lib'] if @lib.nil?
  @version = attrs[:version] || attrs['version']
  @source = attrs[:source] || attrs['source']
end

Instance Attribute Details

#libObject (readonly)

Returns the value of attribute lib.



5
6
7
# File 'lib/gemsconfig/entry.rb', line 5

def lib
  @lib
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/gemsconfig/entry.rb', line 5

def name
  @name
end

#sourceObject (readonly)

Returns the value of attribute source.



5
6
7
# File 'lib/gemsconfig/entry.rb', line 5

def source
  @source
end

#versionObject (readonly)

Returns the value of attribute version.



5
6
7
# File 'lib/gemsconfig/entry.rb', line 5

def version
  @version
end

Instance Method Details

#installObject



31
32
33
34
35
# File 'lib/gemsconfig/entry.rb', line 31

def install
  cmd = install_gem_command
  puts cmd
  puts %x(#{cmd})
end

#loadObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/gemsconfig/entry.rb', line 16

def load
  begin
    unless @lib == false
      gem name, version_spec if @version
      require (@lib || @name)
    end
  rescue LoadError => err
    raise LoadError, "\nGemsconfig: could not load configured gem '#{@name}'#{" (#{@lib})" if @lib} - #{err.message}\n\nTry:\nrake gemsconfig:install\n--or--\n#{install_gem_command}\n\n"
  end
end

#loaded?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/gemsconfig/entry.rb', line 27

def loaded?
  %x(#{gem_command} #{list_command.join(' ')}).split("\n").detect{|listing| listing =~ Regexp.new("#{name}\s+.+#{Regexp.escape(@version) if @version}.+")}
end