Class: DevSystem::AppShell

Inherits:
Shell show all
Defined in:
lib/dev_system/subsystems/shell/shells/app_shell.rb

Defined Under Namespace

Classes: Domain, Layer

Instance Attribute Summary collapse

Attributes inherited from Liza::Controller

#menv

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Shell

all, cruby?, engine, jruby?, linux?, mac?, os, ruby_version, unix?, windows?

Methods inherited from Liza::Controller

#`, `, attr_accessor, attr_reader, attr_writer, #attrs, box, #box, call, color, division, division!, division?, inherited, menv_accessor, menv_reader, menv_writer, on_connected, panel, #panel, plural, require, requirements, sh, #sh, singular, subsystem, subsystem!, subsystem?, subsystem_token, token

Methods inherited from Liza::Unit

_erbs_for, #add, add, cl, #cl, class_methods_defined, const_added, const_missing, constants_defined, define_error, descendants_select, division, 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

Constructor Details

#initializeAppShell

Returns a new instance of AppShell.



32
33
34
35
36
37
38
39
# File 'lib/dev_system/subsystems/shell/shells/app_shell.rb', line 32

def initialize
  Lizarb.eager_load!
  h = @consts = {}
  h[:top_level]  = [Lizarb, App, Liza]
  h[:liza]       = get_liza_classes_structured
  h[:systems]    = get_system_classes_structured
  h[:app]        = get_object_classes_structured
end

Instance Attribute Details

#constsObject (readonly)

Returns the value of attribute consts.



30
31
32
# File 'lib/dev_system/subsystems/shell/shells/app_shell.rb', line 30

def consts
  @consts
end

Class Method Details

.constsObject



24
25
26
# File 'lib/dev_system/subsystems/shell/shells/app_shell.rb', line 24

def self.consts
  new.consts
end

.get_writable_domainsObject



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/dev_system/subsystems/shell/shells/app_shell.rb', line 10

def self.get_writable_domains
  ret = {}
  is_core_writeable = Lizarb.is_gem_dir

  ret[:core] = "Core" if is_core_writeable
  ret.merge! writable_systems
  ret[:app] = "App"
  ret.transform_keys! { _1.to_s }

  ret
end

.writable_systemsObject



5
6
7
8
# File 'lib/dev_system/subsystems/shell/shells/app_shell.rb', line 5

def self.writable_systems
  root = App.root.to_s
  App.systems.select { _2.source_location_radical.start_with? root }
end

Instance Method Details

#_log_count(msg) ⇒ Object



41
42
43
# File 'lib/dev_system/subsystems/shell/shells/app_shell.rb', line 41

def _log_count(msg)
  log "count: #{count} | #{msg}"
end

#_log_historyObject



473
474
475
# File 'lib/dev_system/subsystems/shell/shells/app_shell.rb', line 473

def _log_history
  log_filter "filter_history size: #{filter_history.size}, results size: #{get_lists.map(&:size).sum}"
end

#checkObject



459
460
461
462
# File 'lib/dev_system/subsystems/shell/shells/app_shell.rb', line 459

def check
  filter_history << get_lists.map(&:dup)
  _log_history
end

#countObject



45
# File 'lib/dev_system/subsystems/shell/shells/app_shell.rb', line 45

def count() = get_lists.flatten.count

#filter_by_any_name_including(names) ⇒ Object



423
424
425
426
427
428
429
430
431
432
433
# File 'lib/dev_system/subsystems/shell/shells/app_shell.rb', line 423

def filter_by_any_name_including(names)
  names = names.map &:snakecase
  log_filter names.inspect
  check

  get_lists.each do |list|
    list.select! { |klass| names.any? { |name| klass.last_namespace.snakecase.include? name } }
  end

  self
end

#filter_by_domains(domains) ⇒ Object



345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
# File 'lib/dev_system/subsystems/shell/shells/app_shell.rb', line 345

