Module: Dry::CLI::Registry
- Defined in:
- lib/dry/cli/registry.rb
Overview
Registry mixin
Defined Under Namespace
Classes: Prefix
Class Method Summary collapse
- .extended(base) ⇒ Object private
Instance Method Summary collapse
-
#after(command_name, callback = nil, &blk) ⇒ Object
Register an after callback.
-
#before(command_name, callback = nil, &blk) ⇒ Object
Register a before callback.
- #get(arguments) ⇒ Object private
-
#register(name, command = nil, aliases: [], hidden: false, &block) ⇒ Object
Register a command.
Class Method Details
.extended(base) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
13 14 15 16 17 18 |
# File 'lib/dry/cli/registry.rb', line 13 def self.extended(base) base.class_eval do @_mutex = Mutex.new @commands = CommandRegistry.new end end |
Instance Method Details
#after(command_name, callback = nil, &blk) ⇒ Object
Register an after callback.
261 262 263 264 265 |
# File 'lib/dry/cli/registry.rb', line 261 def after(command_name, callback = nil, &blk) @_mutex.synchronize do command(command_name).after_callbacks.append(&_callback(callback, blk)) end end |
#before(command_name, callback = nil, &blk) ⇒ Object
Register a before callback.
173 174 175 176 177 |
# File 'lib/dry/cli/registry.rb', line 173 def before(command_name, callback = nil, &blk) @_mutex.synchronize do command(command_name).before_callbacks.append(&_callback(callback, blk)) end end |
#get(arguments) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
269 270 271 |
# File 'lib/dry/cli/registry.rb', line 269 def get(arguments) @commands.get(arguments) end |
#register(name, command = nil, aliases: [], hidden: false, &block) ⇒ Object
Register a command
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/dry/cli/registry.rb', line 78 def register(name, command = nil, aliases: [], hidden: false, &block) @commands.set(name, command, aliases, hidden) if block_given? prefix = Prefix.new(@commands, name, aliases, hidden) if block.arity.zero? prefix.instance_eval(&block) else yield(prefix) end end end |