gloo 0.7.7 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (203) hide show
  1. checksums.yaml +4 -4
  2. data/.DS_Store +0 -0
  3. data/.gitignore +2 -1
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/LICENSE.txt +1 -1
  7. data/gloo.gemspec +15 -6
  8. data/lib/VERSION +1 -1
  9. data/lib/dependencies.rb +4 -4
  10. data/lib/gloo/app/info.rb +3 -1
  11. data/lib/gloo/app/log.rb +1 -29
  12. data/lib/gloo/app/platform.rb +142 -0
  13. data/lib/gloo/objs/cli/banner.rb +2 -2
  14. data/lib/gloo/objs/cli/bar.rb +4 -4
  15. data/lib/gloo/objs/cli/colorize.rb +3 -3
  16. data/lib/gloo/objs/cli/confirm.rb +3 -3
  17. data/lib/gloo/objs/cli/menu.rb +9 -9
  18. data/lib/gloo/objs/cli/menu_item.rb +2 -2
  19. data/lib/gloo/objs/cli/pastel.rb +2 -2
  20. data/lib/gloo/objs/cli/prompt.rb +4 -4
  21. data/lib/gloo/objs/cli/select.rb +4 -4
  22. data/lib/gloo/objs/dev/git.rb +7 -7
  23. data/lib/gloo/objs/dev/stats.rb +8 -5
  24. data/lib/gloo/objs/snd/play.rb +1 -1
  25. data/lib/gloo/objs/snd/say.rb +2 -2
  26. data/lib/gloo/objs/system/file_handle.rb +9 -9
  27. data/lib/gloo/objs/system/ssh_exec.rb +3 -3
  28. data/lib/gloo/objs/system/system.rb +2 -2
  29. data/lib/gloo/verbs/alert.rb +7 -7
  30. data/lib/gloo/verbs/beep.rb +1 -1
  31. data/lib/gloo/verbs/cls.rb +2 -2
  32. data/lib/gloo/verbs/help.rb +7 -189
  33. data/lib/gloo/verbs/version.rb +3 -3
  34. data/lib/gloo.rb +5 -1
  35. data/lib/run.rb +5 -1
  36. metadata +43 -221
  37. data/Gemfile.lock +0 -168
  38. data/lib/gloo/app/args.rb +0 -112
  39. data/lib/gloo/app/engine.rb +0 -230
  40. data/lib/gloo/app/help.rb +0 -156
  41. data/lib/gloo/app/mode.rb +0 -27
  42. data/lib/gloo/app/settings.rb +0 -186
  43. data/lib/gloo/convert/converter.rb +0 -35
  44. data/lib/gloo/convert/string_to_datetime.rb +0 -21
  45. data/lib/gloo/convert/string_to_decimal.rb +0 -20
  46. data/lib/gloo/convert/string_to_integer.rb +0 -20
  47. data/lib/gloo/core/baseo.rb +0 -30
  48. data/lib/gloo/core/dictionary.rb +0 -181
  49. data/lib/gloo/core/error.rb +0 -61
  50. data/lib/gloo/core/event_manager.rb +0 -44
  51. data/lib/gloo/core/factory.rb +0 -210
  52. data/lib/gloo/core/gloo_system.rb +0 -266
  53. data/lib/gloo/core/heap.rb +0 -52
  54. data/lib/gloo/core/here.rb +0 -36
  55. data/lib/gloo/core/it.rb +0 -36
  56. data/lib/gloo/core/literal.rb +0 -30
  57. data/lib/gloo/core/obj.rb +0 -303
  58. data/lib/gloo/core/obj_finder.rb +0 -30
  59. data/lib/gloo/core/op.rb +0 -40
  60. data/lib/gloo/core/parser.rb +0 -59
  61. data/lib/gloo/core/pn.rb +0 -188
  62. data/lib/gloo/core/tokens.rb +0 -165
  63. data/lib/gloo/core/verb.rb +0 -86
  64. data/lib/gloo/exec/action.rb +0 -48
  65. data/lib/gloo/exec/dispatch.rb +0 -40
  66. data/lib/gloo/exec/exec_env.rb +0 -74
  67. data/lib/gloo/exec/runner.rb +0 -45
  68. data/lib/gloo/exec/script.rb +0 -49
  69. data/lib/gloo/exec/stack.rb +0 -78
  70. data/lib/gloo/expr/expression.rb +0 -118
  71. data/lib/gloo/expr/l_boolean.rb +0 -36
  72. data/lib/gloo/expr/l_decimal.rb +0 -39
  73. data/lib/gloo/expr/l_integer.rb +0 -37
  74. data/lib/gloo/expr/l_string.rb +0 -58
  75. data/lib/gloo/expr/op_div.rb +0 -22
  76. data/lib/gloo/expr/op_minus.rb +0 -22
  77. data/lib/gloo/expr/op_mult.rb +0 -22
  78. data/lib/gloo/expr/op_plus.rb +0 -24
  79. data/lib/gloo/help/app/application.txt +0 -22
  80. data/lib/gloo/help/app/configuration.txt +0 -7
  81. data/lib/gloo/help/app/default_help.txt +0 -14
  82. data/lib/gloo/help/app/logging.txt +0 -16
  83. data/lib/gloo/help/core/color.txt +0 -31
  84. data/lib/gloo/help/core/error.txt +0 -33
  85. data/lib/gloo/help/core/events.txt +0 -21
  86. data/lib/gloo/help/core/gloo_system.txt +0 -57
  87. data/lib/gloo/help/core/here.txt +0 -30
  88. data/lib/gloo/help/core/it.txt +0 -23
  89. data/lib/gloo/help/core/ops.txt +0 -16
  90. data/lib/gloo/help/core/pathname.txt +0 -29
  91. data/lib/gloo/help/objs/basic/alias.txt +0 -36
  92. data/lib/gloo/help/objs/basic/boolean.txt +0 -28
  93. data/lib/gloo/help/objs/basic/container.txt +0 -33
  94. data/lib/gloo/help/objs/basic/decimal.txt +0 -28
  95. data/lib/gloo/help/objs/basic/integer.txt +0 -27
  96. data/lib/gloo/help/objs/basic/script.txt +0 -29
  97. data/lib/gloo/help/objs/basic/string.txt +0 -28
  98. data/lib/gloo/help/objs/basic/text.txt +0 -27
  99. data/lib/gloo/help/objs/basic/untyped.txt +0 -22
  100. data/lib/gloo/help/objs/cli/banner.txt +0 -49
  101. data/lib/gloo/help/objs/cli/bar.txt +0 -37
  102. data/lib/gloo/help/objs/cli/colorize.txt +0 -33
  103. data/lib/gloo/help/objs/cli/confirm.txt +0 -26
  104. data/lib/gloo/help/objs/cli/menu.txt +0 -44
  105. data/lib/gloo/help/objs/cli/menu_item.txt +0 -26
  106. data/lib/gloo/help/objs/cli/pastel.txt +0 -43
  107. data/lib/gloo/help/objs/cli/prompt.txt +0 -27
  108. data/lib/gloo/help/objs/cli/select.txt +0 -34
  109. data/lib/gloo/help/objs/ctrl/each.txt +0 -48
  110. data/lib/gloo/help/objs/ctrl/repeat.txt +0 -38
  111. data/lib/gloo/help/objs/data/markdown.txt +0 -25
  112. data/lib/gloo/help/objs/data/mysql.txt +0 -40
  113. data/lib/gloo/help/objs/data/query.txt +0 -37
  114. data/lib/gloo/help/objs/data/sqlite.txt +0 -26
  115. data/lib/gloo/help/objs/data/table.txt +0 -46
  116. data/lib/gloo/help/objs/dev/git_repo.txt +0 -36
  117. data/lib/gloo/help/objs/dev/stats.txt +0 -36
  118. data/lib/gloo/help/objs/dt/date.txt +0 -23
  119. data/lib/gloo/help/objs/dt/datetime.txt +0 -24
  120. data/lib/gloo/help/objs/dt/time.txt +0 -23
  121. data/lib/gloo/help/objs/ror/erb.txt +0 -37
  122. data/lib/gloo/help/objs/ror/eval.txt +0 -24
  123. data/lib/gloo/help/objs/snd/play.txt +0 -23
  124. data/lib/gloo/help/objs/snd/say.txt +0 -28
  125. data/lib/gloo/help/objs/system/file.txt +0 -48
  126. data/lib/gloo/help/objs/system/ssh_exec.txt +0 -30
  127. data/lib/gloo/help/objs/system/system.txt +0 -32
  128. data/lib/gloo/help/objs/web/http_get.txt +0 -35
  129. data/lib/gloo/help/objs/web/http_post.txt +0 -34
  130. data/lib/gloo/help/objs/web/json.txt +0 -34
  131. data/lib/gloo/help/objs/web/slack.txt +0 -33
  132. data/lib/gloo/help/objs/web/teams.txt +0 -30
  133. data/lib/gloo/help/objs/web/uri.txt +0 -38
  134. data/lib/gloo/help/verbs/alert.txt +0 -33
  135. data/lib/gloo/help/verbs/beep.txt +0 -25
  136. data/lib/gloo/help/verbs/cls.txt +0 -24
  137. data/lib/gloo/help/verbs/context.txt +0 -43
  138. data/lib/gloo/help/verbs/create.txt +0 -33
  139. data/lib/gloo/help/verbs/execute.txt +0 -27
  140. data/lib/gloo/help/verbs/help.txt +0 -34
  141. data/lib/gloo/help/verbs/if.txt +0 -37
  142. data/lib/gloo/help/verbs/list.txt +0 -34
  143. data/lib/gloo/help/verbs/load.txt +0 -38
  144. data/lib/gloo/help/verbs/move.txt +0 -42
  145. data/lib/gloo/help/verbs/put.txt +0 -38
  146. data/lib/gloo/help/verbs/quit.txt +0 -25
  147. data/lib/gloo/help/verbs/run.txt +0 -41
  148. data/lib/gloo/help/verbs/save.txt +0 -26
  149. data/lib/gloo/help/verbs/show.txt +0 -30
  150. data/lib/gloo/help/verbs/tell.txt +0 -34
  151. data/lib/gloo/help/verbs/unless.txt +0 -38
  152. data/lib/gloo/help/verbs/version.txt +0 -32
  153. data/lib/gloo/help/verbs/wait.txt +0 -29
  154. data/lib/gloo/objs/basic/alias.rb +0 -78
  155. data/lib/gloo/objs/basic/boolean.rb +0 -120
  156. data/lib/gloo/objs/basic/container.rb +0 -76
  157. data/lib/gloo/objs/basic/decimal.rb +0 -76
  158. data/lib/gloo/objs/basic/integer.rb +0 -73
  159. data/lib/gloo/objs/basic/script.rb +0 -99
  160. data/lib/gloo/objs/basic/string.rb +0 -77
  161. data/lib/gloo/objs/basic/text.rb +0 -87
  162. data/lib/gloo/objs/basic/untyped.rb +0 -41
  163. data/lib/gloo/objs/ctrl/each.rb +0 -279
  164. data/lib/gloo/objs/ctrl/repeat.rb +0 -108
  165. data/lib/gloo/objs/data/markdown.rb +0 -84
  166. data/lib/gloo/objs/data/mysql.rb +0 -192
  167. data/lib/gloo/objs/data/query.rb +0 -176
  168. data/lib/gloo/objs/data/sqlite.rb +0 -159
  169. data/lib/gloo/objs/data/table.rb +0 -140
  170. data/lib/gloo/objs/dt/date.rb +0 -50
  171. data/lib/gloo/objs/dt/datetime.rb +0 -62
  172. data/lib/gloo/objs/dt/time.rb +0 -50
  173. data/lib/gloo/objs/ror/erb.rb +0 -116
  174. data/lib/gloo/objs/ror/eval.rb +0 -107
  175. data/lib/gloo/objs/web/http_get.rb +0 -159
  176. data/lib/gloo/objs/web/http_post.rb +0 -183
  177. data/lib/gloo/objs/web/json.rb +0 -135
  178. data/lib/gloo/objs/web/slack.rb +0 -130
  179. data/lib/gloo/objs/web/teams.rb +0 -117
  180. data/lib/gloo/objs/web/uri.rb +0 -148
  181. data/lib/gloo/persist/file_loader.rb +0 -191
  182. data/lib/gloo/persist/file_saver.rb +0 -49
  183. data/lib/gloo/persist/file_storage.rb +0 -45
  184. data/lib/gloo/persist/line_splitter.rb +0 -81
  185. data/lib/gloo/persist/persist_man.rb +0 -120
  186. data/lib/gloo/utils/format.rb +0 -21
  187. data/lib/gloo/utils/stats.rb +0 -205
  188. data/lib/gloo/utils/words.rb +0 -19
  189. data/lib/gloo/verbs/context.rb +0 -62
  190. data/lib/gloo/verbs/create.rb +0 -68
  191. data/lib/gloo/verbs/execute.rb +0 -56
  192. data/lib/gloo/verbs/if.rb +0 -92
  193. data/lib/gloo/verbs/list.rb +0 -98
  194. data/lib/gloo/verbs/load.rb +0 -45
  195. data/lib/gloo/verbs/move.rb +0 -89
  196. data/lib/gloo/verbs/put.rb +0 -94
  197. data/lib/gloo/verbs/quit.rb +0 -40
  198. data/lib/gloo/verbs/run.rb +0 -75
  199. data/lib/gloo/verbs/save.rb +0 -39
  200. data/lib/gloo/verbs/show.rb +0 -64
  201. data/lib/gloo/verbs/tell.rb +0 -79
  202. data/lib/gloo/verbs/unless.rb +0 -92
  203. data/lib/gloo/verbs/wait.rb +0 -42
