Class: Shaf::Command::Upgrade
- Inherits:
-
Base
- Object
- Base
- Shaf::Command::Upgrade
show all
- Defined in:
- lib/shaf/command/upgrade.rb
Defined Under Namespace
Classes: UnknownShafVersionError, UpgradeFailedError
Constant Summary
Constants included
from Utils
Utils::SHAF_VERSION_FILE
Instance Attribute Summary
Attributes inherited from Base
#args, #options
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
exit_with_error, identified_by, identifier, inherited, #initialize, usage
Methods included from Utils
#bootstrap, deep_symbolize_keys, deep_transform_keys, deep_transform_values, environment, gem_root, iana_link_relations, #in_project_root, #in_project_root?, #is_project_root?, model_name, pluralize, #project_root, #project_root!, rackify_header, read_config, #read_shaf_file, #read_shaf_file!, #read_shaf_upgrade_failure_version, #read_shaf_version, singularize, symbol_or_quoted_string, symbol_string, #write_shaf_file, #write_shaf_file!, #write_shaf_upgrade_failure, #write_shaf_version
Class Method Details
.options(parser, options) ⇒ Object
19
20
21
22
23
|
# File 'lib/shaf/command/upgrade.rb', line 19
def self.options(parser, options)
parser.on('--skip VERSION', String, 'Skip version') do |v|
options[:skip_version] = Shaf::Upgrade::Version.new(v)
end
end
|
Instance Method Details
#apply!(package) ⇒ Object
55
56
57
58
59
60
61
|
# File 'lib/shaf/command/upgrade.rb', line 55
def apply!(package)
package.load.apply or raise UpgradeFailedError.new(package.version)
rescue Errno::ENOENT
raise UpgradeFailedError,
"Failed to execute system command 'patch'. Make sure that 'patch' installed!" \
" (E.g. `sudo apt install patch` for Ubuntu)"
end
|
#call ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/shaf/command/upgrade.rb', line 25
def call
in_project_root do
upgrade_packages.each do |package|
next if skip? package
if package.version == current_failed_version
print_previous_failed_warning package.version
else
apply!(package)
end
write_shaf_version(package.version)
end
puts "\nProject is up-to-date! Shaf version: #{current_version}"
end
rescue UpgradeFailedError => e
write_shaf_upgrade_failure e.version
puts <<~ERR
Failed to upgrade project to version #{e.version}
Please try resolve these issues manually and try again.
For more info see:
https://github.com/sammyhenningsson/shaf/blob/master/doc/UPGRADE.md
ERR
raise
end
|
#current_failed_version ⇒ Object
86
87
88
89
|
# File 'lib/shaf/command/upgrade.rb', line 86
def current_failed_version
version = read_shaf_upgrade_failure_version
Shaf::Upgrade::Version.new(version) if version
end
|
#current_version ⇒ Object
#print_previous_failed_warning(version) ⇒ Object
91
92
93
94
95
96
97
|
# File 'lib/shaf/command/upgrade.rb', line 91
def print_previous_failed_warning(version)
puts <<~MSG
Previous upgrade to version #{version} failed!
Assuming all files has been fixed manually and continuing with
upgrade.
MSG
end
|
#skip?(package) ⇒ Boolean
63
64
65
66
|
# File 'lib/shaf/command/upgrade.rb', line 63
def skip?(package)
return false unless options[:skip_version]
package.version == options[:skip_version]
end
|
#target_version ⇒ Object
82
83
84
|
# File 'lib/shaf/command/upgrade.rb', line 82
def target_version
Shaf::Upgrade::Version.new(ENV.fetch('UPGRADE_TARGET', '99.9.9'))
end
|
#upgrade_packages ⇒ Object
68
69
70
71
72
73
74
75
|
# File 'lib/shaf/command/upgrade.rb', line 68
def upgrade_packages
current = current_version
target = target_version
Shaf::Upgrade::Package.all.select do |package|
current < package.version && package.version <= target
end
end
|