Class: Milktea::Application
- Inherits:
-
Object
- Object
- Milktea::Application
- 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
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#loader ⇒ Object
readonly
Returns the value of attribute loader.
-
#program ⇒ Object
readonly
Returns the value of attribute program.
Class Method Summary collapse
- .boot ⇒ Object
- .inherited(subclass) ⇒ Object
- .root(model_name = nil) ⇒ Object
- .root_model_class ⇒ Object
Instance Method Summary collapse
-
#initialize(config: nil) ⇒ Application
constructor
A new instance of Application.
- #run ⇒ Object
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
#config ⇒ Object (readonly)
Returns the value of attribute config.
35 36 37 |
# File 'lib/milktea/application.rb', line 35 def config @config end |
#loader ⇒ Object (readonly)
Returns the value of attribute loader.
35 36 37 |
# File 'lib/milktea/application.rb', line 35 def loader @loader end |
#program ⇒ Object (readonly)
Returns the value of attribute program.
35 36 37 |
# File 'lib/milktea/application.rb', line 35 def program @program end |
Class Method Details
.boot ⇒ Object
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_class ⇒ Object
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
#run ⇒ Object
43 44 45 46 |
# File 'lib/milktea/application.rb', line 43 def run loader.hot_reload if config.hot_reloading? program.run end |