Class: Lucie::App
- Inherits:
-
Object
- Object
- Lucie::App
- Defined in:
- lib/lucie/app.rb
Overview
Lucie::App represents the application context. When a lucie application starts, it requires information about its environment, like root path, env, command. App also responsible for loading the right controller and to execute the process how the input will be parsed and the business logic is executed.
Class Attribute Summary collapse
-
.log_level ⇒ Object
Sets the log level of the application.
-
.raise_exception ⇒ Object
Let the exception leave the application when any occur.
-
.root ⇒ Object
Root directory of the source of application.
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Command line input that is being executed.
-
#pwd ⇒ Object
readonly
The directory where from the application has been executed.
-
#root ⇒ Object
readonly
Root of the application.
Class Method Summary collapse
-
.init(command = ARGV, root = nil, pwd = nil) ⇒ Object
Initializes the application.
-
.run(command = ARGV, root = nil, pwd = nil) ⇒ Object
Initializes and starts the applicaiton.
-
.start(instance) ⇒ Object
Starts the application instance and returns its exit status.
Instance Method Summary collapse
-
#env ⇒ Object
Environment of the application.
-
#exit_value ⇒ Object
Exit status of the application.
-
#initialize(command, root, pwd = nil) ⇒ App
constructor
A new instance of App.
-
#start ⇒ Object
Starts the application.
Constructor Details
#initialize(command, root, pwd = nil) ⇒ App
Returns a new instance of App.
78 79 80 81 82 83 84 85 |
# File 'lib/lucie/app.rb', line 78 def initialize(command, root, pwd = nil) @root = root @command = Core::CommandLineParser.new(command) @exit_value ||= 0 @task = nil @pwd = pwd || ENV["PWD"] Dir.chdir(@pwd) end |
Class Attribute Details
.log_level ⇒ Object
Sets the log level of the application.
25 26 27 |
# File 'lib/lucie/app.rb', line 25 def log_level @log_level end |
.raise_exception ⇒ Object
Let the exception leave the application when any occur.
Normally the application doesn’t raise any exception, just stops quietly. When the application is under debugging, developer needs more, detailed description about the problem. Suggested to turn this attribute on during developing.
App.raise_exception = true
21 22 23 |
# File 'lib/lucie/app.rb', line 21 def raise_exception @raise_exception end |
.root ⇒ Object
Root directory of the source of application.
Template and other source paths are calculated relatively to this directory.
32 33 34 |
# File 'lib/lucie/app.rb', line 32 def root @root end |
Instance Attribute Details
#command ⇒ Object (readonly)
Command line input that is being executed. Usually it equals with ARGV.
40 41 42 |
# File 'lib/lucie/app.rb', line 40 def command @command end |
#pwd ⇒ Object (readonly)
The directory where from the application has been executed.
48 49 50 |
# File 'lib/lucie/app.rb', line 48 def pwd @pwd end |
#root ⇒ Object (readonly)
Root of the application. Same as App.root, it’s a reference for that.
44 45 46 |
# File 'lib/lucie/app.rb', line 44 def root @root end |
Class Method Details
.init(command = ARGV, root = nil, pwd = nil) ⇒ Object
Initializes the application.
64 65 66 67 |
# File 'lib/lucie/app.rb', line 64 def self.init(command = ARGV, root = nil, pwd = nil) root ||= File.("..", File.dirname(Kernel.caller[0])) self.new(command, root, pwd) end |
.run(command = ARGV, root = nil, pwd = nil) ⇒ Object
Initializes and starts the applicaiton. Shortcut for self.init && self.start
52 53 54 55 56 |
# File 'lib/lucie/app.rb', line 52 def self.run(command = ARGV, root = nil, pwd = nil) root ||= File.("..", File.dirname(Kernel.caller[0])) instance = self.init(command, root, pwd) self.start(instance) end |
.start(instance) ⇒ Object
Starts the application instance and returns its exit status.
73 74 75 76 |
# File 'lib/lucie/app.rb', line 73 def self.start(instance) instance.start instance.exit_value end |
Instance Method Details
#env ⇒ Object
Environment of the application. Contains the ENV of the terminal.
98 99 100 |
# File 'lib/lucie/app.rb', line 98 def env ENV end |
#exit_value ⇒ Object
Exit status of the application
93 94 95 |
# File 'lib/lucie/app.rb', line 93 def exit_value @exit_value end |
#start ⇒ Object
Starts the application.
88 89 90 |
# File 'lib/lucie/app.rb', line 88 def start help? ? call_help : call_method_invoking_process end |