Class: Bundler::AutoUpdate::GemUpdater

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gem, gemfile, test_command) ⇒ GemUpdater

Returns a new instance of GemUpdater.



47
48
49
# File 'lib/bundler_auto_update.rb', line 47

def initialize(gem, gemfile, test_command)
  @gem, @gemfile, @test_command = gem, gemfile, test_command
end

Instance Attribute Details

#gemObject (readonly)

Returns the value of attribute gem.



45
46
47
# File 'lib/bundler_auto_update.rb', line 45

def gem
  @gem
end

#gemfileObject (readonly)

Returns the value of attribute gemfile.



45
46
47
# File 'lib/bundler_auto_update.rb', line 45

def gemfile
  @gemfile
end

#test_commandObject (readonly)

Returns the value of attribute test_command.



45
46
47
# File 'lib/bundler_auto_update.rb', line 45

def test_command
  @test_command
end

Instance Method Details

#auto_updateObject

Attempt to update to patch, then to minor then to major versions.



52
53
54
55
56
57
58
59
# File 'lib/bundler_auto_update.rb', line 52

def auto_update
  if updatable?
    Logger.log "Updating #{gem.name}"
    update(:patch) and update(:minor) and update(:major)
  else
    Logger.log "#{gem.name} is not auto-updatable, passing it."
  end
end

#updatable?Boolean

Returns true when the gem has a fixed version.

Returns:

  • (Boolean)

    true when the gem has a fixed version.



88
89
90
# File 'lib/bundler_auto_update.rb', line 88

def updatable?
  !!(gem.version =~ /^~?>? ?\d+\.\d+(\.\d+)?$/)
end

#update(version_type) ⇒ Boolean

Update current gem to latest :version_type:, run test suite and commit new Gemfile if successful.

Parameters:

  • version_type

    :patch or :minor or :major

Returns:

  • (Boolean)

    true on success or when already at latest version



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/bundler_auto_update.rb', line 66

def update(version_type)
  new_version = gem.last_version(version_type)

  if new_version == gem.version
    Logger.log_indent "Current gem already at latest #{version_type} version. Passing this update."

    return true
  end

  Logger.log_indent "Updating to #{version_type} version #{new_version}"

  gem.version = new_version

  if update_gemfile and run_test_suite and commit_new_version
    true
  else
    revert_to_previous_version
    false
  end
end