Class: Smol::App
- Inherits:
-
Object
- Object
- Smol::App
- Defined in:
- lib/smol/app.rb
Class Method Summary collapse
- .banner(text = nil) ⇒ Object
- .boot(mode = nil) ⇒ Object
- .checks ⇒ Object
- .cli(enabled = nil) ⇒ Object
- .commands ⇒ Object
- .config ⇒ Object
- .explicit_registration? ⇒ Boolean
- .find_command(name) ⇒ Object
- .find_mount(name) ⇒ Object
- .history_file(path = nil) ⇒ Object
- .inherited(subclass) ⇒ Object
- .mount(app_class, as:) ⇒ Object
- .mounts ⇒ Object
- .register(command_class) ⇒ Object
- .register_check(check_class) ⇒ Object
- .register_command(command_class) ⇒ Object
- .repl(enabled = nil) ⇒ Object
Class Method Details
.banner(text = nil) ⇒ Object
16 17 18 19 |
# File 'lib/smol/app.rb', line 16 def (text = nil) @banner = text if text @banner || "" end |
.boot(mode = nil) ⇒ Object
31 32 33 34 |
# File 'lib/smol/app.rb', line 31 def boot(mode = nil) @boot_mode = mode if mode @boot_mode || :help end |
.checks ⇒ Object
49 50 51 |
# File 'lib/smol/app.rb', line 49 def checks @checks ||= [] end |
.cli(enabled = nil) ⇒ Object
21 22 23 24 |
# File 'lib/smol/app.rb', line 21 def cli(enabled = nil) @cli_enabled = enabled unless enabled.nil? @cli_enabled.nil? ? true : @cli_enabled end |
.commands ⇒ Object
45 46 47 |
# File 'lib/smol/app.rb', line 45 def commands @commands ||= [] end |
.explicit_registration? ⇒ Boolean
90 91 92 |
# File 'lib/smol/app.rb', line 90 def explicit_registration? @explicit_registration || false end |
.find_command(name) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/smol/app.rb', line 61 def find_command(name) # Check for mounted app prefix (e.g., "admin:users") if name.include?(":") prefix, sub_name = name.split(":", 2) if mounts[prefix] return mounts[prefix].find_command(sub_name) end end commands.find { |c| c.matches?(name) } end |
.find_mount(name) ⇒ Object
73 74 75 |
# File 'lib/smol/app.rb', line 73 def find_mount(name) mounts[name.to_s] end |
.history_file(path = nil) ⇒ Object
36 37 38 39 |
# File 'lib/smol/app.rb', line 36 def history_file(path = nil) @history_file = path if path @history_file end |
.inherited(subclass) ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/smol/app.rb', line 6 def inherited(subclass) super subclass.instance_variable_set(:@commands, []) subclass.instance_variable_set(:@checks, []) subclass.instance_variable_set(:@mounts, {}) parent_module = find_parent_module(subclass) setup_registry_methods(parent_module, subclass) if parent_module end |
.mount(app_class, as:) ⇒ Object
57 58 59 |
# File 'lib/smol/app.rb', line 57 def mount(app_class, as:) mounts[as.to_s] = app_class end |
.mounts ⇒ Object
53 54 55 |
# File 'lib/smol/app.rb', line 53 def mounts @mounts ||= {} end |
.register(command_class) ⇒ Object
85 86 87 88 |
# File 'lib/smol/app.rb', line 85 def register(command_class) @explicit_registration = true commands << command_class end |
.register_check(check_class) ⇒ Object
81 82 83 |
# File 'lib/smol/app.rb', line 81 def register_check(check_class) checks << check_class end |
.register_command(command_class) ⇒ Object
77 78 79 |
# File 'lib/smol/app.rb', line 77 def register_command(command_class) commands << command_class end |
.repl(enabled = nil) ⇒ Object
26 27 28 29 |
# File 'lib/smol/app.rb', line 26 def repl(enabled = nil) @repl_enabled = enabled unless enabled.nil? @repl_enabled.nil? ? true : @repl_enabled end |