Class: App
- Inherits:
-
Object
- Object
- App
- Defined in:
- lib/app.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- DEFAULT_LOG_LEVEL =
settings
4- LOG_LEVELS =
{ :highest => 7, :higher => 6, :high => 5, :normal => 4, :low => 3, :lower => 2, :lowest => 1, }
Class Method Summary collapse
- ._call_class_command(args) ⇒ Object
- ._call_instance_command(args) ⇒ Object
-
.call(argv) ⇒ Object
called from exe/lizarb.
- .call_version ⇒ Object
- .coding? ⇒ Boolean
-
.directory(directory = nil, systems: nil) ⇒ Object
directory.
- .directory_name ⇒ Object
-
.env_vars(*files, mandatory: false) ⇒ Object
env_vars.
- .env_vars_mandatory? ⇒ Boolean
- .file ⇒ Object
- .filename ⇒ Object
-
.gemfile(gemfile = :unset, &block) ⇒ Object
gemfile.
-
.global? ⇒ Boolean
helpers.
- .log(s) ⇒ Object
- .log_boot(level = nil) ⇒ Object
- .log_level(level = nil) ⇒ Object
-
.mode(mode = nil) ⇒ Object
mode.
-
.name(name = nil) ⇒ Object
name.
- .path ⇒ Object
- .project? ⇒ Boolean
- .relative_path ⇒ Object
- .root ⇒ Object
- .script? ⇒ Boolean
- .sfa? ⇒ Boolean
- .system(key) ⇒ Object
- .systems ⇒ Object
- .systems_directory(systems_directory = nil) ⇒ Object
- .systems_directory_name ⇒ Object
- .type ⇒ Object
Instance Method Summary collapse
Class Method Details
._call_class_command(args) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/app.rb', line 29 def self._call_class_command(args) method_name = "call_#{args.shift[2..]}" send(method_name, *args) rescue NoMethodError raise Error, "Invalid App Command `#{args[0]}`. Define a class-method named `#{method_name}` on App", caller[1..], cause: nil end |
._call_instance_command(args) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/app.rb', line 36 def self._call_instance_command(args) method_name = "call_#{args.shift[1..]}" new.send(method_name, *args) rescue NoMethodError raise Error, "Invalid App Command `#{args[0]}`. Define an instance-method named `#{method_name}` on App", caller[1..], cause: nil end |
.call(argv) ⇒ Object
called from exe/lizarb
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/app.rb', line 11 def self.call argv log "#{$boot_time.diff}s to boot" if defined? $log_boot_low should_log = log_level >= 4 puts if should_log log "#{self}.#{__method__}(#{argv.inspect})" if should_log args = argv.dup argv.clear if args[0] return _call_class_command(args) if args[0][0..1] == "--" return _call_instance_command(args) if args[0][0] == "-" end Liza::DevBox.configuration.command args puts if should_log end |
.call_version ⇒ Object
55 56 57 |
# File 'lib/app.rb', line 55 def self.call_version puts "LizaRB v#{Lizarb::VERSION}" end |
.coding? ⇒ Boolean
133 134 135 |
# File 'lib/app.rb', line 133 def self.coding? mode == :code end |
.directory(directory = nil, systems: nil) ⇒ Object
directory
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/app.rb', line 65 def self.directory(directory = nil, systems: nil) if directory @directory_name = directory @directory = directory @relative_path = directory @path = "#{Lizarb.app_dir}/#{directory}" self.systems_directory systems if systems else @directory end end |
.directory_name ⇒ Object
87 |
# File 'lib/app.rb', line 87 def self.directory_name () = @directory_name |
.env_vars(*files, mandatory: false) ⇒ Object
env_vars
139 140 141 142 143 144 145 146 147 |
# File 'lib/app.rb', line 139 def self.env_vars *files, mandatory: false @env_vars ||= [] if files.any? mode = self.mode.to_s @env_vars += files.map { _1.sub(":directory", directory).sub(":mode", mode) } @env_vars_mandatory = mandatory end @env_vars end |
.env_vars_mandatory? ⇒ Boolean
149 150 151 |
# File 'lib/app.rb', line 149 def self.env_vars_mandatory? @env_vars_mandatory end |
.file ⇒ Object
51 52 53 |
# File 'lib/app.rb', line 51 def self.file filename end |
.filename ⇒ Object
47 48 49 |
# File 'lib/app.rb', line 47 def self.filename root.join "#{$APP}.rb" end |
.gemfile(gemfile = :unset, &block) ⇒ Object
gemfile
112 113 114 115 116 117 118 119 120 121 |
# File 'lib/app.rb', line 112 def self.gemfile(gemfile = :unset, &block) raise "locked" if @locked if block_given? @gemfile = block elsif gemfile != :unset @gemfile = gemfile else @gemfile end end |
.global? ⇒ Boolean
helpers
200 201 202 |
# File 'lib/app.rb', line 200 def self.global? $APP == "app_global" end |
.log(s) ⇒ Object
6 7 8 |
# File 'lib/app.rb', line 6 def self.log s puts s end |
.log_boot(level = nil) ⇒ Object
182 183 184 185 186 187 188 |
# File 'lib/app.rb', line 182 def self.log_boot level = nil return @log_boot if level.nil? level = LOG_LEVELS[level] if level.is_a? Symbol raise Error, "invalid log level `#{level}`", caller unless LOG_LEVELS.values.include? level @log_boot = level end |
.log_level(level = nil) ⇒ Object
190 191 192 193 194 195 196 |
# File 'lib/app.rb', line 190 def self.log_level level = nil return @log_level if level.nil? level = LOG_LEVELS[level] if level.is_a? Symbol raise Error, "invalid log level `#{level}`", caller unless LOG_LEVELS.values.include? level @log_level = level end |
.mode(mode = nil) ⇒ Object
mode
125 126 127 128 129 130 131 |
# File 'lib/app.rb', line 125 def self.mode mode = nil if mode @mode = mode.to_sym else @mode ||= (ENV["MODE"] || :code).to_sym end end |
.name(name = nil) ⇒ Object
name
101 102 103 104 105 106 107 108 |
# File 'lib/app.rb', line 101 def self.name(name = nil) raise "locked" if @locked if name @name = name else @name end end |
.path ⇒ Object
91 92 93 |
# File 'lib/app.rb', line 91 def self.path @path end |
.project? ⇒ Boolean
214 215 216 |
# File 'lib/app.rb', line 214 def self.project? type == :project end |
.relative_path ⇒ Object
95 96 97 |
# File 'lib/app.rb', line 95 def self.relative_path @relative_path or raise "@relative_path not set" end |
.script? ⇒ Boolean
218 219 220 |
# File 'lib/app.rb', line 218 def self.script? type == :script end |
.sfa? ⇒ Boolean
210 211 212 |
# File 'lib/app.rb', line 210 def self.sfa? type == :sfa end |
.system(key) ⇒ Object
157 158 159 160 |
# File 'lib/app.rb', line 157 def self.system key raise "locked" if @locked @systems[key] = nil end |
.systems ⇒ Object
162 163 164 |
# File 'lib/app.rb', line 162 def self.systems @systems end |
.systems_directory(systems_directory = nil) ⇒ Object
77 78 79 80 81 82 83 84 85 |
# File 'lib/app.rb', line 77 def self.systems_directory(systems_directory = nil) raise "locked" if @locked if systems_directory @systems_directory = systems_directory @systems_directory_name = systems_directory else @systems_directory end end |
.systems_directory_name ⇒ Object
89 |
# File 'lib/app.rb', line 89 def self.systems_directory_name () = @systems_directory_name ||= "lib" |
.type ⇒ Object
206 207 208 |
# File 'lib/app.rb', line 206 def self.type Lizarb.setup_type end |