Class: Opsicle::Update
- Inherits:
-
Object
- Object
- Opsicle::Update
- Defined in:
- lib/opsicle/commands/update.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #describe ⇒ Object
- #execute(values, options) ⇒ Object
- #format_diff(diff) ⇒ Object
-
#initialize(environment, type) ⇒ Update
constructor
A new instance of Update.
- #print(before, after) ⇒ Object
- #update(values) ⇒ Object
Constructor Details
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
6 7 8 |
# File 'lib/opsicle/commands/update.rb', line 6 def client @client end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
6 7 8 |
# File 'lib/opsicle/commands/update.rb', line 6 def type @type end |
Instance Method Details
#describe ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/opsicle/commands/update.rb', line 20 def describe api_method = "describe_#{@type}s" api_opts = { :"#{@type}_ids" => [client.config.opsworks_config[:"#{@type}_id"]] } client.api_call(api_method, api_opts)[:"#{@type}s"][0] end |
#execute(values, options) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/opsicle/commands/update.rb', line 13 def execute(values, ) before = describe update(values) after = describe print(before, after) end |
#format_diff(diff) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/opsicle/commands/update.rb', line 40 def format_diff(diff) diff.map { |change| case change[0] when '-' change.insert(3, nil) change.map! { |i| Output.format(i, :removal) } when '+' change.insert(2, nil) change.map! { |i| Output.format(i, :addition) } when '~' change.map! { |i| Output.format(i, :modification) } end change } end |
#print(before, after) ⇒ Object
34 35 36 37 38 |
# File 'lib/opsicle/commands/update.rb', line 34 def print(before, after) diff = HashDiff.diff(before, after) Output.say("Changes: #{diff.size}") Output.terminal.say(Terminal::Table.new headings: %w[Change Key Before After], rows: format_diff(diff)) if diff.size > 0 end |
#update(values) ⇒ Object
28 29 30 31 32 |
# File 'lib/opsicle/commands/update.rb', line 28 def update(values) api_method = "update_#{@type}" api_opts = values.merge(:"#{@type}_id" => client.config.opsworks_config[:"#{@type}_id"]) client.api_call(api_method, api_opts) end |