Class: Anticuado::Ruby::Bundler

Inherits:
Base
  • Object
show all
Defined in:
lib/anticuado/ruby/bundler.rb

Class Method Summary collapse

Class Method Details

.format(outdated) ⇒ Array

Returns Array include outdated data. If target project have no outdated data, then return blank array such as ‘[]`.

Parameters:

  • outdated (String)

    The result of command ‘bundle outdated`

Returns:

  • (Array)

    Array include outdated data. If target project have no outdated data, then return blank array such as ‘[]`



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/anticuado/ruby/bundler.rb', line 23

def self.format(outdated)
  array = outdated.split(/\R/).map(&:strip)
  index = array.find_index("Outdated gems included in the bundle:")

  return [] if index.nil?

  array[index + 1..array.size].map { |library|
    versions = library.split(/\s/) # e.g. ["*", "jwt", "(newest", "1.5.6,", "installed", "1.5.5)"]
    if versions[0] == "*"
      {
          library_name: versions[1],
          current_version: versions[5].delete(")"),
          available_version: versions[3].delete(","),
          latest_version: versions[3].delete(",")
      }
    end
  }.compact
end

.outdated(project = nil) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/anticuado/ruby/bundler.rb', line 4

def self.outdated(project = nil)
  return puts "have no bundle command" if `which bundle`.empty?

  if project
    current_dir = Anticuado.current_dir
    Dir.chdir Anticuado.project_dir(project)
    `bundle install`
    outdated_str = `bundle outdated`
    Dir.chdir current_dir
  else
    `bundle install`
    outdated_str = `bundle outdated`
  end
  outdated_str
end