class Anticuado::Ruby::Bundler

Public Instance Methods

format(outdated = nil) click to toggle source

@param [String] outdated The result of command `bundle outdated`. If it's no argument, the method use the result of `outdated`. @return [Array] Array include outdated data.

If target project have no outdated data, then return blank array such as `[]`
# File lib/anticuado/ruby/bundler.rb, line 20
def format(outdated = nil)
  @outdated_libraries = outdated unless outdated.nil?

  array = @outdated_libraries.split(/\R/).map(&:strip)
  index = array.find_index("Outdated gems included in the bundle:")

  return [] if index.nil?

  @formatted_outdated_libraries = 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(option = '') click to toggle source
# File lib/anticuado/ruby/bundler.rb, line 4
def outdated(option = '')
  return puts "have no bundle command" if `which bundle`.empty?

  if @project_dir
    Dir.chdir(@project_dir) do
      @outdated_libraries = run_outdated option
    end
  else
    @outdated_libraries = run_outdated option
  end
  @outdated_libraries
end
update_lock(target_names = nil) click to toggle source
# File lib/anticuado/ruby/bundler.rb, line 41
def update_lock(target_names = nil)
  if @project_dir
    Dir.chdir(@project_dir) do
      do_update_lock target_names
    end
  else
    do_update_lock target_names
  end
end

Private Instance Methods

do_update_lock(target_names = nil) click to toggle source
# File lib/anticuado/ruby/bundler.rb, line 53
def do_update_lock(target_names = nil)
  if target_names.nil?
    `bundle update`
  else
    raise ArgumentError, "An argument should be Array like ['cocoapod']" unless target_names.is_a? Array
    `bundle update #{target_names.join(' ')}`          
  end
end
run_outdated(option) click to toggle source
# File lib/anticuado/ruby/bundler.rb, line 62
def run_outdated(option)
  `bundle install #{option}`
  `bundle outdated`
end