Sha256: 658235ffa74725bdb6edf06b5306fdc950310d0cd6e229bed630956e68554ebb

Contents?: true

Size: 924 Bytes

Versions: 1

Compression:

Stored size: 924 Bytes

Contents

require 'gemfile_entry/version'

#
module GemfileEntry
  def self.latest(gem1)
    # rubocop:disable Metrics/LineLength
    version_json = `curl -s https://rubygems.org/api/v1/versions/#{gem1}/latest.json`
    # rubocop:enable Metrics/LineLength
    version = version_json.delete('"').delete('{\version\:\)').delete('\}')
    gemfile_line = "gem '#{gem1}', '#{version}'"
    gemfile_line
  end

  def self.active(gem1)
    # NOTE: The delete and gsub commands do not work for removing
    # substrings containing dashes.
    # As a result, - is converted to +.
    path = `bundle show #{gem1}`
    path_last = path.split('/').last
    path_last_u = path_last.tr('-', '+')
    gem1_u = gem1.tr('-', '+')
    version = path_last_u.gsub(gem1_u, '').delete('+').delete("\n")
    gemfile_line = "gem '#{gem1}', '#{version}'"
    gemfile_line
  end
end
# Your new gem is a module by default.  You may wish to use a class instead.

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gemfile_entry-0.0.1 lib/gemfile_entry.rb