def filter_by_domains(domains)
  log_filter domains.inspect
  check
  _log_count ""

  system_names = domains - ["core", "app"]
  is_core_included = domains.include? "core"
  is_app_included = domains.include? "app"

  unless is_core_included
    _log_count "core is not included in the domains"

    consts[:top_level].clear
    consts[:liza].values.map &:clear
  end

  consts[:systems].reject do |system_name, tree_system|
    system_names.include? system_name
  end.each do |system_name, tree_system|
    tree_system["system"].clear
    tree_system["box"].clear
    tree_system["parts"].clear
      tree_system["controllers"].values.map &:clear
      tree_system["subsystems"].values.map { _1.values.map &:clear }

    _log_count "#{system_name} is not included in the domains"
  end

  unless is_app_included
    consts[:app].each do |system_name, tree_system|
      tree_system["box"].clear
      tree_system["controllers"].values.each { _1.values.map &:clear }
    end
    
    _log_count "app is not included in the domains"
  end

  _log_count ""

  self
end

#filter_by_including_all_names(names) ⇒ Object



435
436
437
438
439
440
441
442
443
444
445
# File 'lib/dev_system/subsystems/shell/shells/app_shell.rb', line 435

def filter_by_including_all_names(names)
  names = names.map &:snakecase
  log_filter names.inspect
  check

  get_lists.each do |list|
    list.select! { |klass| names.all? { |name| klass.last_namespace.snakecase.include? name } }
  end

  self
end

#filter_by_including_any_name(names) ⇒ Object



447
448
449
# File 'lib/dev_system/subsystems/shell/shells/app_shell.rb', line 447

def filter_by_including_any_name(names)
  filter_by_any_name_including(names)
end

#filter_by_name_including(name) ⇒ Object



399
400
401
402
403
404
405
406
407
408
409
# File 'lib/dev_system/subsystems/shell/shells/app_shell.rb', line 399

def filter_by_name_including(name)
  name = name.downcase
  log_filter name.inspect
  check

  get_lists.each do |list|
    list.select! { _1.to_s.snakecase.include? name }
  end

  self
end

#filter_by_starting_with(name) ⇒ Object



411
412
413
414
415
416
417
418
419
420
421
# File 'lib/dev_system/subsystems/shell/shells/app_shell.rb', line 411

def filter_by_starting_with(name)
  name = name.downcase
  log_filter name.inspect
  check

  get_lists.each do |list|
    list.select! { _1.last_namespace.snakecase.start_with? name }
  end

  self
end

#filter_by_systems(*systems) ⇒ Object



387
388
389
390
391
392
393
394
395
396
397
# File 'lib/dev_system/subsystems/shell/shells/app_shell.rb', line 387

def filter_by_systems(*systems)
  log_filter systems.inspect
  systems = systems.map { (_1.is_a? Symbol) ? App.systems[_1] : _1 }
  check

  get_lists.each do |list|
    list.select! { (_1 <= Liza::Unit) ? (systems.include? _1.system) : true }
  end

  self
end

#filter_by_unit(unit_class) ⇒ Object



333
334
335
336
337
338
339
340
341
342
343
# File 'lib/dev_system/subsystems/shell/shells/app_shell.rb', line 333

def filter_by_unit(unit_class)
  log_filter unit_class.inspect
  check

  get_lists.each do |list|
    list.reject! { _1.class == Module }
    list.select! { _1 <= unit_class }
  end

  self
end

#filter_historyObject



455
456
457
# File 'lib/dev_system/subsystems/shell/shells/app_shell.rb', line 455

def filter_history
  @filter_history ||= []
end

#filter_in_units(*units) ⇒ Object



322
323
324
325
326
327
328
329
330
331
# File 'lib/dev_system/subsystems/shell/shells/app_shell.rb', line 322

def filter_in_units(*units)
  log_filter units.inspect
  check

  get_lists.each do |list|
    list.select! { units.include? _1 }
  end

  self
end

#filter_out_units(*units) ⇒ Object



311
312
313
314
315
316
317
318
319
320
# File 'lib/dev_system/subsystems/shell/shells/app_shell.rb', line 311

def filter_out_units(*units)
  log_filter units.inspect
  check

  get_lists.each do |list|
    list.reject! { units.include? _1 }
  end

  self
end

#get_domainsArray<Domain>

Returns an array of domains representing the core, systems, and app.

Each Domain contains the name, color, and layers of the core, systems, and app.

Examples:

domains = app_shell.get_domains
domains.each do |domain|
  log domain.name
  log domain.color
  domain.layers.each do |layer|
    log layer.name
    log layer.path
    layer.objects.each do |object|
      log object
    end
  end
