gloo-lang 0.9.0 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (193) hide show
  1. checksums.yaml +4 -4
  2. data/lib/VERSION +1 -1
  3. data/lib/dependencies.rb +2 -2
  4. data/lib/{gloo_lang.rb → gloo-lang.rb} +7 -9
  5. data/lib/gloo_lang/app/args.rb +112 -0
  6. data/lib/gloo_lang/app/engine.rb +230 -0
  7. data/lib/gloo_lang/app/help.rb +156 -0
  8. data/lib/gloo_lang/app/log.rb +81 -0
  9. data/lib/gloo_lang/app/mode.rb +27 -0
  10. data/lib/gloo_lang/app/settings.rb +186 -0
  11. data/lib/gloo_lang/convert/converter.rb +35 -0
  12. data/lib/gloo_lang/convert/string_to_datetime.rb +21 -0
  13. data/lib/gloo_lang/convert/string_to_decimal.rb +20 -0
  14. data/lib/gloo_lang/convert/string_to_integer.rb +20 -0
  15. data/lib/gloo_lang/core/baseo.rb +30 -0
  16. data/lib/gloo_lang/core/dictionary.rb +181 -0
  17. data/lib/gloo_lang/core/error.rb +61 -0
  18. data/lib/gloo_lang/core/event_manager.rb +44 -0
  19. data/lib/gloo_lang/core/factory.rb +210 -0
  20. data/lib/gloo_lang/core/gloo_system.rb +266 -0
  21. data/lib/gloo_lang/core/heap.rb +52 -0
  22. data/lib/gloo_lang/core/here.rb +36 -0
  23. data/lib/gloo_lang/core/it.rb +36 -0
  24. data/lib/gloo_lang/core/literal.rb +30 -0
  25. data/lib/gloo_lang/core/obj.rb +303 -0
  26. data/lib/gloo_lang/core/obj_finder.rb +30 -0
  27. data/lib/gloo_lang/core/op.rb +40 -0
  28. data/lib/gloo_lang/core/parser.rb +59 -0
  29. data/lib/gloo_lang/core/pn.rb +188 -0
  30. data/lib/gloo_lang/core/tokens.rb +165 -0
  31. data/lib/gloo_lang/core/verb.rb +86 -0
  32. data/lib/gloo_lang/exec/action.rb +48 -0
  33. data/lib/gloo_lang/exec/dispatch.rb +40 -0
  34. data/lib/gloo_lang/exec/exec_env.rb +74 -0
  35. data/lib/gloo_lang/exec/runner.rb +45 -0
  36. data/lib/gloo_lang/exec/script.rb +49 -0
  37. data/lib/gloo_lang/exec/stack.rb +78 -0
  38. data/lib/gloo_lang/expr/expression.rb +118 -0
  39. data/lib/gloo_lang/expr/l_boolean.rb +36 -0
  40. data/lib/gloo_lang/expr/l_decimal.rb +39 -0
  41. data/lib/gloo_lang/expr/l_integer.rb +37 -0
  42. data/lib/gloo_lang/expr/l_string.rb +58 -0
  43. data/lib/gloo_lang/expr/op_div.rb +22 -0
  44. data/lib/gloo_lang/expr/op_minus.rb +22 -0
  45. data/lib/gloo_lang/expr/op_mult.rb +22 -0
  46. data/lib/gloo_lang/expr/op_plus.rb +24 -0
  47. data/lib/gloo_lang/help/app/application.txt +22 -0
  48. data/lib/gloo_lang/help/app/configuration.txt +7 -0
  49. data/lib/gloo_lang/help/app/default_help.txt +14 -0
  50. data/lib/gloo_lang/help/app/logging.txt +16 -0
  51. data/lib/gloo_lang/help/core/color.txt +31 -0
  52. data/lib/gloo_lang/help/core/error.txt +33 -0
  53. data/lib/gloo_lang/help/core/events.txt +21 -0
  54. data/lib/gloo_lang/help/core/gloo_system.txt +57 -0
  55. data/lib/gloo_lang/help/core/here.txt +30 -0
  56. data/lib/gloo_lang/help/core/it.txt +23 -0
  57. data/lib/gloo_lang/help/core/ops.txt +16 -0
  58. data/lib/gloo_lang/help/core/pathname.txt +29 -0
  59. data/lib/gloo_lang/help/objs/basic/alias.txt +36 -0
  60. data/lib/gloo_lang/help/objs/basic/boolean.txt +28 -0
  61. data/lib/gloo_lang/help/objs/basic/container.txt +33 -0
  62. data/lib/gloo_lang/help/objs/basic/decimal.txt +28 -0
  63. data/lib/gloo_lang/help/objs/basic/integer.txt +27 -0
  64. data/lib/gloo_lang/help/objs/basic/script.txt +29 -0
  65. data/lib/gloo_lang/help/objs/basic/string.txt +28 -0
  66. data/lib/gloo_lang/help/objs/basic/text.txt +27 -0
  67. data/lib/gloo_lang/help/objs/basic/untyped.txt +22 -0
  68. data/lib/gloo_lang/help/objs/cli/banner.txt +49 -0
  69. data/lib/gloo_lang/help/objs/cli/bar.txt +37 -0
  70. data/lib/gloo_lang/help/objs/cli/colorize.txt +33 -0
  71. data/lib/gloo_lang/help/objs/cli/confirm.txt +26 -0
  72. data/lib/gloo_lang/help/objs/cli/menu.txt +44 -0
  73. data/lib/gloo_lang/help/objs/cli/menu_item.txt +26 -0
  74. data/lib/gloo_lang/help/objs/cli/pastel.txt +43 -0
  75. data/lib/gloo_lang/help/objs/cli/prompt.txt +27 -0
  76. data/lib/gloo_lang/help/objs/cli/select.txt +34 -0
  77. data/lib/gloo_lang/help/objs/ctrl/each.txt +48 -0
  78. data/lib/gloo_lang/help/objs/ctrl/repeat.txt +38 -0
  79. data/lib/gloo_lang/help/objs/data/markdown.txt +25 -0
  80. data/lib/gloo_lang/help/objs/data/mysql.txt +40 -0
  81. data/lib/gloo_lang/help/objs/data/query.txt +37 -0
  82. data/lib/gloo_lang/help/objs/data/sqlite.txt +26 -0
  83. data/lib/gloo_lang/help/objs/data/table.txt +46 -0
  84. data/lib/gloo_lang/help/objs/dev/git_repo.txt +36 -0
  85. data/lib/gloo_lang/help/objs/dev/stats.txt +36 -0
  86. data/lib/gloo_lang/help/objs/dt/date.txt +23 -0
  87. data/lib/gloo_lang/help/objs/dt/datetime.txt +24 -0
  88. data/lib/gloo_lang/help/objs/dt/time.txt +23 -0
  89. data/lib/gloo_lang/help/objs/ror/erb.txt +37 -0
  90. data/lib/gloo_lang/help/objs/ror/eval.txt +24 -0
  91. data/lib/gloo_lang/help/objs/snd/play.txt +23 -0
  92. data/lib/gloo_lang/help/objs/snd/say.txt +28 -0
  93. data/lib/gloo_lang/help/objs/system/file.txt +48 -0
  94. data/lib/gloo_lang/help/objs/system/ssh_exec.txt +30 -0
  95. data/lib/gloo_lang/help/objs/system/system.txt +32 -0
  96. data/lib/gloo_lang/help/objs/web/http_get.txt +35 -0
  97. data/lib/gloo_lang/help/objs/web/http_post.txt +34 -0
  98. data/lib/gloo_lang/help/objs/web/json.txt +34 -0
  99. data/lib/gloo_lang/help/objs/web/slack.txt +33 -0
  100. data/lib/gloo_lang/help/objs/web/teams.txt +30 -0
  101. data/lib/gloo_lang/help/objs/web/uri.txt +38 -0
  102. data/lib/gloo_lang/help/verbs/alert.txt +33 -0
  103. data/lib/gloo_lang/help/verbs/beep.txt +25 -0
  104. data/lib/gloo_lang/help/verbs/cls.txt +24 -0
  105. data/lib/gloo_lang/help/verbs/context.txt +43 -0
  106. data/lib/gloo_lang/help/verbs/create.txt +33 -0
  107. data/lib/gloo_lang/help/verbs/execute.txt +27 -0
  108. data/lib/gloo_lang/help/verbs/help.txt +34 -0
  109. data/lib/gloo_lang/help/verbs/if.txt +37 -0
  110. data/lib/gloo_lang/help/verbs/list.txt +34 -0
  111. data/lib/gloo_lang/help/verbs/load.txt +38 -0
  112. data/lib/gloo_lang/help/verbs/move.txt +42 -0
  113. data/lib/gloo_lang/help/verbs/put.txt +38 -0
  114. data/lib/gloo_lang/help/verbs/quit.txt +25 -0
  115. data/lib/gloo_lang/help/verbs/run.txt +41 -0
  116. data/lib/gloo_lang/help/verbs/save.txt +26 -0
  117. data/lib/gloo_lang/help/verbs/show.txt +30 -0
  118. data/lib/gloo_lang/help/verbs/tell.txt +34 -0
  119. data/lib/gloo_lang/help/verbs/unless.txt +38 -0
  120. data/lib/gloo_lang/help/verbs/version.txt +32 -0
  121. data/lib/gloo_lang/help/verbs/wait.txt +29 -0
  122. data/lib/gloo_lang/objs/basic/alias.rb +78 -0
  123. data/lib/gloo_lang/objs/basic/boolean.rb +120 -0
  124. data/lib/gloo_lang/objs/basic/container.rb +76 -0
  125. data/lib/gloo_lang/objs/basic/decimal.rb +76 -0
  126. data/lib/gloo_lang/objs/basic/integer.rb +73 -0
  127. data/lib/gloo_lang/objs/basic/script.rb +99 -0
  128. data/lib/gloo_lang/objs/basic/string.rb +77 -0
  129. data/lib/gloo_lang/objs/basic/text.rb +87 -0
  130. data/lib/gloo_lang/objs/basic/untyped.rb +41 -0
  131. data/lib/gloo_lang/objs/cli/banner.rb +108 -0
  132. data/lib/gloo_lang/objs/cli/bar.rb +133 -0
  133. data/lib/gloo_lang/objs/cli/colorize.rb +73 -0
  134. data/lib/gloo_lang/objs/cli/confirm.rb +96 -0
  135. data/lib/gloo_lang/objs/cli/menu.rb +206 -0
  136. data/lib/gloo_lang/objs/cli/menu_item.rb +95 -0
  137. data/lib/gloo_lang/objs/cli/pastel.rb +97 -0
  138. data/lib/gloo_lang/objs/cli/prompt.rb +110 -0
  139. data/lib/gloo_lang/objs/cli/select.rb +126 -0
  140. data/lib/gloo_lang/objs/ctrl/each.rb +279 -0
  141. data/lib/gloo_lang/objs/ctrl/repeat.rb +108 -0
  142. data/lib/gloo_lang/objs/data/markdown.rb +84 -0
  143. data/lib/gloo_lang/objs/data/mysql.rb +192 -0
  144. data/lib/gloo_lang/objs/data/query.rb +176 -0
  145. data/lib/gloo_lang/objs/data/sqlite.rb +159 -0
  146. data/lib/gloo_lang/objs/data/table.rb +140 -0
  147. data/lib/gloo_lang/objs/dev/git.rb +140 -0
  148. data/lib/gloo_lang/objs/dev/stats.rb +120 -0
  149. data/lib/gloo_lang/objs/dt/date.rb +50 -0
  150. data/lib/gloo_lang/objs/dt/datetime.rb +62 -0
  151. data/lib/gloo_lang/objs/dt/time.rb +50 -0
  152. data/lib/gloo_lang/objs/ror/erb.rb +116 -0
  153. data/lib/gloo_lang/objs/ror/eval.rb +107 -0
  154. data/lib/gloo_lang/objs/snd/play.rb +48 -0
  155. data/lib/gloo_lang/objs/snd/say.rb +98 -0
  156. data/lib/gloo_lang/objs/system/file_handle.rb +138 -0
  157. data/lib/gloo_lang/objs/system/ssh_exec.rb +126 -0
  158. data/lib/gloo_lang/objs/system/system.rb +136 -0
  159. data/lib/gloo_lang/objs/web/http_get.rb +159 -0
  160. data/lib/gloo_lang/objs/web/http_post.rb +183 -0
  161. data/lib/gloo_lang/objs/web/json.rb +135 -0
  162. data/lib/gloo_lang/objs/web/slack.rb +130 -0
  163. data/lib/gloo_lang/objs/web/teams.rb +117 -0
  164. data/lib/gloo_lang/objs/web/uri.rb +148 -0
  165. data/lib/gloo_lang/persist/file_loader.rb +191 -0
  166. data/lib/gloo_lang/persist/file_saver.rb +49 -0
  167. data/lib/gloo_lang/persist/file_storage.rb +45 -0
  168. data/lib/gloo_lang/persist/line_splitter.rb +81 -0
  169. data/lib/gloo_lang/persist/persist_man.rb +120 -0
  170. data/lib/gloo_lang/utils/format.rb +21 -0
  171. data/lib/gloo_lang/utils/stats.rb +205 -0
  172. data/lib/gloo_lang/utils/words.rb +19 -0
  173. data/lib/gloo_lang/verbs/alert.rb +79 -0
  174. data/lib/gloo_lang/verbs/beep.rb +40 -0
  175. data/lib/gloo_lang/verbs/cls.rb +37 -0
  176. data/lib/gloo_lang/verbs/context.rb +62 -0
  177. data/lib/gloo_lang/verbs/create.rb +68 -0
  178. data/lib/gloo_lang/verbs/execute.rb +56 -0
  179. data/lib/gloo_lang/verbs/help.rb +264 -0
  180. data/lib/gloo_lang/verbs/if.rb +92 -0
  181. data/lib/gloo_lang/verbs/list.rb +98 -0
  182. data/lib/gloo_lang/verbs/load.rb +45 -0
  183. data/lib/gloo_lang/verbs/move.rb +89 -0
  184. data/lib/gloo_lang/verbs/put.rb +94 -0
  185. data/lib/gloo_lang/verbs/quit.rb +40 -0
  186. data/lib/gloo_lang/verbs/run.rb +75 -0
  187. data/lib/gloo_lang/verbs/save.rb +39 -0
  188. data/lib/gloo_lang/verbs/show.rb +64 -0
  189. data/lib/gloo_lang/verbs/tell.rb +79 -0
  190. data/lib/gloo_lang/verbs/unless.rb +92 -0
  191. data/lib/gloo_lang/verbs/version.rb +37 -0
  192. data/lib/gloo_lang/verbs/wait.rb +42 -0
  193. metadata +191 -3
