Class: DevSystem::LocCommand

Inherits:
SimpleCommand show all
Defined in:
lib/dev_system/sub/shell/commands/loc_command.rb

Overview

LocCommand is a custom LinesOfCode script using gem coderay

Instance Attribute Summary

Attributes inherited from BaseCommand

#env

Instance Method Summary collapse

Methods inherited from SimpleCommand

#call, #log_simple_remember, #simple_arg, #simple_arg_ask, #simple_arg_ask_snakecase, #simple_args, #simple_boolean, #simple_boolean_no, #simple_boolean_yes, #simple_color, #simple_controller_placement, #simple_string

Methods inherited from BaseCommand

call, #call, get_command_signatures

Methods inherited from Command

call, #call, get_command_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

liza loc



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/dev_system/sub/shell/commands/loc_command.rb', line 7

def call_default
  log "LINES OF CODE"
  puts
  log "TODO: write filters"
  puts

  print_top_level
  print_liza
  print_systems
  print_app
end

#color(klass) ⇒ Object

color helpers



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/dev_system/sub/shell/commands/loc_command.rb', line 152

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



120
121
122
# File 'lib/dev_system/sub/shell/commands/loc_command.rb', line 120

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

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



124
125
126
# File 'lib/dev_system/sub/shell/commands/loc_command.rb', line 124

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

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



128
129
130
131
# File 'lib/dev_system/sub/shell/commands/loc_command.rb', line 128

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

#h4(system) ⇒ Object



133
134
135
136
137
138
139
140
141
142
143
# File 'lib/dev_system/sub/shell/commands/loc_command.rb', line 133

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



145
146
147
148
# File 'lib/dev_system/sub/shell/commands/loc_command.rb', line 145

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


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
# File 'lib/dev_system/sub/shell/commands/loc_command.rb', line 92

def print_app
  if App.global?
    h1 "TOP LEVEL CONSTANTS"
  else
    h1 "TOP LEVEL CONSTANTS OWNED BY THE TEAM"
  end
  start_total
  AppShell.consts[:app].each do |system_name, tree_system|

    system = Liza.const "#{system_name}_system"
    h5 "app/#{system_name}_box.rb", color: system.color

    tree_system["box"].each { print_class _1 }

    tree_system["controllers"].each do |family, structure|
      start_subtotal
      structure.each do |division, klasses|
        h5 "app/#{system_name}/#{division.plural}/", color: system.color
        klasses.each { print_class _1 }
      end
      print_subtotal
    end
  end
  print_total
end

class helpers



189
190
191
192
193
194
195
196
# File 'lib/dev_system/sub/shell/commands/loc_command.rb', line 189

def print_class klass
  text, loc = read_loc klass
  
  @total_loc += loc
  @subtotal_loc += loc if defined? @subtotal_loc

  puts "#{loc.to_s.rjust 5} LINES #{ (color klass) rescue klass }"
end


30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/dev_system/sub/shell/commands/loc_command.rb', line 30

def print_liza
  start_total
  h1 "LIZA NAMESPACE"
  h4 Liza
  AppShell.consts[:liza].each do |category, klasses|
    start_subtotal
    h5 "lib/liza/#{category}/"
    klasses.each { print_class _1 }
    print_subtotal
  end
  print_total
  puts
end


178
179
180
181
# File 'lib/dev_system/sub/shell/commands/loc_command.rb', line 178

def print_subtotal
  puts stick :b, :silver, "#{@subtotal_loc.to_s.rjust 5} TOTAL-ISH"
  puts
end


76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/dev_system/sub/shell/commands/loc_command.rb', line 76

def print_system_sub system, system_name, tree_system
  tree_system["subsystems"].each do |subsystem, tree_subsystem|
    h4 subsystem
    h5 "lib/#{system_name}_system/sub/#{subsystem.singular}/", color: system.color

    tree_subsystem["panel"].each { print_class _1 }
    tree_subsystem["controller"].each { print_class _1 }
    tree_subsystem["controllers"].each do |controller_class, klasses|
      start_subtotal
      h5 "lib/#{system_name}_system/sub/#{subsystem.singular}/#{controller_class.plural}/", color: system.color
      klasses.each { print_class _1 }
      print_subtotal
    end
  end
end


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/dev_system/sub/shell/commands/loc_command.rb', line 44

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

    h4 system
    h5 "lib/#{system_name}_system/", color: system.color

    tree_system["system"].each { print_class _1 }
    tree_system["box"].each { print_class _1 }
    print_subtotal

    if tree_system["controllers"].any?
      start_subtotal
      h3 "controllers"
      tree_system["controllers"].each do |family, klasses|
        h5 "lib/#{system_name}_system/#{family.plural}/", color: system.color
        klasses.each { print_class _1 }
      end
      print_subtotal
    end

    h3 "subsystems" if tree_system["subsystems"].any?
    print_system_sub system, system_name, tree_system

    print_total
  end
  puts
end

sub-methods



21
22
23
24
25
26
27
28
# File 'lib/dev_system/sub/shell/commands/loc_command.rb', line 21

def print_top_level
  start_total
  h1 "TOP LEVEL CONSTANTS OWNED BY LIZA"
  h5 "lib/"
  AppShell.consts[:top_level].each { print_class _1 }
  print_total
  puts
end


183
184
185
# File 'lib/dev_system/sub/shell/commands/loc_command.rb', line 183

def print_total
  puts stick :b, :silver, "#{@total_loc.to_s.rjust 5} TOTAL"
end

#read_loc(klass) ⇒ Object

loc helpers



200
201
202
203
204
205
206
207
208
209
# File 'lib/dev_system/sub/shell/commands/loc_command.rb', line 200

def read_loc(klass)
  require "coderay"

  fname = klass.source_location[0]
  fname = fname.sub "/version", "" if klass == Lizarb # this is a hack :)
  text  = TextShell.read(fname, log_level: :lower)
  loc   = CodeRay.scan(text, :ruby).loc

  [text, loc]
end

#start_subtotalObject



174
175
176
# File 'lib/dev_system/sub/shell/commands/loc_command.rb', line 174

def start_subtotal
  @subtotal_loc = 0
end

#start_totalObject

total helpers



170
171
172
# File 'lib/dev_system/sub/shell/commands/loc_command.rb', line 170

def start_total
  @total_loc = 0
end