end

Returns:

  • (Array<Domain>)

    An array of domains.



499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
# File 'lib/dev_system/subsystems/shell/shells/app_shell.rb', line 499

def get_domains
  ret = []

  log_filter "reading the domain of the core"

  ret << Domain.new(
    name: "core",
    color: :white,
    layers: get_layers_for_core
  )

  log_filter "reading the domains of the systems"

  App.systems.values.each do |system|
    ret << Domain.new(
      name: system.to_s,
      color: system.color,
      layers: get_layers_for_system(system)
    )
  end

  log_filter "reading the domain of the app"

  ret << Domain.new(
    name: "app",
    color: :white,
    layers: get_layers_for_app
  )

  ret
end

#get_layers_for_appObject



619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
# File 'lib/dev_system/subsystems/shell/shells/app_shell.rb', line 619

def get_layers_for_app
  ret = []

  ret << Layer.new(
    level: 1,
    name: "App",
    color: system.color,
    path: "#{App.directory_name}/",
    objects: []
  )

  consts[:app].each do |system_name, tree_system|
    system = App.systems[system_name.to_sym]
    ret << Layer.new(
      level: 2,
      name: system_name,
      color: system.color,
      path: "app/#{system_name}_box.rb",
      objects: tree_system["box"]
    )
    tree_system["controllers"].each do |controller_name, structure|
      structure.each do |division_name, klasses|
        division = Liza.const division_name
        ret << Layer.new(
          level: 3,
          name: division.plural,
          color: system.color,
          path: "app/#{system_name}/#{division.plural}/",
          objects: klasses
        )
      end
    end
  end

  ret
end

#get_layers_for_coreObject



531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
# File 'lib/dev_system/subsystems/shell/shells/app_shell.rb', line 531

def get_layers_for_core
  ret = []

  ret << Layer.new(
    level: 1,
    name: "top level",
    color: :white,
    path: "lib/",
    objects: consts[:top_level]
  )

  consts[:liza].each do |category, classes|
    path = "lib/liza/#{category}/"
    ret << Layer.new(
      level: 2,
      name: category,
      color: :white,
      path: ,
      objects: classes
    )
  end

  ret
end

#get_layers_for_system(system) ⇒ Object



556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
# File 'lib/dev_system/subsystems/shell/shells/app_shell.rb', line 556

def get_layers_for_system(system)
  ret = []

  tree_system = consts[:systems][system.token.to_s]
  path = system.source_location_radical.sub("#{App.root}/", "")
  ret << Layer.new(
    level: 1,
    name: system.to_s,
    color: system.color,
    path: ,
    objects: tree_system["system"] + tree_system["box"]
  )
  
  tree_system["controllers"].each do |division_name, klasses|
    division = Liza.const division_name
    path = system.source_location_radical.sub("#{App.root}/", "")
    path << "/#{division.plural}/"

    name = division.plural
    color = division.subsystem.system.color

    ret << Layer.new(
      level: 3,
      name: ,
      color: ,
      path: ,
      objects: klasses
    )
  end

  tree_system["subsystems"].each do |subsystem_token, tree_subsystem|
    subsystem = system.const subsystem_token
    path = system.source_location_radical.sub("#{App.root}/", "")
    path << "/subsystems/#{subsystem.singular}/"
    ret << Layer.new(
      level: 2,
      name: subsystem.to_s,
      color: system.color,
      path: ,
      objects: tree_subsystem["controller"] + tree_subsystem["panel"]
    )

    tree_subsystem["controllers"].each do |controller_name, klasses|
      controller = Liza.const controller_name
      path = system.source_location_radical.sub("#{App.root}/", "")
      path << "/subsystems/#{subsystem.singular}/#{controller.division.plural}/"

      name = controller.plural
      color = controller.subsystem.system.color

      ret << Layer.new(
        level: 3,
        name: ,
        color: ,
        path: ,
        objects: klasses
      )
    end
  end

  ret
end

#get_listsObject



271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# File 'lib/dev_system/subsystems/shell/shells/app_shell.rb', line 271

