Method: Sfn::CommandModule::Callbacks#callbacks_for

Defined in:
lib/sfn/command_module/callbacks.rb

#callbacks_for(type) ⇒ Array<Method>

Fetch valid callbacks for given type

Parameters:

  • type (Symbol, String)

    name of callback type

  • responder (Array<String, Symbol>)

    matching response methods

Returns:

  • (Array<Method>)


57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/sfn/command_module/callbacks.rb', line 57

def callbacks_for(type)
  ([config.fetch(:callbacks, type, [])].flatten.compact + [config.fetch(:callbacks, :default, [])].flatten.compact).map do |c_name|
    instance = memoize(c_name) do
      begin
        klass = Sfn::Callback.const_get(Bogo::Utility.camel(c_name.to_s))
        klass.new(ui, config, arguments, provider)
      rescue NameError => e
        ui.debug "Callback type lookup error: #{e.class} - #{e}"
        raise NameError.new("Unknown #{type} callback requested: #{c_name} (not found)")
      end
    end
    if instance.respond_to?(type)
      [c_name, instance.method(type), instance.respond_to?(:quiet) ? instance.quiet : false]
    end
  end.compact
end