Class: Depec::Target::Ruby

Inherits:
Base
  • Object
show all
Defined in:
lib/depec/target/ruby.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Depec::Target::Base

Instance Method Details

#bundler_versionString

Returns:

  • (String)


43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/depec/target/ruby.rb', line 43

def bundler_version
  return unless File.exists?(gemfile_lock)

  version_line = false
  File.open(gemfile_lock) do |f|
    f.each_line do |line|
      return line.strip if version_line
      version_line = true if line.include?('BUNDLED WITH')
    end
  end

  return nil
end

#gem_version(gem) ⇒ String

Parameters:

  • gem (String)

Returns:

  • (String)


61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/depec/target/ruby.rb', line 61

def gem_version(gem)
  return unless File.exists?(gemfile_lock)
  
  File.open(gemfile_lock) do |f|
    f.each_line do |line|
      if line.match?(/ #{gem} \([0-9\.]+\)/)
        return line.match(/#{gem} \((?<version>.*)\)/)[:version]
      end
    end
  end
  
  return nil
end

#gemfileString

Returns:

  • (String)


14
15
16
# File 'lib/depec/target/ruby.rb', line 14

def gemfile
  File.join(@dir, 'Gemfile')
end

#gemfile_lockString

Returns:

  • (String)


21
22
23
# File 'lib/depec/target/ruby.rb', line 21

def gemfile_lock
  File.join(@dir, 'Gemfile.lock')
end

#ruby_version_fileString

Returns:

  • (String)


7
8
9
# File 'lib/depec/target/ruby.rb', line 7

def ruby_version_file
  File.join(@dir, '.ruby-version')
end

#used?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/depec/target/ruby.rb', line 28

def used?
  File.exists?(gemfile)
end

#versionString

Returns:

  • (String)


35
36
37
38
# File 'lib/depec/target/ruby.rb', line 35

def version
  return unless File.exists?(ruby_version_file)
  File.open(ruby_version_file) { |f| return f.gets.strip }
end