Class: Gemstat::Dependency

Inherits:
Object
  • Object
show all
Defined in:
lib/gemstat/dependency.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(folder_path) ⇒ Dependency

Returns a new instance of Dependency.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/gemstat/dependency.rb', line 4

def initialize(folder_path)
  ENV["BUNDLE_GEMFILE"] = "./Gemfile" # set this otherwise you'll get the error: `rescue in root': Could not locate Gemfile or .bundle/ directory (Bundler::GemfileNotFound)
  @gems = []
  if File.exist?("#{folder_path}/Gemfile") then
    @gemfile = "#{folder_path}/Gemfile"
    definition = Bundler::Definition.build @gemfile, nil, nil
    @gems = @gems + definition.dependencies.map{|dependency| dependency.name}
  end
  gemspec_path = Dir.entries(folder_path).select{|name| name.match(/(.*).gemspec\Z/)}[0]
  if gemspec_path then
    @gemspec = folder_path+"/"+gemspec_path
    #@gems = @gems + Gem::Specification.load(@gemspec).dependencies.map{|dependency| dependency.name}
    @gems = Gemspec.new(@gemspec).gems
    @name = gemspec_path.match(/(.*).gemspec\Z/)[1]
  end
  @name = @name || `basename #{folder_path}`.chomp
end

Instance Attribute Details

#gemsObject (readonly)

Returns the value of attribute gems.



3
4
5
# File 'lib/gemstat/dependency.rb', line 3

def gems
  @gems
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/gemstat/dependency.rb', line 3

def name
  @name
end

Instance Method Details

#exist?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/gemstat/dependency.rb', line 22

def exist?
  !@gemfile.nil? || !@gemspec.nil?
end

#gem_nameObject



26
27
28
29
30
31
32
# File 'lib/gemstat/dependency.rb', line 26

def gem_name
  if @name.index(':')
    @name.match(/(.*):(.*)/)[1]
  else
    @name
  end
end

#gem_versionObject



34
35
36
37
38
39
40
# File 'lib/gemstat/dependency.rb', line 34

def gem_version
  if @name.index(':')
    @name.match(/(.*):(.*)/)[2]
  else
    @name
  end
end