Class: Smol::App

Inherits:
Object
  • Object
show all
Defined in:
lib/smol/app.rb

Class Method Summary collapse

Class Method Details



16
17
18
19
# File 'lib/smol/app.rb', line 16

def banner(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

.checksObject



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

.commandsObject



45
46
47
# File 'lib/smol/app.rb', line 45

def commands
  @commands ||= []
end

.configObject



41
42
43
# File 'lib/smol/app.rb', line 41

def config
  @config ||= Config.new
end

.explicit_registration?Boolean

Returns:

  • (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

.mountsObject



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