class CuffSert::RendererPresenter

Public Class Methods

new(events, renderer) click to toggle source
Calls superclass method CuffSert::BasePresenter::new
# File lib/cuffsert/presenters.rb, line 51
def initialize(events, renderer)
  @resources = []
  @index = {}
  @renderer = renderer
  super(events)
end

Public Instance Methods

on_complete() click to toggle source
# File lib/cuffsert/presenters.rb, line 92
def on_complete
end
on_error(err) click to toggle source
Calls superclass method CuffSert::BasePresenter#on_error
# File lib/cuffsert/presenters.rb, line 82
def on_error(err)
  case err
  when CuffSertError
    @renderer.abort(err)
  else
    super(err)
  end
  exit(1)
end
on_event(event) click to toggle source
# File lib/cuffsert/presenters.rb, line 58
def on_event(event)
  case event
  when ::CuffSert::Templates
    @renderer.templates(*event.message)
  when Aws::CloudFormation::Types::StackEvent
    on_stack_event(event)
  when ::CuffSert::ChangeSet
    on_change_set(event.message)
  # when [:recreate, Aws::CloudFormation::Types::Stack]
  when Array
    on_stack(*event)
  when ::CuffSert::Report
    @renderer.report(event)
  when ::CuffSert::Abort
    @renderer.abort(event)
  when ::CuffSert::Done
    @renderer.done(event)
  when ::CuffSert::Message
    puts event.message
  else
    puts event
  end
end

Private Instance Methods

clear_resources() click to toggle source
# File lib/cuffsert/presenters.rb, line 140
def clear_resources
  @resources.clear
  @index.clear
end
is_completed_stack_event(event) click to toggle source
# File lib/cuffsert/presenters.rb, line 135
def is_completed_stack_event(event)
  event[:resource_type] == 'AWS::CloudFormation::Stack' &&
    FINAL_STATES.include?(event[:resource_status])
end
lookup_stack_resource(event) click to toggle source
# File lib/cuffsert/presenters.rb, line 114
def lookup_stack_resource(event)
  rid = event[:logical_resource_id]
  unless (pos = @index[rid])
    pos = @index[rid] = @resources.size
    @resources << make_resource(event)
  end
  @resources[pos]
end
make_resource(event) click to toggle source
# File lib/cuffsert/presenters.rb, line 123
def make_resource(event)
  event.to_h
    .reject { |k, _| k == :timestamp }
    .merge!(:states => [])
end
on_change_set(change_set) click to toggle source
# File lib/cuffsert/presenters.rb, line 97
def on_change_set(change_set)
  @renderer.change_set(change_set.to_h)
end
on_stack(event, stack) click to toggle source
# File lib/cuffsert/presenters.rb, line 110
def on_stack(event, stack)
  @renderer.stack(event, stack)
end
on_stack_event(event) click to toggle source
# File lib/cuffsert/presenters.rb, line 101
def on_stack_event(event)
  resource = lookup_stack_resource(event)
  update_resource_states(resource, event)
  @renderer.event(event, resource)
  @renderer.clear
  @resources.each { |resource| @renderer.resource(resource) }
  clear_resources if is_completed_stack_event(event)
end
update_resource_states(resource, event) click to toggle source
# File lib/cuffsert/presenters.rb, line 129
def update_resource_states(resource, event)
  resource[:states] = resource[:states]
    .reject { |state| state == :progress }
    .take(1) << CuffSert.state_category(event[:resource_status])
end