Class: DevSystem::NotFoundGenerator

Inherits:
SimpleGenerator show all
Defined in:
lib/dev_system/sub/generator/generators/not_found_generator.rb

Instance Attribute Summary

Attributes inherited from BaseGenerator

#env

Instance Method Summary collapse

Methods inherited from SimpleGenerator

#add_change, #changes, #copy_examples, #copy_file, #copy_files, #create_controller, #create_file, #create_unit, #inform, #last_change, #name!, #place!, #puts_line, #save

Methods inherited from BaseGenerator

#args, #call, call, #command, get_generator_signatures, #inform, #save

Methods inherited from Generator

get_generator_signatures

Methods inherited from Liza::Controller

color, inherited, on_connected

Methods inherited from Liza::Unit

const_missing, division, part, system, #system, test_class

Instance Method Details

#call_defaultObject



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/dev_system/sub/generator/generators/not_found_generator.rb', line 5

def call_default
  h3 "Liza is a light application framework written in Ruby 3.3 ❤", color: DevSystem.color
  h5 "We're optimizing for happiness. Come join us!", color: ColorShell.colors.keys.sample
  puts

  if App.global?
    print_global
  else
    print_systems
    print_app
  end
end

#color(klass) ⇒ Object

color helpers



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/dev_system/sub/generator/generators/not_found_generator.rb', line 20

def color klass
  return klass unless klass < Liza::Unit

  namespace, _sep, classname = klass.to_s.rpartition('::')

  if namespace.empty?
    return stick classname, Liza.const(classname).system.color
  end

  "#{
    stick namespace, Liza.const(namespace).system.color
  }::#{
    stick classname, Liza.const(classname).color
  }"
end

#h1(text) ⇒ Object

typography helpers



124
125
126
# File 'lib/dev_system/sub/generator/generators/not_found_generator.rb', line 124

def h1 text
  puts stick " #{ text } ".center(80, "="), :b
end

#h2(text, color: :white) ⇒ Object



128
129
130
# File 'lib/dev_system/sub/generator/generators/not_found_generator.rb', line 128

def h2 text, color: :white
  puts stick " #{ text } ".center(80, "-"), :b, color
end

#h3(text, color: :white) ⇒ Object



132
133
134
135
# File 'lib/dev_system/sub/generator/generators/not_found_generator.rb', line 132

def h3 text, color: :white
  puts
  puts stick " #{ text } ".center(80, " "), :b, color
end

#h4(system) ⇒ Object



137
138
139
140
141
142
143
144
145
146
147
# File 'lib/dev_system/sub/generator/generators/not_found_generator.rb', line 137

def h4 system
  puts
  s = system.to_s
  s1 = s
  s1 = "#{ color(system) }" if system < Liza::Unit
  color = system.color rescue :white
  t = s.rjust(80, " ")
  t = "#{ stick t, :b, color }"
  t = t.gsub(s, s1)
  puts t
end

#h5(text, color: :white) ⇒ Object



149
150
151
152
153
# File 'lib/dev_system/sub/generator/generators/not_found_generator.rb', line 149

def h5 text, color: :white
  puts
  puts stick text.ljust(80, " "), color
  puts
end


93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/dev_system/sub/generator/generators/not_found_generator.rb', line 93

def print_app
  h1 "TEAM CODE AT app/"

  system_name = "dev"
  tree_system = AppShell.consts[:app]["dev"]

  system = Liza.const "#{system_name}_system"
  tree_system["controllers"].each do |family, structure|
    structure.each do |division, klasses|
      klasses = klasses.select { _1 < Generator }
      if klasses.any?
        h5 "app/#{system_name}/#{division.plural}/", color: system.color
        klasses.each { print_class _1 }
      end
    end
  end
end

print helpers



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/dev_system/sub/generator/generators/not_found_generator.rb', line 38

def print_class klass, description: nil
  loc = klass.to_s

  sidebar_length = 50
  klass.get_generator_signatures.each do |signature|
    signature.name =
      signature.name.empty? \
        ? klass.token.to_s
        : "#{klass.token}:#{signature.name}"
    #
  end.sort_by(&:name).map do |signature|
    puts [
      "liza generate #{signature.name}".ljust(sidebar_length),
      (description or signature.description)
    ].join ""
  end
end


111
112
113
114
115
116
117
118
119
120
# File 'lib/dev_system/sub/generator/generators/not_found_generator.rb', line 111

def print_global
  klasses = {
    # GemfileGenerator => "# no description",
    # EnvGenerator => "# no description",
  }

  klasses.each { print_class _1, description: _2 }

  5.times { puts }
end


77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/dev_system/sub/generator/generators/not_found_generator.rb', line 77

def print_system_sub system, system_name, tree_system
  tree_system["subsystems"].each do |subsystem, tree_subsystem|
    klasses = tree_subsystem["controllers"].values.flatten.select { _1 < Generator }
    next if klasses.empty?

    tree_subsystem["controllers"].each do |controller_class, klasses|
      klasses = klasses.select { _1 < Generator }
      klasses = klasses.reject { _1 == NewGenerator }
      next if klasses.empty?

      h5 "lib/#{system_name}_system/sub/#{subsystem.singular}/#{controller_class.plural}/", color: system.color
      klasses.each { print_class _1 }
    end
  end
end


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/dev_system/sub/generator/generators/not_found_generator.rb', line 58

def print_systems
  h1 "SYSTEMS"
  AppShell.consts[:systems].each do |system_name, tree_system|
    system = tree_system["system"][0]

    h4 system
    tree_system["controllers"].each do |family, klasses|
      klasses = tree_system["controllers"][family].to_a.select { _1 < Generator }
      next if klasses.empty?

      h5 "lib/#{system_name}_system/#{family.plural}/", color: system.color
      klasses.each { print_class _1 }
    end

    print_system_sub system, system_name, tree_system
  end
  puts
end