Class: Flo::Runner
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.
Instance Attribute Summary collapse
-
#commands ⇒ CommandCollection
readonly
List of commands currently defined.
Instance Method Summary collapse
-
#config {|Config| ... } ⇒ Config
DSL method: Returns the instance of Config associated with this runner.
-
#execute(command_namespace, args = []) ⇒ Object
Executes the command specified, with the arguments specified.
-
#initialize(opts = {}) ⇒ Runner
constructor
Creates a new runner.
-
#load_config_file(config_file) ⇒ Object
Open and parse a file containing flo configuration.
-
#load_default_config_files ⇒ Object
Open and parse any available config files, in the following order: * ENV # Allows the addition of custom files * ./.flo * ~/.flo See #load_config_file.
-
#register_command(command_namespace, opts = {}) {|args*| ... } ⇒ Object
DSL method: Creates and defines a Command, adding it to the command collection.
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
35 36 37 38 39 |
# File 'lib/flo/runner.rb', line 35 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
#commands ⇒ CommandCollection (readonly)
List of commands currently defined
27 28 29 |
# File 'lib/flo/runner.rb', line 27 def commands @commands end |
Instance Method Details
#config {|Config| ... } ⇒ Config
82 83 84 85 |
# File 'lib/flo/runner.rb', line 82 def config yield(@config) if block_given? @config end |
#execute(command_namespace, args = []) ⇒ Object
Executes the command specified, with the arguments specified
70 71 72 |
# File 'lib/flo/runner.rb', line 70 def execute(command_namespace, args=[]) commands[command_namespace][:command].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.
46 47 48 |
# File 'lib/flo/runner.rb', line 46 def load_config_file(config_file) evaluate_file(config_file) end |
#load_default_config_files ⇒ Object
Open and parse any available config files, in the following order:
-
ENV # Allows the addition of custom files
-
./.flo
-
~/.flo
56 57 58 59 60 61 62 |
# File 'lib/flo/runner.rb', line 56 def load_default_config_files [ENV['FLO_CONFIG_FILE'], File.join(Dir.pwd, '.flo'), File.join(Dir.home, '.flo')].compact.each do |file| if File.exist?(file) self.load_config_file(file) end end end |
#register_command(command_namespace, opts = {}) {|args*| ... } ⇒ Object
98 99 100 101 |
# File 'lib/flo/runner.rb', line 98 def register_command(command_namespace, opts={}, &blk) opts[:command] = command_class.new(providers: config.providers, &blk) commands[command_namespace] = opts end |