Class: PDK::Module::Update

Inherits:
Convert
  • Object
show all
Defined in:
lib/pdk/module/update.rb

Constant Summary collapse

GIT_DESCRIBE_PATTERN =
%r{\A(?<base>.+?)-(?<additional_commits>\d+)-g(?<sha>.+)\Z}

Instance Attribute Summary

Attributes inherited from Convert

#options

Instance Method Summary collapse

Methods inherited from Convert

#force?, #full_report, #generate_banner, #initialize, invoke, #needs_bundle_update?, #noop?, #print_result, #print_summary, #stage_changes!, #summary, #update_manager, #update_metadata

Constructor Details

This class inherits a constructor from PDK::Module::Convert

Instance Method Details

#current_versionObject



57
58
59
# File 'lib/pdk/module/update.rb', line 57

def current_version
  @current_version ||= describe_ref_to_s(current_template_version)
end

#module_metadataObject



47
48
49
50
51
# File 'lib/pdk/module/update.rb', line 47

def 
  @module_metadata ||= PDK::Module::Metadata.from_file('metadata.json')
rescue ArgumentError => e
  raise PDK::CLI::ExitWithError, e.message
end

#new_versionObject



61
62
63
# File 'lib/pdk/module/update.rb', line 61

def new_version
  @new_version ||= fetch_remote_version(new_template_version)
end

#runObject



8
9
10
11
12
13
14
15
16
17
18
19
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
# File 'lib/pdk/module/update.rb', line 8

def run
  stage_changes!

  if current_version == new_version
    PDK.logger.debug _('This module is already up to date with version %{version} of the template.') % {
      version: new_version,
    }
  end

  unless update_manager.changes?
    PDK::Report.default_target.puts(_('No changes required.'))
    return
  end

  PDK.logger.info(update_message)

  print_summary
  full_report('update_report.txt') unless update_manager.changes[:modified].empty?

  return if noop?

  unless force?
    message = _('Do you want to continue and make these changes to your module?')
    return unless PDK::CLI::Util.prompt_for_yes(message)
  end

  # Remove these files straight away as these changes are not something that the user needs to review.
  if needs_bundle_update?
    update_manager.unlink_file('Gemfile.lock')
    update_manager.unlink_file(File.join('.bundle', 'config'))
  end

  update_manager.sync_changes!

  PDK::Util::Bundler.ensure_bundle! if needs_bundle_update?

  print_result 'Update completed'
end

#template_urlObject



53
54
55
# File 'lib/pdk/module/update.rb', line 53

def template_url
  @template_url ||= .data['template-url']
end