Class: Bundler::AutoUpdate::Dependency

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, version = nil, options = nil) ⇒ Dependency

Returns a new instance of Dependency.



236
237
238
239
240
241
# File 'lib/bundler_auto_update.rb', line 236

def initialize(name, version = nil, options = nil)
  @name, @version, @options = name, version, options

  # TODO: enhance support of > and ~> in versions
  @major, @minor, @patch = version[/\d+\.\d+(\.\d+)?/].split('.') if version
end

Instance Attribute Details

#majorObject (readonly)

Returns the value of attribute major.



233
234
235
# File 'lib/bundler_auto_update.rb', line 233

def major
  @major
end

#minorObject (readonly)

Returns the value of attribute minor.



233
234
235
# File 'lib/bundler_auto_update.rb', line 233

def minor
  @minor
end

#nameObject (readonly)

Returns the value of attribute name.



233
234
235
# File 'lib/bundler_auto_update.rb', line 233

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



233
234
235
# File 'lib/bundler_auto_update.rb', line 233

def options
  @options
end

#patchObject (readonly)

Returns the value of attribute patch.



233
234
235
# File 'lib/bundler_auto_update.rb', line 233

def patch
  @patch
end

#versionObject

Returns the value of attribute version.



234
235
236
# File 'lib/bundler_auto_update.rb', line 234

def version
  @version
end

Instance Method Details

#available_versionsArray

Return an ordered array of all available versions.

Returns:

  • (Array)

    of [String].



266
267
268
269
# File 'lib/bundler_auto_update.rb', line 266

def available_versions
  the_gem_line = gem_remote_list_output.scan(/^#{name}\s.*$/).first
  the_gem_line.scan /\d+\.\d+\.\d+/
end

#last_version(version_type) ⇒ String

Return last version scoped at :version_type:.

Example: last_version(:patch), returns the last patch version for the current major/minor version

Returns:

  • (String)

    last version. Ex: ‘1.2.3’



250
251
252
253
254
255
256
257
258
259
260
261
# File 'lib/bundler_auto_update.rb', line 250

def last_version(version_type)
  case version_type
  when :patch
    available_versions.select { |v| v =~ /^#{major}\.#{minor}\D/ }.first
  when :minor
    available_versions.select { |v| v =~ /^#{major}\./ }.first
  when :major
    available_versions.first
  else
    raise "Invalid version_type: #{version_type}"
  end
end