Class: Flo::Runner

Inherits:
Object
  • Object
show all
Includes:
Cleanroom
Defined in:
lib/flo/runner.rb

Overview

This is the main class for instantiating and performing Flo commands. If you are wanting to interact with Flo via a ruby script, this is the class you want. Utilizing Flo through the command line interface will invoke this class after all of the argument parsing is complete.

Examples:

runner = Runner.new
runner.load_config_file('path/to/config/file')
runner.execute([:issue, :submit], id: '1234', submitter: 'John Doe')

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Runner

Creates a new runner. This object is generally useless until you load some configuration into it, typically using #load_config_file



36
37
38
39
40
# File 'lib/flo/runner.rb', line 36

def initialize(opts={})
  @config = opts[:config] || Flo::Config.new
  @command_class = opts[:command_class] || Flo::Command
  @commands = opts[:command_collection] || Flo::CommandCollection.new
end

Instance Attribute Details

#commandsCommandCollection (readonly)

List of commands currently defined

Returns:



28
29
30
# File 'lib/flo/runner.rb', line 28

def commands
  @commands
end

Instance Method Details

#config {|Config| ... } ⇒ Config

DSL method: Returns the instance of Config associated with this runner. Exposes the Config instance if a block is used

Yields:

Returns:



69
70
71
72
# File 'lib/flo/runner.rb', line 69

def config
  yield(@config) if block_given?
  @config
end

#execute(command_namespace, args = {}) ⇒ Object

Executes the command specified, with the arguments specified

Parameters:

  • command_namespace (Array<Symbol>)

    An array containing the name of the command as a symbol, including the namespace. For example, the command “issue submit” would become [:issue, :submit]

  • args={}
    Hash

    Options that will get passed to the command



57
58
59
# File 'lib/flo/runner.rb', line 57

def execute(command_namespace, args={})
  commands[command_namespace].call(args)
end

#load_config_file(config_file) ⇒ Object

Open and parse a file containing flo configuration. This file is evaluated within a cleanroom. See the cleanroom gem for more information.

Parameters:

  • config_file (String)

    path to the flo configuration file



47
48
49
# File 'lib/flo/runner.rb', line 47

def load_config_file(config_file)
  evaluate_file(config_file)
end

#register_command(command_namespace) {|args*| ... } ⇒ Object

DSL method: Creates and defines a Command, adding it to the command collection. Definition for the command should happen inside of the required block. See Command for methods available within the block.

Parameters:

  • command_namespace (Array<Symbol>)

    Array of symbols representing the command including the namespace

Yields:

  • (args*)

    The block containing the definition for the command. Arguments passed into #execute are available within the block



84
85
86
# File 'lib/flo/runner.rb', line 84

def register_command(command_namespace, &blk)
  commands[command_namespace] = command_class.new(providers: config.providers, &blk)
end