Class: Milktea::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/milktea/application.rb

Overview

Application class provides a high-level interface for creating Milktea applications It encapsulates the Loader and Program setup, making it easier to create TUI applications

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config: nil) ⇒ Application

Returns a new instance of Application.



37
38
39
40
41
# File 'lib/milktea/application.rb', line 37

def initialize(config: nil)
  @config = config || Milktea.config
  setup_loader
  setup_program
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



35
36
37
# File 'lib/milktea/application.rb', line 35

def config
  @config
end

#loaderObject (readonly)

Returns the value of attribute loader.



35
36
37
# File 'lib/milktea/application.rb', line 35

def loader
  @loader
end

#programObject (readonly)

Returns the value of attribute program.



35
36
37
# File 'lib/milktea/application.rb', line 35

def program
  @program
end

Class Method Details

.bootObject

Raises:



28
29
30
31
32
# File 'lib/milktea/application.rb', line 28

def boot
  return new.run if @root_model_name

  raise Error, "No root model defined. Use 'root \"ModelName\"' in your Application class."
end

.inherited(subclass) ⇒ Object



10
11
12
13
14
# File 'lib/milktea/application.rb', line 10

def inherited(subclass)
  super

  Milktea.app = subclass
end

.root(model_name = nil) ⇒ Object



16
17
18
19
20
# File 'lib/milktea/application.rb', line 16

def root(model_name = nil)
  return @root_model_name if model_name.nil?

  @root_model_name = model_name
end

.root_model_classObject



22
23
24
25
26
# File 'lib/milktea/application.rb', line 22

def root_model_class
  return unless @root_model_name

  Kernel.const_get(@root_model_name)
end

Instance Method Details

#runObject



43
44
45
46
# File 'lib/milktea/application.rb', line 43

def run
  loader.hot_reload if config.hot_reloading?
  program.run
end