def get_lists
  ret = []

  ret << consts[:top_level]

  consts[:liza].each do |category, classes|
    ret << classes
  end

  consts[:systems].each do |system_name, tree_system|
    ret << tree_system["system"]
    ret << tree_system["box"]
    ret << tree_system["parts"]
    tree_system["controllers"].values.each do |klasses|
      ret << klasses
    end
    tree_system["subsystems"].values.each do |tree_subsystem|
      ret << tree_subsystem["panel"]
      ret << tree_subsystem["controller"]
      tree_subsystem["controllers"].values.each do |klasses|
        ret << klasses
      end
    end
  end

  consts[:app].each do |system_name, tree_system|
    ret << tree_system["box"]
    tree_system["controllers"].each do |_controller, structure|
      
      structure.each do |_division, klasses|
        ret << klasses
      end
    end
  end

  ret
end

#get_liza_categoriesObject



49
50
51
# File 'lib/dev_system/subsystems/shell/shells/app_shell.rb', line 49

def get_liza_categories
  ["unit", "helper_units", "systemic_units", "subsystemic_units", "extra_tests"]
end

#get_liza_classes_structuredObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/dev_system/subsystems/shell/shells/app_shell.rb', line 55

def get_liza_classes_structured
  ret = {}
  liza_classes = ZeitwerkShell.get_units_in_core

  ret["unit"] =
    liza_classes
      .select { _1.source_location_radical.include? "/liza/unit" }
      .sort_by { _1.to_s }

  ret["helper_units"] =
    liza_classes
      .select { _1.source_location_radical.include? "/liza/helper_units" }
      .sort_by { _1.to_s }

  ret["systemic_units"] =
    liza_classes
      .select { _1.source_location_radical.include? "/liza/systemic_units" }
      .sort_by { _1.to_s }

  ret["subsystemic_units"] =
    liza_classes
      .select { _1.source_location_radical.include? "/liza/subsystemic_units" }
      .sort_by { _1.to_s }

  ret["extra_tests"] =
    liza_classes
      .select { _1.source_location_radical.include? "/liza/extra_tests" }
      .sort_by { _1.to_s }

  ret
end

#get_object_classes_structuredObject



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/dev_system/subsystems/shell/shells/app_shell.rb', line 161

def get_object_classes_structured
  ret = {}

  object_classes = ZeitwerkShell.get_units_in_app.sort_by { _1.source_location_radical }

  App.systems.each do |system_name, system|
    tree = ret[system_name.to_s] = {}

    a = object_classes.select { _1.system == system }
    
    tree["box"] = []
    box = Liza.const "#{system_name}_box"
    if box.namespace == Object
      tree["box"] << box
      a.delete box
    end

    tree["controllers"] = {}

    a.each do |klass|
      tree["controllers"][klass.subsystem.subsystem_token] ||= {}
      tree["controllers"][klass.subsystem.subsystem_token][klass.division.last_namespace] ||= []
      tree["controllers"][klass.subsystem.subsystem_token][klass.division.last_namespace] << klass
    end

    system.subsystems.values.each do |subsystem|
      tree["controllers"][subsystem.subsystem_token]&.each do |division, klasses|
        klasses.sort_by! &:to_s
      end
    end

  end

  ret
end

#get_system_classes_structuredObject



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/dev_system/subsystems/shell/shells/app_shell.rb', line 87

