Class: AppUpdate
Overview
Main class of the app update tool.
Constant Summary collapse
- APP_CONFIG =
'.applications'
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#extra_args ⇒ Object
readonly
Returns the value of attribute extra_args.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#runner ⇒ Object
readonly
Returns the value of attribute runner.
Instance Method Summary collapse
-
#app(name) ⇒ Object
—————————————————————– internal.
- #applications_path ⇒ Object
-
#initialize(args) ⇒ AppUpdate
constructor
A new instance of AppUpdate.
- #panic(message) ⇒ Object
- #parse_options(args) ⇒ Object
- #run ⇒ Object
- #run_for_app(name) ⇒ Object
Methods included from Delegation
Constructor Details
#initialize(args) ⇒ AppUpdate
Returns a new instance of AppUpdate.
23 24 25 26 27 28 29 30 |
# File 'lib/app_update.rb', line 23 def initialize args @opts, extra_args = (args) @config = Configuration.current @runner = config.runner @logger = config.logger @extra_args = extra_args end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
20 21 22 |
# File 'lib/app_update.rb', line 20 def config @config end |
#extra_args ⇒ Object (readonly)
Returns the value of attribute extra_args.
21 22 23 |
# File 'lib/app_update.rb', line 21 def extra_args @extra_args end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
19 20 21 |
# File 'lib/app_update.rb', line 19 def logger @logger end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
17 18 19 |
# File 'lib/app_update.rb', line 17 def opts @opts end |
#runner ⇒ Object (readonly)
Returns the value of attribute runner.
18 19 20 |
# File 'lib/app_update.rb', line 18 def runner @runner end |
Instance Method Details
#app(name) ⇒ Object
—————————————————————– internal
92 93 94 |
# File 'lib/app_update.rb', line 92 def app(name) Application.new(name, config, opts) end |
#applications_path ⇒ Object
95 96 97 |
# File 'lib/app_update.rb', line 95 def applications_path config.app_base_path(APP_CONFIG) end |
#panic(message) ⇒ Object
99 100 101 102 103 |
# File 'lib/app_update.rb', line 99 def panic puts fatal exit 1 end |
#parse_options(args) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/app_update.rb', line 32 def args opts = { force: false } args = OptionParser.new do |parser| parser. = "Usage: mau [options] APPLICATION_NAME" parser.separator "" parser.separator "Specific options:" parser.on('-r', '--ref REF', 'Target git reference to update to') do |v| opts[:ref] = v end.on('-f', '--force', 'Forces update') do |v| opts[:force] = true end.on("-v", "--[no-]verbose", "Run verbosely") do |v| opts[:verbose] = v end.on_tail("-h", "--help", "Show this message") do puts parser exit end end.parse(args) return opts, args end |
#run ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/app_update.rb', line 57 def run # If extra_args is empty, we need to look at all apps that were deployed # here before. app_names = extra_args if app_names.empty? begin app_names = IO.readlines(applications_path).map(&:chomp) rescue Errno::ENOENT warn "Could not read application names from #{APP_CONFIG}." end end # Iterate over all applications, updating every one of them. successful_apps = app_names.select do |name| run_for_app name end # Keep track of what applications are deployed here. File.write applications_path, successful_apps.join("\n") end |
#run_for_app(name) ⇒ Object
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/app_update.rb', line 79 def run_for_app name info "Attempting update of #{name}." app(name).update info "Done. (updating #{name})" return true rescue error "Failed to update #{name}, see exception for details." raise end |