@@ -0,0 +1,140 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # A data table.
5
+ # The table container headers and data.
6
+ #
7
+ require 'tty-table'
8
+ require 'pastel'
9
+
10
+ module GlooLang
11
+ module Objs
12
+ class Table < GlooLang::Core::Obj
13
+
14
+ KEYWORD = 'table'.freeze
15
+ KEYWORD_SHORT = 'tbl'.freeze
16
+ HEADERS = 'headers'.freeze
17
+ DATA = 'data'.freeze
18
+
19
+ #
20
+ # The name of the object type.
21
+ #
22
+ def self.typename
23
+ return KEYWORD
24
+ end
25
+
26
+ #
27
+ # The short name of the object type.
28
+ #
29
+ def self.short_typename
30
+ return KEYWORD_SHORT
31
+ end
32
+
33
+ #
34
+ # Get the list of headers.
35
+ # Returns nil if there is none.
36
+ #
37
+ def headers
38
+ o = find_child HEADERS
39
+ return [] unless o
40
+
41
+ return o.children.map( &:value )
42
+ end
43
+
44
+ #
45
+ # Get the list of column names.
46
+ # Returns nil if there is none.
47
+ #
48
+ def columns
49
+ o = find_child HEADERS
50
+ return [] unless o
51
+
52
+ return o.children.map( &:name )
53
+ end
54
+
55
+ #
56
+ # Get the list of data elements.
57
+ #
58
+ def data
59
+ o = find_child DATA
60
+ return [] unless o
61
+
62
+ o = GlooLang::Objs::Alias.resolve_alias( o )
63
+ cols = self.columns
64
+ return o.children.map do |e|
65
+ cols.map { |h| e.find_child( h ).value }
66
+ end
67
+ end
68
+
69
+ # ---------------------------------------------------------------------
70
+ # Children
71
+ # ---------------------------------------------------------------------
72
+
73
+ #
74
+ # Does this object have children to add when an object
75
+ # is created in interactive mode?
76
+ # This does not apply during obj load, etc.
77
+ #
78
+ def add_children_on_create?
79
+ return true
80
+ end
81
+
82
+ #
83
+ # Add children to this object.
84
+ # This is used by containers to add children needed
85
+ # for default configurations.
86
+ #
87
+ def add_default_children
88
+ fac = $engine.factory
89
+ fac.create_can HEADERS, self
90
+ fac.create_can DATA, self
91
+ end
92
+
93
+ # ---------------------------------------------------------------------
94
+ # Messages
95
+ # ---------------------------------------------------------------------
96
+
97
+ #
98
+ # Get a list of message names that this object receives.
99
+ #
100
+ def self.messages
101
+ return super + %w[show]
102
+ end
103
+
104
+ #
105
+ # Show the table in the CLI.
106
+ #
107
+ def msg_show
108
+ title = self.value
109
+ GlooLang::Objs::Table.show headers, data, title
110
+ end
111
+
112
+ # ---------------------------------------------------------------------
113
+ # Static table helper
114
+ # ---------------------------------------------------------------------
115
+
116
+ #
117
+ # Show the given table data.
118
+ #
119
+ def self.show( headers, data, title = nil )
120
+ pastel = ::Pastel.new
121
+ table = TTY::Table.new headers, data
122
+ pad = [ 0, 1, 0, 1 ]
123
+ rendered = table.render( :ascii, indent: 2, padding: pad ) do |r|
124
+ r.border.style = :blue
125
+ r.filter = proc do |val, row_index, _col_index|
126
+ # col_index % 2 == 1 ? pastel.red.on_green(val) : val
127
+ if row_index.zero?
128
+ pastel.blue( val )
129
+ else
130
+ row_index.odd? ? pastel.white( val ) : pastel.yellow( val )
131
+ end
132
+ end
133
+ end
134
+ puts "\n#{title.white}"
135
+ puts "#{rendered}\n\n"
136
+ end
137
+
138
+ end
139
+ end
140
+ end
@@ -0,0 +1,140 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # An object that interacts with a git repository
5
+ #
6
+
7
+ module GlooLang
8
+ module Objs
9
+ class Git < GlooLang::Core::Obj
10
+
11
+ KEYWORD = 'git_repo'.freeze
12
+ KEYWORD_SHORT = 'git'.freeze
13
+
14
+ #
15
+ # The name of the object type.
16
+ #
17
+ def self.typename
18
+ return KEYWORD
19
+ end
20
+
21
+ #
22
+ # The short name of the object type.
23
+ #
24
+ def self.short_typename
25
+ return KEYWORD_SHORT
26
+ end
27
+
28
+ #
29
+ # Get the path to the git repo (locally).
30
+ #
31
+ def path_value
32
+ return value
33
+ end
34
+
35
+ # ---------------------------------------------------------------------
36
+ # Messages
37
+ # ---------------------------------------------------------------------
38
+
39
+ #
40
+ # Get a list of message names that this object receives.
41
+ #
42
+ def self.messages
43
+ actions = %w[validate commit get_branch review]
44
+ changes = %w[check_changes get_changes]
45
+ return super + changes + actions
46
+ end
47
+
48
+ #
49
+ # Get the current working branch.
50
+ #
51
+ def msg_get_branch
52
+ branch = ''
53
+ path = path_value
54
+ if path_is_dir?( path )
55
+ branch = `cd #{path}; git rev-parse --abbrev-ref HEAD`
56
+ branch = branch.strip
57
+ end
58
+
59
+ $engine.heap.it.set_to branch
60
+ end
61
+
62
+ #
63
+ # Review pending changes.
64
+ #
65
+ def msg_review
66
+ $log.debug 'Reviewing pending changes'
67
+ cmd = "cd #{path_value}; git diff"
68
+ $log.debug cmd
69
+ system cmd
70
+ end
71
+
72
+ #
73
+ # Commit pending changes.
74
+ #
75
+ def msg_commit
76
+ msg = 'Commit'
77
+ path = path_value
78
+ if path_is_dir?( path )
79
+ if @params&.token_count&.positive?
80
+ expr = GlooLang::Expr::Expression.new( @params.tokens )
81
+ msg = expr.evaluate
82
+ end
83
+ branch = `cd #{path}; git rev-parse --abbrev-ref HEAD`
84
+ branch = branch.strip
85
+ add = 'git add .'
86
+ cmt = 'git commit -m '
87
+ psh = 'git push origin '
88
+ `cd #{path};#{add};#{cmt}"#{msg}";#{psh}#{branch}`
89
+ end
90
+ $engine.heap.it.set_to msg
91
+ end
92
+
93
+ #
94
+ # Get the pending changes.
95
+ #
96
+ def msg_get_changes
97
+ path = path_value
98
+ result = `cd #{path}; git status -s` if path_is_dir?( path )
99
+ result ||= ''
100
+ $engine.heap.it.set_to result
101
+ end
102
+
103
+ #
104
+ # Is the given path non nil and is it a directory?
105
+ #
106
+ def path_is_dir?( path )
107
+ return path && File.directory?( path )
108
+ end
109
+
110
+ #
111
+ # Check to see if the repo has changes.
112
+ #
113
+ def msg_check_changes
114
+ result = false
115
+ path = path_value
116
+ if path_is_dir?( path )
117
+ data = `cd #{path}; git status -s`
118
+ result = true unless data.strip.empty?
119
+ end
120
+
121
+ $engine.heap.it.set_to result
122
+ end
123
+
124
+ #
125
+ # Check to make sure this is a valide git repo.
126
+ #
127
+ def msg_validate
128
+ result = false
129
+ path = path_value
130
+ if path_is_dir?( path )
131
+ pn = File.join( path, '.git' )
132
+ result = File.exist? pn
133
+ end
134
+
135
+ $engine.heap.it.set_to result
136
+ end
137
+
138
+ end
139
+ end
140
+ end
@@ -0,0 +1,120 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # Get statistics about a development project.
5
+ #
6
+
7
+ module GlooLang
8
+ module Objs
9
+ class Stats < GlooLang::Core::Obj
10
+
11
+ KEYWORD = 'stats'.freeze
12
+ KEYWORD_SHORT = 'stat'.freeze
13
+ FOLDER = 'folder'.freeze
14
+ TYPES = 'types'.freeze
15
+ SKIP = 'skip'.freeze
16
+
17
+ #
18
+ # The name of the object type.
19
+ #
20
+ def self.typename
21
+ return KEYWORD
22
+ end
23
+
24
+ #
25
+ # The short name of the object type.
26
+ #
27
+ def self.short_typename
28
+ return KEYWORD_SHORT
29
+ end
30
+
31
+ #
32
+ # Get the path to the git repo (locally).
33
+ #
34
+ def path_value
35
+ o = find_child FOLDER
36
+ return o ? o.value : nil
37
+ end
38
+
39
+ #
40
+ # The code file types to count.
41
+ #
42
+ def types_value
43
+ o = find_child TYPES
44
+ return o ? o.value : ''
45
+ end
46
+
47
+ #
48
+ # Get the list of files and folders to skip.
49
+ #
50
+ def skip_list
51
+ o = find_child SKIP
52
+ val = o ? o.value : ''
53
+ return val.split ' '
54
+ end
55
+
56
+ # ---------------------------------------------------------------------
57
+ # Children
58
+ # ---------------------------------------------------------------------
59
+
60
+ #
61
+ # Does this object have children to add when an object
62
+ # is created in interactive mode?
63
+ # This does not apply during obj load, etc.
64
+ #
65
+ def add_children_on_create?
66
+ return true
67
+ end
68
+
69
+ #
70
+ # Add children to this object.
71
+ # This is used by containers to add children needed
72
+ # for default configurations.
73
+ #
74
+ def add_default_children
75
+ fac = $engine.factory
76
+ fac.create_file FOLDER, '', self
77
+ fac.create_string TYPES, '', self
78
+ fac.create_can SKIP, self
79
+ end
80
+
81
+ # ---------------------------------------------------------------------
82
+ # Messages
83
+ # ---------------------------------------------------------------------
84
+
85
+ #
86
+ # Get a list of message names that this object receives.
87
+ #
88
+ def self.messages
89
+ all = %w[show_all]
90
+ more = %w[show_busy_folders show_types]
91
+ return super + all + more
92
+ end
93
+
94
+ #
95
+ # Show all project stats.
96
+ #
97
+ def msg_show_all
98
+ o = GlooLang::Utils::Stats.new( path_value, types_value, skip_list )
99
+ o.show_all
100
+ end
101
+
102
+ #
103
+ # Show file types.
104
+ #
105
+ def msg_show_types
106
+ o = GlooLang::Utils::Stats.new( path_value, types_value, skip_list )
107
+ o.file_types
108
+ end
109
+
110
+ #
111
+ # Show busy folders: those with the most files.
112
+ #
113
+ def msg_show_busy_folders
114
+ o = GlooLang::Utils::Stats.new( path_value, types_value, skip_list )
115
+ o.busy_folders
116
+ end
117
+
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,50 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # A Date object (does not include a time).
5
+ #
6
+
7
+ module GlooLang
8
+ module Objs
9
+ class Date < GlooLang::Core::Obj
10
+
11
+ KEYWORD = 'date'.freeze
12
+ KEYWORD_SHORT = 'date'.freeze
13
+
14
+ #
15
+ # The name of the object type.
16
+ #
17
+ def self.typename
18
+ return KEYWORD
19
+ end
20
+
21
+ #
22
+ # The short name of the object type.
23
+ #
24
+ def self.short_typename
25
+ return KEYWORD_SHORT
26
+ end
27
+
28
+ # ---------------------------------------------------------------------
29
+ # Messages
30
+ # ---------------------------------------------------------------------
31
+
32
+ #
33
+ # Get a list of message names that this object receives.
34
+ #
35
+ def self.messages
36
+ return super + %w[now]
37
+ end
38
+
39
+ #
40
+ # Set to the current date.
41
+ #
42
+ def msg_now
43
+ t = DateTime.now.strftime( '%Y.%m.%d' )
44
+ self.value = t
45
+ $engine.heap.it.set_to t
46
+ end
47
+
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,62 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # A Date and Time object.
5
+ #
6
+
7
+ module GlooLang
8
+ module Objs
9
+ class Datetime < GlooLang::Core::Obj
10
+
11
+ KEYWORD = 'datetime'.freeze
12
+ KEYWORD_SHORT = 'dt'.freeze
13
+
14
+ #
15
+ # The name of the object type.
16
+ #
17
+ def self.typename
18
+ return KEYWORD
19
+ end
20
+
21
+ #
22
+ # The short name of the object type.
23
+ #
24
+ def self.short_typename
25
+ return KEYWORD_SHORT
26
+ end
27
+
28
+ #
29
+ # Set the value with any necessary type conversions.
30
+ #
31
+ def set_value( new_value )
32
+ unless new_value.is_a? DateTime
33
+ self.value = $engine.converter.convert( new_value, 'DateTime', nil )
34
+ return
35
+ end
36
+
37
+ self.value = new_value
38
+ end
39
+
40
+ # ---------------------------------------------------------------------
41
+ # Messages
42
+ # ---------------------------------------------------------------------
43
+
44
+ #
45
+ # Get a list of message names that this object receives.
46
+ #
47
+ def self.messages
48
+ return super + %w[now]
49
+ end
50
+
51
+ #
52
+ # Set to the current date and time.
53
+ #
54
+ def msg_now
55
+ t = DateTime.now.strftime( '%Y.%m.%d %I:%M:%S %P' )
56
+ self.value = t
57
+ $engine.heap.it.set_to t
58
+ end
59
+
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,50 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # A Time object (does not include a date).
5
+ #
6
+
7
+ module GlooLang
8
+ module Objs
9
+ class Time < GlooLang::Core::Obj
10
+
11
+ KEYWORD = 'time'.freeze
12
+ KEYWORD_SHORT = 'time'.freeze
13
+
14
+ #
15
+ # The name of the object type.
16
+ #
17
+ def self.typename
18
+ return KEYWORD
19
+ end
20
+
21
+ #
22
+ # The short name of the object type.
23
+ #
24
+ def self.short_typename
25
+ return KEYWORD_SHORT
26
+ end
27
+
28
+ # ---------------------------------------------------------------------
29
+ # Messages
30
+ # ---------------------------------------------------------------------
31
+
32
+ #
33
+ # Get a list of message names that this object receives.
34
+ #
35
+ def self.messages
36
+ return super + %w[now]
37
+ end
38
+
39
+ #
40
+ # Set to the current time.
41
+ #
42
+ def msg_now
43
+ t = DateTime.now.strftime( '%I:%M:%S %P' )
44
+ self.value = t
45
+ $engine.heap.it.set_to t
46
+ end
47
+
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,116 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # An object that evaluate a ruby statement.
5
+ #
6
+ require 'erb'
7
+
8
+ module GlooLang
9
+ module Objs
10
+ class Erb < GlooLang::Core::Obj
11
+
12
+ KEYWORD = 'erb'.freeze
13
+ KEYWORD_SHORT = 'erb'.freeze
14
+ TEMPLATE = 'template'.freeze
15
+ PARAMS = 'params'.freeze
16
+ RESULT = 'result'.freeze
17
+
18
+ #
19
+ # The name of the object type.
20
+ #
21
+ def self.typename
22
+ return KEYWORD
23
+ end
24
+
25
+ #
26
+ # The short name of the object type.
27
+ #
28
+ def self.short_typename
29
+ return KEYWORD_SHORT
30
+ end
31
+
32
+ #
33
+ # Get the ERB template.
34
+ #
35
+ def template_value
36
+ tmpl = find_child TEMPLATE
37
+ return nil unless tmpl
38
+
39
+ return tmpl.value
40
+ end
41
+
42
+ #
43
+ # Set the result of the ERB template conversion.
44
+ #
45
+ def set_result( data )
46
+ r = find_child RESULT
47
+ return nil unless r
48
+
49
+ r.set_value data
50
+ end
51
+
52
+ #
53
+ # Get a hash with parameters for the ERB render.
54
+ #
55
+ def param_hash
56
+ h = {}
57
+
58
+ body = find_child PARAMS
59
+ body.children.each do |child|
60
+ child = GlooLang::Objs::Alias.resolve_alias( child )
61
+ h[ child.name ] = child.value
62
+ end
63
+
64
+ return h
65
+ end
66
+
67
+ # ---------------------------------------------------------------------
68
+ # Children
69
+ # ---------------------------------------------------------------------
70
+
71
+ #
72
+ # Does this object have children to add when an object
73
+ # is created in interactive mode?
74
+ # This does not apply during obj load, etc.
75
+ #
76
+ def add_children_on_create?
77
+ return true
78
+ end
79
+
80
+ #
81
+ # Add children to this object.
82
+ # This is used by containers to add children needed
83
+ # for default configurations.
84
+ #
85
+ def add_default_children
86
+ fac = $engine.factory
87
+ fac.create_text TEMPLATE, '', self
88
+ fac.create_can PARAMS, self
89
+ fac.create_text RESULT, '', self
90
+ end
91
+
92
+ # ---------------------------------------------------------------------
93
+ # Messages
94
+ # ---------------------------------------------------------------------
95
+
96
+ #
97
+ # Get a list of message names that this object receives.
98
+ #
99
+ def self.messages
100
+ return super + [ 'run' ]
101
+ end
102
+
103
+ #
104
+ # Run the ERB template conversion.
105
+ #
106
+ def msg_run
107
+ tmpl = template_value
108
+ return unless tmpl
109
+
110
+ render = ERB.new( tmpl )
111
+ set_result render.result_with_hash( param_hash )
112
+ end
113
+
114
+ end
115
+ end
116
+ end