Class: Gem::Dependency

Inherits:
Micro::YAMLable show all
Defined in:
lib/microgem/dependency.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Micro::YAMLable

[], inherited

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/microgem/dependency.rb', line 7

def name
  @name
end

#versionObject (readonly)

Returns the value of attribute version.



7
8
9
# File 'lib/microgem/dependency.rb', line 7

def version
  @version
end

#version_requirementsObject (readonly)

Returns the value of attribute version_requirements.



7
8
9
# File 'lib/microgem/dependency.rb', line 7

def version_requirements
  @version_requirements
end

Instance Method Details

#gem_specObject

Returns the Gem::Specification instance for this dependency. If the required version is ‘0’ then the latest version is used.



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

def gem_spec
  if @gem_spec.nil?
    unless @gem_spec = Micro::Source.gem_spec(@name, @version_requirements.version)
      raise Micro::GemSpecMissingError, "Unable to locate Gem::Specification for Gem::Dependency `#{self}'"
    end
  end
  
  @gem_spec
end

#meets_requirements?Boolean

Returns whether or not any of the installed gems matches the requirements.

For now we just compare against the last one which should be the highest.

Returns:

  • (Boolean)


12
13
14
15
16
# File 'lib/microgem/dependency.rb', line 12

def meets_requirements?
  if dirname = Micro.installed_gem_dirnames(name).last
    Gem::Version.from_gem_dirname(dirname) >= @version_requirements.version
  end
end

#to_sObject

Returns a ‘pretty’ string representation of the Dependency instance:

dependency.to_s # => "rake >= 0.8.1"


33
34
35
# File 'lib/microgem/dependency.rb', line 33

def to_s
  "#{name} #{@version_requirements}"
end