Class: Lucie::App

Inherits:
Object
  • Object
show all
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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_levelObject

Sets the log level of the application.



25
26
27
# File 'lib/lucie/app.rb', line 25

def log_level
  @log_level
end

.raise_exceptionObject

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

.rootObject

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

#commandObject (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

#pwdObject (readonly)

The directory where from the application has been executed.



48
49
50
# File 'lib/lucie/app.rb', line 48

def pwd
  @pwd
end

#rootObject (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.

Parameters:

  • command (Array or String) (defaults to: ARGV)
  • root (String) (defaults to: nil)

    Path of the root of the app. [default: current application’s path]

  • pwd (String) (defaults to: nil)

    Path of the terminal position.



64
65
66
67
# File 'lib/lucie/app.rb', line 64

def self.init(command = ARGV, root = nil, pwd = nil)
  root ||= File.expand_path("..", 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.expand_path("..", 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.

Parameters:

  • instance (App)

    Application instance



73
74
75
76
# File 'lib/lucie/app.rb', line 73

def self.start(instance)
  instance.start
  instance.exit_value
end

Instance Method Details

#envObject

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_valueObject

Exit status of the application



93
94
95
# File 'lib/lucie/app.rb', line 93

def exit_value
  @exit_value
end

#startObject

Starts the application.



88
89
90
# File 'lib/lucie/app.rb', line 88

def start
  help? ? call_help : call_method_invoking_process
end