@@ -1,191 +0,0 @@
1
- # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
- # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
- #
4
- # Helper class used to load a file and create objects in the heap.
5
- #
6
-
7
- module Gloo
8
- module Persist
9
- class FileLoader
10
-
11
- BEGIN_BLOCK = 'BEGIN'.freeze
12
- END_BLOCK = 'END'.freeze
13
- SPACE_CNT = 2
14
-
15
- attr_reader :obj
16
-
17
- #
18
- # Set up a file storage for an object.
19
- #
20
- def initialize( pn )
21
- @pn = pn
22
- @tabs = 0
23
- @obj = nil
24
- @in_multiline = false
25
- @exiting_multiline = false
26
- @in_block = false
27
- @block_value = ''
28
- @debug = false
29
- end
30
-
31
- #
32
- # Load the objects from the file.
33
- #
34
- def load
35
- unless File.exist?( @pn )
36
- $log.error "File '#{@pn}' does not exist."
37
- return
38
- end
39
-
40
- $log.debug "Loading file '#{@pn}'"
41
- @tabs = 0
42
- @parent_stack = []
43
- @parent = $engine.heap.root
44
- @parent_stack.push @parent
45
- f = File.open( @pn, 'r' )
46
- f.each_line do |line|
47
- next if skip_line? line
48
-
49
- handle_one_line line
50
- end
51
- end
52
-
53
- #
54
- # Process one one of the file we're loading.
55
- #
56
- def handle_one_line( line )
57
- if line.strip.end_with? BEGIN_BLOCK
58
- @in_block = true
59
- @save_line = line
60
- elsif @in_block
61
- if line.strip == END_BLOCK
62
- @in_block = false
63
- determine_indent @save_line
64
- process_line @save_line
65
- else
66
- @block_value << line
67
- end
68
- else
69
- determine_indent line
70
- process_line line
71
- end
72
- end
73
-
74
- #
75
- # Is this line a comment or a blank line?
76
- # If so we'll skip it.
77
- #
78
- def skip_line?( line )
79
- line = line.strip
80
- return true if line.empty?
81
- return true if line[ 0 ] == '#'
82
-
83
- return false
84
- end
85
-
86
- #
87
- # Determine the relative indent level for the line.
88
- #
89
- def determine_indent( line )
90
- tabs = tab_count( line )
91
- @indent = 0 # same level as prior line
92
- if tabs > @tabs # indent
93
- # TODO: What if indent is more than one more level?
94
- @tabs = tabs
95
- @indent = 1
96
- elsif tabs < @tabs # outdent
97
- diff = @tabs - tabs
98
- @tabs -= diff
99
- @indent -= diff
100
- end
101
- puts "tabs: #{@tabs}, indent: #{@indent}, line: #{line}" if @debug
102
- end
103
-
104
- #
105
- # Process one line and add objects.
106
- #
107
- def process_line( line )
108
- # reset multiline unless we're actually indented
109
- if @in_multiline && @multi_indent > @indent
110
- puts "Done multiline mi: #{@multi_indent}, i: #{@indent}" if @debug
111
- @in_multiline = false
112
- @exiting_multiline = true
113
- end
114
-
115
- if @in_multiline
116
- @last.add_line line
117
- else
118
- setup_process_obj_line
119
- process_obj_line line
120
- end
121
- end
122
-
123
- #
124
- # Setup and get ready to process an object line.
125
- #
126
- def setup_process_obj_line
127
- if @exiting_multiline
128
- @exiting_multiline = false
129
- @indent += 1
130
- end
131
-
132
- if @indent.positive?
133
- @parent = @last
134
- @parent_stack.push @parent
135
- elsif @indent.negative?
136
- @indent.abs.times do
137
- @parent_stack.pop
138
- @parent = @parent_stack.last
139
- end
140
- end
141
- end
142
-
143
- #
144
- # Process one line and add objects.
145
- #
146
- def process_obj_line( line )
147
- name, type, value = split_line( line )
148
- unless @block_value == ''
149
- value = @block_value
150
- @block_value = ''
151
- end
152
- params = { name: name, type: type, value: value, parent: @parent }
153
- @last = $engine.factory.create( params )
154
-
155
- if value.empty? && @last&.multiline_value?
156
- @multi_indent = 0
157
- @in_multiline = true
158
- puts "*** Start multiline. multi_indent: #{@multi_indent}" if @debug
159
- end
160
-
161
- @obj = @last if @obj.nil?
162
- end
163
-
164
- #
165
- # Get the number of leading tabs.
166
- #
167
- def tab_count( line )
168
- i = 0
169
-
170
- if line[ i ] == ' '
171
- i += 1 while line[ i ] == ' '
172
- tab_equiv = ( i / SPACE_CNT ).to_i
173
- puts "Found #{i} spaces => #{tab_equiv}" if @debug
174
- return tab_equiv
175
- end
176
-
177
- i += 1 while line[ i ] == "\t"
178
- return i
179
- end
180
-
181
- #
182
- # Split the line into 3 parts.
183
- #
184
- def split_line( line )
185
- o = LineSplitter.new( line, @tabs )
186
- return o.split
187
- end
188
-
189
- end
190
- end
191
- end
@@ -1,49 +0,0 @@
1
- # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
- # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
- #
4
- # Helper class used to save an object to a file..
5
- #
6
-
7
- module Gloo
8
- module Persist
9
- class FileSaver
10
-
11
- #
12
- # Set up a file storage for an object.
13
- #
14
- def initialize( pn, obj )
15
- @pn = pn
16
- @obj = obj
17
- end
18
-
19
- #
20
- # Save the object to the file.
21
- #
22
- def save
23
- data = get_obj( @obj )
24
- File.write( @pn, data )
25
- end
26
-
27
- #
28
- # Get string of tabs for indentation.
29
- #
30
- def tabs( indent = 0 )
31
- return "\t" * indent
32
- end
33
-
34
- #
35
- # Convert an object to textual representation.
36
- # This is a recursive function.
37
- #
38
- def get_obj( obj, indent = 0 )
39
- t = tabs( indent )
40
- str = "#{t}#{obj.name} [#{obj.type_display}] : #{obj.value_display}\n"
41
- obj.children.each do |child|
42
- str << get_obj( child, indent + 1 )
43
- end
44
- return str
45
- end
46
-
47
- end
48
- end
49
- end
@@ -1,45 +0,0 @@
1
- # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
- # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
- #
4
- # Helper class takes an object and writes it to a file.
5
- #
6
-
7
- module Gloo
8
- module Persist
9
- class FileStorage
10
-
11
- attr_reader :obj, :pn
12
-
13
- #
14
- # Set up a file storage for an object.
15
- #
16
- def initialize( pn, obj = nil )
17
- @obj = obj
18
- @pn = pn
19
- end
20
-
21
- #
22
- # Save the object to the file.
23
- #
24
- def save
25
- fs = FileSaver.new @pn, @obj
26
- fs.save
27
- end
28
-
29
- #
30
- # Load the object from the file.
31
- #
32
- def load
33
- fl = FileLoader.new @pn
34
- fl.load
35
- @obj = fl.obj
36
- if @obj
37
- $log.debug "Loaded object: #{@obj.name}"
38
- else
39
- $log.error "Error loading file at #{@pn}"
40
- end
41
- end
42
-
43
- end
44
- end
45
- end
@@ -1,81 +0,0 @@
1
- # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
- # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
- #
4
- # Helper class used as part of file loading.
5
- # It is responsible for splitting a line into components.
6
- #
7
-
8
- module Gloo
9
- module Persist
10
- class LineSplitter
11
-
12
- BEGIN_BLOCK = 'BEGIN'.freeze
13
- END_BLOCK = 'END'.freeze
14
-
15
- attr_reader :obj
16
-
17
- #
18
- # Set up a line splitter
19
- #
20
- def initialize( line, tabs )
21
- @line = line
22
- @tabs = tabs
23
- end
24
-
25
- #
26
- # Split the line into 3 parts.
27
- #
28
- def split
29
- detect_name
30
- detect_type
31
- detect_value
32
-
33
- return @name, @type, @value
34
- end
35
-
36
- #
37
- # Detect the object name.
38
- #
39
- def detect_name
40
- @line = @line.strip
41
- @idx = @line.index( ' ' )
42
- @name = @line[ 0..@idx - 1 ]
43
- end
44
-
45
- #
46
- # Detect the object type.
47
- #
48
- def detect_type
49
- @line = @line[ @idx + 1..-1 ]
50
- @idx = @line.index( ' ' )
51
-
52
- if @line[ 0 ] == ':'
53
- @type = 'untyped'
54
- return
55
- end
56
-
57
- @type = @line[ 0..( @idx ? @idx - 1 : -1 ) ]
58
- @type = @type[ 1..-1 ] if @type[ 0 ] == '['
59
- @type = @type[ 0..-2 ] if @type[ -1 ] == ']'
60
- end
61
-
62
- #
63
- # Detect the object value.
64
- # Use nil if there is no value specified.
65
- #
66
- def detect_value
67
- if @idx
68
- @value = @line[ @idx + 1..-1 ]
69
- if @value[ 0..1 ] == ': '
70
- @value = @value[ 2..-1 ]
71
- elsif @value[ 0 ] == ':'
72
- @value = @value[ 1..-1 ]
73
- end
74
- else
75
- @value = nil
76
- end
77
- end
78
-
79
- end
80
- end
81
- end
@@ -1,120 +0,0 @@
1
- # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
- # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
- #
4
- # The persistance manager.
5
- # Keeps a collection of object-file mappings, and then
6
- # uses mappings to know how/where to save updated objects.
7
- #
8
-
9
- module Gloo
10
- module Persist
11
- class PersistMan
12
-
13
- attr_reader :maps
14
-
15
- #
16
- # Contructor for the persistence manager.
17
- #
18
- def initialize
19
- @maps = []
20
- end
21
-
22
- #
23
- # Save one object to the file.
24
- #
25
- def save( name = '' )
26
- if name.nil? || name.strip.empty?
27
- save_all
28
- else
29
- save_one name
30
- end
31
- end
32
-
33
- #
34
- # Save one object to the file.
35
- #
36
- def save_all
37
- @maps.each( &:save )
38
- end
39
-
40
- #
41
- # Save one object to the file.
42
- #
43
- def save_one( name )
44
- ref = Gloo::Core::Pn.new name
45
- obj = ref.resolve
46
- pn = get_full_path_name name
47
- fs = Gloo::Persist::FileStorage.new( pn, obj )
48
- fs.save
49
- end
50
-
51
- #
52
- # Load the object from the file.
53
- #
54
- def load( name )
55
- pns = get_full_path_names name
56
- return unless pns
57
-
58
- pns.each do |pn|
59
- $log.debug "Load file(s) at: #{pn}"
60
- fs = Gloo::Persist::FileStorage.new( pn )
61
- fs.load
62
- @maps << fs
63
- $engine.event_manager.on_load fs.obj
64
- end
65
- end
66
-
67
- #
68
- # Get the full path and name of the file.
69
- #
70
- def get_full_path_names( name )
71
- return nil if name.strip.empty?
72
-
73
- if name.strip[ -1 ] == '*'
74
- pns = []
75
- dir = File.join( $settings.project_path, name[ 0..-2 ] )
76
- Dir.glob( "#{dir}*.gloo" ).each do |f|
77
- pns << f
78
- end
79
- return pns
80
- else
81
- ext_path = File.expand_path( name )
82
- return [ ext_path ] if self.gloo_file?( ext_path )
83
-
84
- full_name = "#{name}#{file_ext}"
85
- return [ File.join( $settings.project_path, full_name ) ]
86
- end
87
- end
88
-
89
- #
90
- # Check to see if a given path name refers to a gloo object file.
91
- #
92
- def gloo_file?( name )
93
- return false unless name
94
- return false unless File.exist?( name )
95
- return false unless File.file?( name )
96
- return false unless name.end_with?( self.file_ext )
97
-
98
- return true
99
- end
100
-
101
- #
102
- # Get the default file extention.
103
- #
104
- def file_ext
105
- return '.gloo'
106
- end
107
-
108
- #
109
- # Print out all object - persistance mappings.
110
- # This is a debugging tool.
111
- #
112
- def show_maps
113
- @maps.each do |o|
114
- puts " \t #{o.pn} \t #{o.obj.name}"
115
- end
116
- end
117
-
118
- end
119
- end
120
- end
@@ -1,21 +0,0 @@
1
- # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
- # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
- #
4
- # Formatting utilities
5
- #
6
-
7
- module Gloo
8
- module Utils
9
- class Format
10
-
11
- #
12
- # Format number, adding comma separators.
13
- # Ex: 1000 -> 1,000
14
- #
15
- def self.number( num )
16
- return num.to_s.reverse.scan( /.{1,3}/ ).join( ',' ).reverse
17
- end
18
-
19
- end
20
- end
21
- end
@@ -1,205 +0,0 @@
1
- # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
- # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
- #
4
- # Utilities related to words (strings).
5
- #
6
-
7
- module Gloo
8
- module Utils
9
- class Stats
10
-
11
- DIR_NOT_FOUND_ERR = 'The folder was not found!'.freeze
12
-
13
- # ---------------------------------------------------------------------
14
- # Setup
15
- # ---------------------------------------------------------------------
16
-
17
- #
18
- # Create a stats utility class for the given directory.
19
- #
20
- def initialize( dir, types, skip = [] )
21
- @dir = dir
22
- setup_loc types
23
- @skip = skip
24
- end
25
-
26
- # ---------------------------------------------------------------------
27
- # Public Functions
28
- # ---------------------------------------------------------------------
29
-
30
- #
31
- # Is the stats utility valid?
32
- # Does it have a valid root directory.
33
- #
34
- def valid?
35
- return true if @dir && File.directory?( @dir )
36
-
37
- $engine.err DIR_NOT_FOUND_ERR
38
- $engine.heap.it.set_to false
39
-
40
- return false
41
- end
42
-
43
- #
44
- # Show all stat data for the project.
45
- #
46
- def show_all
47
- return unless valid?
48
-
49
- generate
50
- puts "Showing All stats for #{@dir}".white
51
- puts "\n ** #{@dir_cnt} Total Folders ** "
52
- puts " ** #{@file_cnt} Total Files ** "
53
-
54
- busy_folders( 7 )
55
- file_types
56
- loc
57
- end
58
-
59
- #
60
- # Get a list of the busiest folders.
61
- # Count is how many results we want.
62
- #
63
- def busy_folders( count = 17 )
64
- return unless valid?
65
-
66
- generate
67
- puts "\nBusy Folders:".yellow
68
-
69
- @folders.sort! { |a, b| a[ :cnt ] <=> b[ :cnt ] }
70
- @folders.reverse!
71
- @folders[ 0..count ].each do |f|
72
- puts " #{f[ :cnt ]} - #{f[ :name ]}"
73
- end
74
- end
75
-
76
- #
77
- # Show file types and how many of each there are.
78
- #
79
- def file_types
80
- return unless valid?
81
-
82
- generate
83
- puts "\nFiles by Type:".yellow
84
-
85
- @types = @types.sort_by( &:last )
86
- @types.reverse!
87
- @types.each do |o|
88
- puts " #{o[ 1 ]} - #{o[ 0 ]}" unless o[ 0 ].empty?
89
- end
90
- end
91
-
92
- #
93
- # Show Lines of Code
94
- #
95
- def loc
96
- return unless valid?
97
-
98
- generate
99
- total = 0
100
-
101
- @loc.each do |k, v|
102
- puts "\n #{k} Lines of Code".yellow
103
- total += v[ :lines ]
104
- formatted = Gloo::Utils::Format.number( v[ :lines ] )
105
- puts " ** #{formatted} in #{v[ :files ].count} #{k} files ** "
106
-
107
- puts "\n Busy #{k} files:".yellow
108
- files = v[ :files ].sort! { |a, b| a[ :lines ] <=> b[ :lines ] }
109
- files.reverse!
110
- files[ 0..12 ].each do |f|
111
- puts " #{f[ :lines ]} - #{f[ :file ]}"
112
- end
113
- end
114
-
115
- formatted = Gloo::Utils::Format.number( total )
116
- puts "\n #{formatted} Total Lines of Code".white
117
- end
118
-
119
- # ---------------------------------------------------------------------
120
- # Private Functions
121
- # ---------------------------------------------------------------------
122
-
123
- #
124
- # Setup counters for lines of code by file type.
125
- def setup_loc( types )
126
- @loc = {}
127
-
128
- types.split( ' ' ).each do |t|
129
- @loc[ t ] = { lines: 0, files: [] }
130
- end
131
- end
132
-
133
- #
134
- # Generate stat data unless we've already done so.
135
- #
136
- def generate
137
- return if @folders
138
-
139
- $log.debug 'Generating...'
140
- @folders = []
141
- @types = {}
142
- @file_cnt = 0
143
- @dir_cnt = 0
144
-
145
- generate_for Pathname.new( @dir )
146
- end
147
-
148
- #
149
- # Generate data for the given path.
150
- # NOTE: this is a recursive function.
151
- # It traverses all sub-direcctories.
152
- #
153
- def generate_for( path )
154
- return if @skip.include?( File.basename( path ) )
155
-
156
- cnt = 0
157
- path.children.each do |f|
158
- if f.directory?
159
- @dir_cnt += 1
160
- generate_for( f )
161
- else
162
- @file_cnt += 1
163
- cnt += 1
164
- handle_file( f )
165
- inc_type( File.extname( f ) )
166
- end
167
- end
168
- @folders << { name: path, cnt: cnt }
169
- end
170
-
171
- #
172
- # Increment the file count.
173
- #
174
- def inc_type( type )
175
- if @types[ type ]
176
- @types[ type ] += 1
177
- else
178
- @types[ type ] = 1
179
- end
180
- end
181
-
182
- #
183
- # Consider code file types.
184
- #
185
- def handle_file( file )
186
- ext = File.extname( file )
187
- return unless ext
188
-
189
- ext = ext[ 1..-1 ]
190
- return unless @loc.key?( ext )
191
-
192
- lines = count_lines( file )
193
- @loc[ ext ][ :lines ] += lines
194
- @loc[ ext ][ :files ] << { lines: lines, file: file }
195
- end
196
-
197
- #
198
- # Count lines of code in file.
199
- def count_lines( file )
200
- return `wc -l #{file}`.split.first.to_i
201
- end
202
-
203
- end
204
- end
205
- end