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 <akhoury@live.com>                        #

Class Method Summary collapse

Class Method Details

.register_operation(operation, name: nil, priority: nil) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/rbcli/components/core/engine.rb', line 9

def self.register_operation operation, name: nil, priority: nil
  conflicts = @operations.select { |op| op[:priority] == priority }
  unless conflicts.empty?
    raise Rbcli::Error, "The Rbcli engine can not have two operations defined with the same priority: #{name}, #{conflicts.join(", ")}"
  end
  @operations << { operation: operation, name: name, priority: priority }
end

.run!Object



17
18
19
20
21
22
23
24
# File 'lib/rbcli/components/core/engine.rb', line 17

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