Class: Liza::Controller
- Inherits:
-
Unit
- Object
- Unit
- Liza::Controller
show all
- Defined in:
- lib/liza/subsystemic_units/controller.rb
Direct Known Subclasses
DevSystem::Bench, DevSystem::Command, DevSystem::Generator, DevSystem::Log, DevSystem::Shell, HappySystem::Axo, NetSystem::Client, NetSystem::Database, NetSystem::Filebase, NetSystem::Record, NetSystem::Socket, PrimeSystem::Epic, WebSystem::Rack, WebSystem::Request
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Unit
_erbs_for, #add, add, #cl, cl, class_methods_defined, const_added, const_missing, constants_defined, define_error, descendants_select, erbs_available, erbs_defined, erbs_for, errors, #fetch, fetch, get, #get, instance_methods_defined, #log, log, log?, #log?, log_array, #log_array, #log_hash, log_hash, #log_level, log_level, log_level?, #log_level?, log_levels, #log_levels, #log_render_convert, #log_render_format, #log_render_in, #log_render_out, method_added, methods_defined, namespace, part, raise_error, #raise_error, #reload!, reload!, #render, #render!, #render_stack, renderable_formats_for, renderable_names, section, sections, #set, set, #settings, settings, singleton_method_added, sleep, #sleep, stick, #stick, #sticks, sticks, subclasses_select, subunits, #system, system, system?, test_class, time_diff, #time_diff
Instance Attribute Details
#menv ⇒ Object
Returns the value of attribute menv.
217
218
219
|
# File 'lib/liza/subsystemic_units/controller.rb', line 217
def menv
@menv
end
|
Class Method Details
.`(s) ⇒ Object
33
34
35
|
# File 'lib/liza/subsystemic_units/controller.rb', line 33
def self.`(s)
KernelShell.call_backticks s
end
|
.attr_accessor(*names) ⇒ Object
179
180
181
182
|
# File 'lib/liza/subsystemic_units/controller.rb', line 179
def self.attr_accessor(*names)
attr_reader(*names)
attr_writer(*names)
end
|
.attr_reader(*names) ⇒ Object
161
162
163
164
165
166
167
168
|
# File 'lib/liza/subsystemic_units/controller.rb', line 161
def self.attr_reader(*names)
names.each do |name|
define_method name do
log :highest, "@#{name} reads #{instance_variable_get("@#{name}").inspect}" unless name == :menv
instance_variable_get "@#{name}"
end
end
end
|
.attr_writer(*names) ⇒ Object
170
171
172
173
174
175
176
177
|
# File 'lib/liza/subsystemic_units/controller.rb', line 170
def self.attr_writer(*names)
names.each do |name|
define_method "#{name}=" do |value|
log :higher, "@#{name} writes #{value.inspect}" unless name == :menv
instance_variable_set "@#{name}", value
end
end
end
|
.box ⇒ Object
72
73
74
|
# File 'lib/liza/subsystemic_units/controller.rb', line 72
def self.box
get :box
end
|
.call(env) ⇒ Object
138
139
140
141
142
143
144
145
146
147
|
# File 'lib/liza/subsystemic_units/controller.rb', line 138
def self.call(env)
log :higher, "env.count is #{env.count}" unless self <= DevSystem::Log
requirements.each do
log :normal, "require '#{_1}'" unless self <= DevSystem::Log
Kernel.require _1
end.clear
true
end
|
.color ⇒ Object
19
20
21
22
23
|
# File 'lib/liza/subsystemic_units/controller.rb', line 19
def self.color
return :white if self == Liza::Controller
return system.color if subsystem?
subsystem.color
end
|
.division ⇒ Object
90
91
92
|
# File 'lib/liza/subsystemic_units/controller.rb', line 90
def self.division
get :division
end
|
.division! ⇒ Object
98
99
100
101
102
103
104
105
106
|
# File 'lib/liza/subsystemic_units/controller.rb', line 98
def self.division!
set :division, self
camel = last_namespace
singular = camel.snakecase.to_sym
plural = "#{camel}s".snakecase.to_sym
fetch(:singular) { singular }
fetch(:plural) { plural }
end
|
.division? ⇒ Boolean
94
95
96
|
# File 'lib/liza/subsystemic_units/controller.rb', line 94
def self.division?
get(:division) == self
end
|
.inherited(klass) ⇒ Object
11
12
13
14
15
|
# File 'lib/liza/subsystemic_units/controller.rb', line 11
def self.inherited klass
super
klass.on_connected if klass.superclass == Liza::Controller
end
|
.menv_accessor(*names) ⇒ Object
212
213
214
215
|
# File 'lib/liza/subsystemic_units/controller.rb', line 212
def self.menv_accessor(*names)
menv_reader(*names)
menv_writer(*names)
end
|
.menv_reader(*names) ⇒ Object
192
193
194
195
196
197
198
199
200
|
# File 'lib/liza/subsystemic_units/controller.rb', line 192
def self.menv_reader(*names)
names.each do |name|
define_method name do
log :highest, "env[:#{name}] reads #{env[name].inspect}", method_name: 'menv_reader'
raise "env is nil!" unless env
env[name]
end
end
end
|
.menv_writer(*names) ⇒ Object
202
203
204
205
206
207
208
209
210
|
# File 'lib/liza/subsystemic_units/controller.rb', line 202
def self.menv_writer(*names)
names.each do |name|
define_method "#{name}=" do |value|
log :higher, "env[:#{name}] writes #{value.inspect}", method_name: 'menv_writer'
raise "env is nil!" unless env
env[name] = value
end
end
end
|
.on_connected ⇒ Object
5
6
7
8
9
|
# File 'lib/liza/subsystemic_units/controller.rb', line 5
def self.on_connected
token = self.last_namespace.snakecase.to_sym
subsystem! system.box, token
division!
end
|
.panel ⇒ Object
76
77
78
|
# File 'lib/liza/subsystemic_units/controller.rb', line 76
def self.panel
get :panel
end
|
.plural ⇒ Object
118
119
120
121
122
123
124
|
# File 'lib/liza/subsystemic_units/controller.rb', line 118
def self.plural
case
when subsystem? then get :plural
when division? then :"#{token}_#{subsystem.plural}"
else :"#{token}_#{division.plural}"
end
end
|
.require(gem_name) ⇒ Object
This gem will be lazily required
152
153
154
155
|
# File 'lib/liza/subsystemic_units/controller.rb', line 152
def self.require(gem_name)
log :higher, "lazy require '#{gem_name}'" unless self <= DevSystem::Log
requirements << gem_name
end
|
.requirements ⇒ Object
157
|
# File 'lib/liza/subsystemic_units/controller.rb', line 157
def self.requirements()= @requirements ||= fetch(:requirements) { [] }
|
.sh(s) ⇒ Object
25
26
27
|
# File 'lib/liza/subsystemic_units/controller.rb', line 25
def self.sh(s)
KernelShell.call_system s
end
|
.singular ⇒ Object
110
111
112
113
114
115
116
|
# File 'lib/liza/subsystemic_units/controller.rb', line 110
def self.singular
case
when subsystem? then get :singular
when division? then :"#{token}_#{subsystem.singular}"
else :"#{token}_#{division.singular}"
end
end
|
.subsystem ⇒ Object
47
48
49
|
# File 'lib/liza/subsystemic_units/controller.rb', line 47
def self.subsystem
get :subsystem
end
|
.subsystem!(box_klass, token) ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/liza/subsystemic_units/controller.rb', line 55
def self.subsystem! box_klass, token
panel = box_klass[token]
set :subsystem_token, token
set :subsystem, self
set :box, box_klass
set :panel, panel
panel.settings.each do |k, v|
next if settings.key? k
set k, v
end
end
|
.subsystem? ⇒ Boolean
51
52
53
|
# File 'lib/liza/subsystemic_units/controller.rb', line 51
def self.subsystem?
get(:subsystem) == self
end
|
.subsystem_token ⇒ Object
43
44
45
|
# File 'lib/liza/subsystemic_units/controller.rb', line 43
def self.subsystem_token
get :subsystem_token
end
|
.token ⇒ Object
126
127
128
129
130
131
132
133
134
|
# File 'lib/liza/subsystemic_units/controller.rb', line 126
def self.token
if subsystem?
nil
elsif division?
last_namespace.gsub(/#{subsystem.last_namespace}$/, '').snakecase.to_sym
else
last_namespace.gsub(/#{division.last_namespace}$/, '').snakecase.to_sym
end
end
|
Instance Method Details
#`(s) ⇒ Object
37
38
39
|
# File 'lib/liza/subsystemic_units/controller.rb', line 37
def `(s)
KernelShell.call_backticks s
end
|
#attrs ⇒ Object
184
185
186
187
188
|
# File 'lib/liza/subsystemic_units/controller.rb', line 184
def attrs
instance_variables.map do |ivar|
[ivar, instance_variable_get(ivar)]
end.to_h
end
|
#box ⇒ Object
80
81
82
|
# File 'lib/liza/subsystemic_units/controller.rb', line 80
def box
self.class.box
end
|
#panel ⇒ Object
84
85
86
|
# File 'lib/liza/subsystemic_units/controller.rb', line 84
def panel
self.class.panel
end
|
#sh(s) ⇒ Object
29
30
31
|
# File 'lib/liza/subsystemic_units/controller.rb', line 29
def sh(s)
KernelShell.call_system s
end
|