Class: Ukiryu::Shell::Registry
- Inherits:
-
Object
- Object
- Ukiryu::Shell::Registry
- Defined in:
- lib/ukiryu/shell.rb,
lib/ukiryu/shell/registry.rb
Overview
Registry for shell implementations
Provides a self-registration pattern for shells, making it easy to add new shells without modifying the core Shell module.
Usage
# Define a new shell class Ukiryu::Shell::Nushell < Base
PLATFORM = :unix
SHELL_NAME = :nushell
EXECUTABLE = 'nu'
end
# Auto-registers with the registry Shell::Registry.register(Nushell)
# Now you can use it Shell.class_for(:nushell) # => Nushell
Class Method Summary collapse
-
.all_shells ⇒ Array<Class<Base>>
Get all registered shells.
-
.clear ⇒ Object
private
Clear all registered shells (mainly for testing).
-
.default_for_platform(platform) ⇒ Class<Base>?
Get the default shell for a platform.
-
.for_name(name) ⇒ Class<Base>
Get a shell class by name.
-
.for_platform(platform) ⇒ Array<Class<Base>>
Get all shells for a platform.
-
.lookup(name) ⇒ Class?
private
Lookup a shell class by name.
-
.platform_names ⇒ Array<Symbol>
Get all registered platform names.
-
.register(shell_class) ⇒ true
Register a shell class.
-
.register_builtin_shells ⇒ Object
private
Register all built-in shells.
-
.registered?(name) ⇒ Boolean
Check if a shell is registered.
-
.registered_shells ⇒ Array<Symbol>
private
Get all registered shell names.
-
.reset ⇒ Object
Reset the registry (for testing).
-
.shell_names ⇒ Array<Symbol>
Get all registered shell names.
- .shells ⇒ Object private
Class Method Details
.all_shells ⇒ Array<Class<Base>>
Get all registered shells
106 107 108 |
# File 'lib/ukiryu/shell/registry.rb', line 106 def all_shells @registry.values.flatten.uniq end |
.clear ⇒ 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.
Clear all registered shells (mainly for testing)
95 96 97 |
# File 'lib/ukiryu/shell.rb', line 95 def clear @shells = nil end |
.default_for_platform(platform) ⇒ Class<Base>?
Get the default shell for a platform
72 73 74 75 |
# File 'lib/ukiryu/shell/registry.rb', line 72 def default_for_platform(platform) shells = for_platform(platform) shells.first end |
.for_name(name) ⇒ Class<Base>
Get a shell class by name
54 55 56 |
# File 'lib/ukiryu/shell/registry.rb', line 54 def for_name(name) @registry[name.to_sym] || raise(Errors::UnknownShellError, "Unknown shell: #{name}") end |
.for_platform(platform) ⇒ Array<Class<Base>>
Get all shells for a platform
63 64 65 |
# File 'lib/ukiryu/shell/registry.rb', line 63 def for_platform(platform) @registry[platform] || [] end |
.lookup(name) ⇒ Class?
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.
Lookup a shell class by name
83 84 85 |
# File 'lib/ukiryu/shell.rb', line 83 def lookup(name) shells[name.to_sym] end |
.platform_names ⇒ Array<Symbol>
Get all registered platform names
98 99 100 |
# File 'lib/ukiryu/shell/registry.rb', line 98 def platform_names @registry.keys.select { |k| %i[unix windows powershell].include?(k) } end |
.register(shell_class) ⇒ true
Register a shell class
73 74 75 76 77 |
# File 'lib/ukiryu/shell.rb', line 73 def register(name, shell_class) raise ArgumentError, 'Shell class must inherit from Ukiryu::Shell::Base' unless shell_class.ancestors.include?(Base) shells[name.to_sym] = shell_class end |
.register_builtin_shells ⇒ 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.
Register all built-in shells
This is called automatically when the module is loaded.
124 125 126 127 128 129 130 131 132 133 |
# File 'lib/ukiryu/shell/registry.rb', line 124 def register_builtin_shells register(Bash) register(Zsh) register(Fish) register(Sh) register(Dash) register(Tcsh) register(PowerShell) register(Cmd) end |
.registered?(name) ⇒ Boolean
Check if a shell is registered
82 83 84 |
# File 'lib/ukiryu/shell/registry.rb', line 82 def registered?(name) @registry.key?(name.to_sym) end |
.registered_shells ⇒ Array<Symbol>
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.
Get all registered shell names
90 91 92 |
# File 'lib/ukiryu/shell.rb', line 90 def registered_shells shells.keys end |
.reset ⇒ Object
Reset the registry (for testing)
112 113 114 115 116 |
# File 'lib/ukiryu/shell/registry.rb', line 112 def reset @mutex.synchronize do @registry = {} end end |
.shell_names ⇒ Array<Symbol>
Get all registered shell names
90 91 92 |
# File 'lib/ukiryu/shell/registry.rb', line 90 def shell_names @registry.keys.select { |k| k.is_a?(Symbol) && !%i[unix windows powershell].include?(k) } end |
.shells ⇒ 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.
64 65 66 |
# File 'lib/ukiryu/shell.rb', line 64 def shells @shells ||= {} end |