Class: SafeUpdate::OutdatedGem

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

Constant Summary collapse

STATUS_PENDING =
'pending'
STATUS_UPDATING =
'updating'
STATUS_TESTING =
'testing'
STATUS_UPDATED =
'updated'
STATUS_UNCHANGED =
'unchanged'
STATUS_TESTS_FAIL =
'tests_fail'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ OutdatedGem

Returns a new instance of OutdatedGem.



11
12
13
14
15
16
17
18
# File 'lib/safe_update/outdated_gem.rb', line 11

def initialize(opts = {})
  @gem_name  = opts[:gem_name]
  @newest    = opts[:newest]
  @installed = opts[:installed]
  @requested = opts[:requested]
  @git_repo  = opts[:git_repo] || GitRepo.new
  @current_status = STATUS_PENDING
end

Instance Attribute Details

#current_statusObject (readonly)

Returns the value of attribute current_status.



10
11
12
# File 'lib/safe_update/outdated_gem.rb', line 10

def current_status
  @current_status
end

#gem_nameObject (readonly)

Returns the value of attribute gem_name.



10
11
12
# File 'lib/safe_update/outdated_gem.rb', line 10

def gem_name
  @gem_name
end

#installedObject (readonly)

Returns the value of attribute installed.



10
11
12
# File 'lib/safe_update/outdated_gem.rb', line 10

def installed
  @installed
end

#newestObject (readonly)

Returns the value of attribute newest.



10
11
12
# File 'lib/safe_update/outdated_gem.rb', line 10

def newest
  @newest
end

#requestedObject (readonly)

Returns the value of attribute requested.



10
11
12
# File 'lib/safe_update/outdated_gem.rb', line 10

def requested
  @requested
end

Instance Method Details

#attempt_update(test_command = nil) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/safe_update/outdated_gem.rb', line 20

def attempt_update(test_command = nil)
  @current_status = STATUS_UPDATING
  `bundle update #{@gem_name}`

  # sometimes the gem may be outdated, but it's matching the
  # version required by the gemfile, so bundle update does nothing
  # in which case, don't waste time on tests etc.
  if false
    return
  end

  if test_command
    @current_status = STATUS_TESTING
    result = system(test_command)
    if result != true
      @current_status = STATUS_TESTS_FAIL
      @git_repo.discard_local_changes
      return
    end
  end

  if @git_repo.gemfile_lock_has_changes?
    @git_repo.commit_gemfile_lock(commit_message)
    @current_status = STATUS_UPDATED
  else
    @current_status = STATUS_UNCHANGED
  end
end

#being_operated_on_now?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/safe_update/outdated_gem.rb', line 49

def being_operated_on_now?
  [STATUS_UPDATING, STATUS_TESTING].include?(@current_status)
end