Class: Sfn::Callback

Inherits:
Object
  • Object
show all
Defined in:
lib/sfn/callback.rb,
lib/sfn/callback/stack_policy.rb

Overview

Interface for injecting custom functionality

Direct Known Subclasses

StackPolicy

Defined Under Namespace

Classes: StackPolicy

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ui, config, arguments, api) ⇒ self

Create a new callback instance

Parameters:

  • (Bogo::Ui)
  • configuration (Smash)

    hash

  • arguments (Array<String>)

    from the CLI

  • API (Provider)

    connection



22
23
24
25
26
27
# File 'lib/sfn/callback.rb', line 22

def initialize(ui, config, arguments, api)
  @ui = ui
  @config = config
  @arguments = arguments
  @api = api
end

Instance Attribute Details

#configSmash (readonly)

Returns:

  • (Smash)


12
13
14
# File 'lib/sfn/callback.rb', line 12

def config
  @config
end

#uiBogo::Ui (readonly)

Returns:

  • (Bogo::Ui)


10
11
12
# File 'lib/sfn/callback.rb', line 10

def ui
  @ui
end

Instance Method Details

#run_action(msg) ⇒ Object

Wrap action within status text

Parameters:

  • msg (String)

    action text

Returns:

  • (Object)

    result of yield



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/sfn/callback.rb', line 34

def run_action(msg)
  ui.info("#{msg}... ", :nonewline)
  begin
    result = yield
    ui.puts ui.color('complete!', :green, :bold)
    result
  rescue => e
    ui.puts ui.color('error!', :red, :bold)
    ui.error "Reason - #{e}"
    raise
  end
end