Sha256: 4740d55590c0458c0706f44f893a2795844bb4c1e5bc7f3d0866cc00aae4f7f0

Contents?: true

Size: 1.19 KB

Versions: 2

Compression:

Stored size: 1.19 KB

Contents

require 'sfn'

module Sfn
  # Interface for injecting custom functionality
  class Callback

    autoload :StackPolicy, 'sfn/callback/stack_policy'

    # @return [Bogo::Ui]
    attr_reader :ui
    # @return [Smash]
    attr_reader :config
    # @return [Array<String>] CLI arguments
    attr_reader :arguments
    # @return [Miasma::Models::Orchestration] remote API
    attr_reader :api

    # Create a new callback instance
    #
    # @param [Bogo::Ui]
    # @param [Smash] configuration hash
    # @param [Array<String>] arguments from the CLI
    # @param [Provider] API connection
    #
    # @return [self]
    def initialize(ui, config, arguments, api)
      @ui = ui
      @config = config
      @arguments = arguments
      @api = api
    end

    # Wrap action within status text
    #
    # @param msg [String] action text
    # @yieldblock action to perform
    # @return [Object] result of yield
    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

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sfn-1.1.6 lib/sfn/callback.rb
sfn-1.1.4 lib/sfn/callback.rb