Class: Bundler::Whatsup::Gemfile

Inherits:
Object
  • Object
show all
Defined in:
lib/bundler/whatsup/gemfile.rb

Overview

Works with dependencies and specs described in Gemfile

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGemfile

Returns a new instance of Gemfile.


9
10
11
12
13
# File 'lib/bundler/whatsup/gemfile.rb', line 9

def initialize
  b = Bundler.load
  @specs = b.specs.sort_by(&:name)
  @dependencies = b.dependencies.sort_by(&:name)
end

Instance Attribute Details

#dependenciesObject

Returns the value of attribute dependencies


7
8
9
# File 'lib/bundler/whatsup/gemfile.rb', line 7

def dependencies
  @dependencies
end

#specsObject

Returns the value of attribute specs


7
8
9
# File 'lib/bundler/whatsup/gemfile.rb', line 7

def specs
  @specs
end

Instance Method Details

#dependencies_versionsHash

Returns Hash: dependency_name=>version

Returns:

  • (Hash)

38
39
40
41
42
43
44
45
# File 'lib/bundler/whatsup/gemfile.rb', line 38

def dependencies_versions
  dependencies_versions = {}
  dependencies.each do |dependency|
    dependencies_versions[dependency.name.to_sym] = specs_versions[dependency.name.to_sym]
  end

  dependencies_versions
end

#specs_versionsHash

Returns Hash: spec_name=>version

Returns:

  • (Hash)

26
27
28
29
30
31
32
33
# File 'lib/bundler/whatsup/gemfile.rb', line 26

def specs_versions
  specs_versions = {}
  specs.map do |spec|
    specs_versions[spec.name.to_sym] = spec.version.to_s
  end

  specs_versions
end

#version_of(gem) ⇒ String|nil

Returns current version of given gem if it is installed, or nil

Parameters:

  • gem (String)

    name of gem

Returns:

  • (String|nil)

    version of gem


19
20
21
# File 'lib/bundler/whatsup/gemfile.rb', line 19

def version_of(gem)
  specs_versions[gem.to_sym]
end