def get_system_classes_structured
  ret = {}

  App.systems.each do |system_name, system|
    tree = ret[system_name.to_s] = {}

    system_classes = ZeitwerkShell.get_units_in_system system
    array = system_classes.select { _1.system == system }

    part_classes = array.select { _1.source_location_radical.include? "/#{system_name}_system/parts/" }

    tree["system"]      = [system, system.test_class]
    tree["box"]         = [system.box, system.box.test_class]
    tree["parts"]       = part_classes
    tree["controllers"] = {}
    tree["subsystems"]  = {}

    array.delete system
    array.delete system.test_class
    array.delete system.box
    array.delete system.box.test_class
    part_classes.each do |klass|
      array.delete klass
    end

    system.subsystems.values.each do |subsystem|
      part_classes = array.select { _1.source_location_radical.include?("/subsystems/#{subsystem.last_namespace.downcase}/parts/") }
      tree["subsystems"][subsystem.subsystem_token] = {}
      tree["subsystems"][subsystem.subsystem_token]["parts"] = part_classes
      tree["subsystems"][subsystem.subsystem_token]["panel"] = [subsystem.panel.class, subsystem.panel.class.test_class]
      tree["subsystems"][subsystem.subsystem_token]["controller"] = [subsystem, subsystem.test_class]
      tree["subsystems"][subsystem.subsystem_token]["controllers"] = {}

      array.delete subsystem.panel.class
      array.delete subsystem.panel.class.test_class
      array.delete subsystem
      array.delete subsystem.test_class
      part_classes.each do |klass|
        array.delete klass
      end

    end

    array.each do |klass|
      radical = klass.source_location_radical
      tree = ret[system_name.to_s] or raise "no tree for #{system_name}"

      if radical.include? "/#{system_name}_system/subsystems"
        name = radical.split("_system/subsystems/").last.split("/").first
        subsystem = system.const name
        klasses = tree["subsystems"][subsystem.subsystem_token]["controllers"][klass.division.last_namespace] ||= []
      else
        klasses = tree["controllers"][klass.division.last_namespace] ||= []
      end

      klasses << klass
    end

  end

  ret.each do |system_name, tree|
    tree["subsystems"].each do |subsystem_name, subsystem_tree|
      subsystem_tree["controllers"].values.each do |controllers|
        controllers.sort_by! &:to_s
      end
    end
    tree["controllers"].values.each do |controllers|
      controllers.sort_by! &:to_s
    end
  end

  ret
end

#get_test_unitsObject



267
268
269
# File 'lib/dev_system/subsystems/shell/shells/app_shell.rb', line 267

def get_test_units
  units.select { _1 <= Liza::UnitTest }
end

#get_unitsObject



263
264
265
# File 'lib/dev_system/subsystems/shell/shells/app_shell.rb', line 263

def get_units
  get_lists.flatten.select { _1 <= Liza::Unit }
end

#log_filter(string) ⇒ Object



451
452
453
# File 'lib/dev_system/subsystems/shell/shells/app_shell.rb', line 451

def log_filter(string)
  log (stick :black, :light_green, string), kaller: caller if log? :higher
end

#sorted_unitsObject



207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
# File 'lib/dev_system/subsystems/shell/shells/app_shell.rb', line 207

def sorted_units
  begin
    ret = []
    consts[:liza].each do |category, classes|
      classes.each do |klass|
        ret << klass
      end
    end
    consts[:systems].each do |system_name, tree|
      tree["box"].each do |klass|
        ret << klass
      end
      tree["parts"].each do |klass|
        ret << klass
      end
      tree["controllers"].values.each do |controllers|
        controllers.each do |klass|
          ret << klass
        end
      end

      tree["subsystems"].each do |subsystem_name, subsystem_tree|
        subsystem_tree["panel"].each do |klass|
          ret << klass
        end
        subsystem_tree["parts"].each do |klass|
          ret << klass
        end
        subsystem_tree["controller"].each do |klass|
          ret << klass
        end
        subsystem_tree["controllers"].values.each do |controllers|
          controllers.each do |klass|
            ret << klass
          end
        end
      end
    end
    consts[:app].each do |system_name, tree|
      tree["box"].each do |klass|
        ret << klass
      end
      tree["controllers"].values.each do |divisions|
        divisions.values.each do |controllers|
          controllers.each do |klass|
            ret << klass
          end
        end
      end
    end
    ret.freeze
  end
end

#sorted_writable_unitsObject



203
204
205
# File 'lib/dev_system/subsystems/shell/shells/app_shell.rb', line 203

def sorted_writable_units
  sorted_units.select { _1.source_location_radical.start_with? App.root.to_s }
end

#sorted_writable_units_in_systemsObject



199
200
201
# File 'lib/dev_system/subsystems/shell/shells/app_shell.rb', line 199

def sorted_writable_units_in_systems
  sorted_units.select { _1.source_location_radical.start_with? App.systems_directory.to_s }
end

#undo_filter!Object



464
465
466
467
468
469
470
471
# File 'lib/dev_system/subsystems/shell/shells/app_shell.rb', line 464

def undo_filter!
  old_lists = filter_history.pop
  get_lists.each.with_index do |list, i|
    list.clear
    list.concat old_lists[i]
  end
  _log_history
end