Module: Rbcli::Engine
- Defined in:
- lib/rbcli/components/core/engine.rb
Overview
Rbcli – A framework for developing command line applications in Ruby #
Copyright (C) 2024 Andrew Khoury <[email protected]> #
Class Method Summary collapse
Class Method Details
.register_operation(operation, name: nil, priority: nil) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/rbcli/components/core/engine.rb', line 9 def self.register_operation operation, name: nil, priority: nil if @operations.select { |op| op[:priority] == priority }.count != 0 raise Rbcli::Error.new "The Rbcli engine can not have two operations defined with the same priority: #{name}, #{@operations.select { |op| op[:priority] == priority }.join(", ")}" end @operations << { operation: operation, name: name, priority: priority } end |
.run! ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/rbcli/components/core/engine.rb', line 16 def self.run! Rbcli.log.debug "The engine has been started", "ENGN" @operations.sort_by { |op| op[:priority] }.each do |op| Rbcli.log.debug "Running operation #{op[:priority]} -- #{op[:name]}", "ENGN" op[:operation].call end Rbcli.log.debug "The engine has been stopped", "ENGN" end |