Class: Iota::CLI::Rollback
- Inherits:
-
Object
- Object
- Iota::CLI::Rollback
- Defined in:
- lib/iota/cli/rollback.rb
Instance Attribute Summary collapse
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#thor ⇒ Object
readonly
Returns the value of attribute thor.
Instance Method Summary collapse
-
#initialize(options, environment, thor) ⇒ Rollback
constructor
A new instance of Rollback.
- #run ⇒ Object
Constructor Details
#initialize(options, environment, thor) ⇒ Rollback
Returns a new instance of Rollback.
7 8 9 10 11 12 |
# File 'lib/iota/cli/rollback.rb', line 7 def initialize(, environment, thor) = @environment = environment @thor = thor @path = [:path] || '.' end |
Instance Attribute Details
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
5 6 7 |
# File 'lib/iota/cli/rollback.rb', line 5 def environment @environment end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/iota/cli/rollback.rb', line 5 def end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/iota/cli/rollback.rb', line 5 def path @path end |
#thor ⇒ Object (readonly)
Returns the value of attribute thor.
5 6 7 |
# File 'lib/iota/cli/rollback.rb', line 5 def thor @thor end |
Instance Method Details
#run ⇒ Object
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/iota/cli/rollback.rb', line 14 def run unless File.exists?('./iota.conf') thor.say("Config file ('./iota.conf') is missing.", :red) return end thor.say("Loading configuration.", :yellow) config = YAML.load_file('./iota.conf') thor.say("Done.", :blue) unless Iota::Function::ENVIRONMENT_ALIAS_NAME_MAP.keys.include?(environment) thor.say("Invalid environment #{environment}. \ Please specify either 'production' or 'development'.", :red) return end # TODO: not found function_name = config['function_name'] function = Iota::Function.new(function_name, path) if function.exists? aliases = function.list_aliases current_version_alias_name = Iota::Function::ENVIRONMENT_ALIAS_NAME_MAP[environment] last_version_alias_name = current_version_alias_name + Iota::Function::LAST_VERSION_SUFFIX last_version_alias = aliases.select{|a| a.name == last_version_alias_name}.first current_version_alias = aliases.select{|a| a.name == current_version_alias_name}.first # last -> current, current -> last unless last_version_alias.nil? || current_version_alias.nil? if last_version_alias.function_version == current_version_alias.function_version thor.say("Can't rollback before deploy.", :yellow) return else thor.say("Updating alias", :yellow) function.update_alias(current_version_alias_name, last_version_alias.function_version) thor.say("Version is now at #{last_version_alias.function_version}.", :yellow) thor.say("Done.", :blue) end end else thor.say("Function #{function_name} doesn't seem to be exists.", :yellow) end end |