gloo-lang 0.9.2 → 0.9.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (178) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/gloo-lang.gemspec +1 -0
  4. data/lib/VERSION +1 -1
  5. data/lib/dependencies.rb +2 -2
  6. data/lib/gloo-lang.rb +1 -5
  7. data/lib/gloo_lang/app/args.rb +111 -0
  8. data/lib/gloo_lang/app/engine.rb +200 -0
  9. data/lib/gloo_lang/app/help.rb +117 -0
  10. data/lib/gloo_lang/app/info.rb +34 -0
  11. data/lib/gloo_lang/app/log.rb +81 -0
  12. data/lib/gloo_lang/app/mode.rb +27 -0
  13. data/lib/gloo_lang/app/platform.rb +75 -0
  14. data/lib/gloo_lang/app/settings.rb +185 -0
  15. data/lib/gloo_lang/convert/converter.rb +35 -0
  16. data/lib/gloo_lang/convert/string_to_datetime.rb +21 -0
  17. data/lib/gloo_lang/convert/string_to_decimal.rb +20 -0
  18. data/lib/gloo_lang/convert/string_to_integer.rb +20 -0
  19. data/lib/gloo_lang/core/baseo.rb +30 -0
  20. data/lib/gloo_lang/core/dictionary.rb +181 -0
  21. data/lib/gloo_lang/core/error.rb +61 -0
  22. data/lib/gloo_lang/core/event_manager.rb +44 -0
  23. data/lib/gloo_lang/core/factory.rb +210 -0
  24. data/lib/gloo_lang/core/gloo_system.rb +266 -0
  25. data/lib/gloo_lang/core/heap.rb +52 -0
  26. data/lib/gloo_lang/core/here.rb +36 -0
  27. data/lib/gloo_lang/core/it.rb +36 -0
  28. data/lib/gloo_lang/core/literal.rb +30 -0
  29. data/lib/gloo_lang/core/obj.rb +303 -0
  30. data/lib/gloo_lang/core/obj_finder.rb +30 -0
  31. data/lib/gloo_lang/core/op.rb +40 -0
  32. data/lib/gloo_lang/core/parser.rb +59 -0
  33. data/lib/gloo_lang/core/pn.rb +188 -0
  34. data/lib/gloo_lang/core/tokens.rb +165 -0
  35. data/lib/gloo_lang/core/verb.rb +86 -0
  36. data/lib/gloo_lang/exec/action.rb +48 -0
  37. data/lib/gloo_lang/exec/dispatch.rb +40 -0
  38. data/lib/gloo_lang/exec/exec_env.rb +74 -0
  39. data/lib/gloo_lang/exec/runner.rb +45 -0
  40. data/lib/gloo_lang/exec/script.rb +49 -0
  41. data/lib/gloo_lang/exec/stack.rb +78 -0
  42. data/lib/gloo_lang/expr/expression.rb +118 -0
  43. data/lib/gloo_lang/expr/l_boolean.rb +36 -0
  44. data/lib/gloo_lang/expr/l_decimal.rb +39 -0
  45. data/lib/gloo_lang/expr/l_integer.rb +37 -0
  46. data/lib/gloo_lang/expr/l_string.rb +58 -0
  47. data/lib/gloo_lang/expr/op_div.rb +22 -0
  48. data/lib/gloo_lang/expr/op_minus.rb +22 -0
  49. data/lib/gloo_lang/expr/op_mult.rb +22 -0
  50. data/lib/gloo_lang/expr/op_plus.rb +24 -0
  51. data/lib/gloo_lang/help/app/application.txt +22 -0
  52. data/lib/gloo_lang/help/app/configuration.txt +7 -0
  53. data/lib/gloo_lang/help/app/default_help.txt +14 -0
  54. data/lib/gloo_lang/help/app/logging.txt +16 -0
  55. data/lib/gloo_lang/help/core/color.txt +31 -0
  56. data/lib/gloo_lang/help/core/error.txt +33 -0
  57. data/lib/gloo_lang/help/core/events.txt +21 -0
  58. data/lib/gloo_lang/help/core/gloo_system.txt +57 -0
  59. data/lib/gloo_lang/help/core/here.txt +30 -0
  60. data/lib/gloo_lang/help/core/it.txt +23 -0
  61. data/lib/gloo_lang/help/core/ops.txt +16 -0
  62. data/lib/gloo_lang/help/core/pathname.txt +29 -0
  63. data/lib/gloo_lang/help/objs/basic/alias.txt +36 -0
  64. data/lib/gloo_lang/help/objs/basic/boolean.txt +28 -0
  65. data/lib/gloo_lang/help/objs/basic/container.txt +33 -0
  66. data/lib/gloo_lang/help/objs/basic/decimal.txt +28 -0
  67. data/lib/gloo_lang/help/objs/basic/integer.txt +27 -0
  68. data/lib/gloo_lang/help/objs/basic/script.txt +29 -0
  69. data/lib/gloo_lang/help/objs/basic/string.txt +28 -0
  70. data/lib/gloo_lang/help/objs/basic/text.txt +27 -0
  71. data/lib/gloo_lang/help/objs/basic/untyped.txt +22 -0
  72. data/lib/gloo_lang/help/objs/cli/banner.txt +49 -0
  73. data/lib/gloo_lang/help/objs/cli/bar.txt +37 -0
  74. data/lib/gloo_lang/help/objs/cli/colorize.txt +33 -0
  75. data/lib/gloo_lang/help/objs/cli/confirm.txt +26 -0
  76. data/lib/gloo_lang/help/objs/cli/menu.txt +44 -0
  77. data/lib/gloo_lang/help/objs/cli/menu_item.txt +26 -0
  78. data/lib/gloo_lang/help/objs/cli/pastel.txt +43 -0
  79. data/lib/gloo_lang/help/objs/cli/prompt.txt +27 -0
  80. data/lib/gloo_lang/help/objs/cli/select.txt +34 -0
  81. data/lib/gloo_lang/help/objs/ctrl/each.txt +48 -0
  82. data/lib/gloo_lang/help/objs/ctrl/repeat.txt +38 -0
  83. data/lib/gloo_lang/help/objs/data/markdown.txt +25 -0
  84. data/lib/gloo_lang/help/objs/data/mysql.txt +40 -0
  85. data/lib/gloo_lang/help/objs/data/query.txt +37 -0
  86. data/lib/gloo_lang/help/objs/data/sqlite.txt +26 -0
  87. data/lib/gloo_lang/help/objs/data/table.txt +46 -0
  88. data/lib/gloo_lang/help/objs/dev/git_repo.txt +36 -0
  89. data/lib/gloo_lang/help/objs/dev/stats.txt +36 -0
  90. data/lib/gloo_lang/help/objs/dt/date.txt +23 -0
  91. data/lib/gloo_lang/help/objs/dt/datetime.txt +24 -0
  92. data/lib/gloo_lang/help/objs/dt/time.txt +23 -0
  93. data/lib/gloo_lang/help/objs/ror/erb.txt +37 -0
  94. data/lib/gloo_lang/help/objs/ror/eval.txt +24 -0
  95. data/lib/gloo_lang/help/objs/snd/play.txt +23 -0
  96. data/lib/gloo_lang/help/objs/snd/say.txt +28 -0
  97. data/lib/gloo_lang/help/objs/system/file.txt +48 -0
  98. data/lib/gloo_lang/help/objs/system/ssh_exec.txt +30 -0
  99. data/lib/gloo_lang/help/objs/system/system.txt +32 -0
  100. data/lib/gloo_lang/help/objs/web/http_get.txt +35 -0
  101. data/lib/gloo_lang/help/objs/web/http_post.txt +34 -0
  102. data/lib/gloo_lang/help/objs/web/json.txt +34 -0
  103. data/lib/gloo_lang/help/objs/web/slack.txt +33 -0
  104. data/lib/gloo_lang/help/objs/web/teams.txt +30 -0
  105. data/lib/gloo_lang/help/objs/web/uri.txt +38 -0
  106. data/lib/gloo_lang/help/verbs/alert.txt +33 -0
  107. data/lib/gloo_lang/help/verbs/beep.txt +25 -0
  108. data/lib/gloo_lang/help/verbs/cls.txt +24 -0
  109. data/lib/gloo_lang/help/verbs/context.txt +43 -0
  110. data/lib/gloo_lang/help/verbs/create.txt +33 -0
  111. data/lib/gloo_lang/help/verbs/execute.txt +27 -0
  112. data/lib/gloo_lang/help/verbs/help.txt +34 -0
  113. data/lib/gloo_lang/help/verbs/if.txt +37 -0
  114. data/lib/gloo_lang/help/verbs/list.txt +34 -0
  115. data/lib/gloo_lang/help/verbs/load.txt +38 -0
  116. data/lib/gloo_lang/help/verbs/move.txt +42 -0
  117. data/lib/gloo_lang/help/verbs/put.txt +38 -0
  118. data/lib/gloo_lang/help/verbs/quit.txt +25 -0
  119. data/lib/gloo_lang/help/verbs/run.txt +41 -0
  120. data/lib/gloo_lang/help/verbs/save.txt +26 -0
  121. data/lib/gloo_lang/help/verbs/show.txt +30 -0
  122. data/lib/gloo_lang/help/verbs/tell.txt +34 -0
  123. data/lib/gloo_lang/help/verbs/unless.txt +38 -0
  124. data/lib/gloo_lang/help/verbs/version.txt +32 -0
  125. data/lib/gloo_lang/help/verbs/wait.txt +29 -0
  126. data/lib/gloo_lang/objs/basic/alias.rb +78 -0
  127. data/lib/gloo_lang/objs/basic/boolean.rb +120 -0
  128. data/lib/gloo_lang/objs/basic/container.rb +65 -0
  129. data/lib/gloo_lang/objs/basic/decimal.rb +76 -0
  130. data/lib/gloo_lang/objs/basic/integer.rb +73 -0
  131. data/lib/gloo_lang/objs/basic/script.rb +99 -0
  132. data/lib/gloo_lang/objs/basic/string.rb +77 -0
  133. data/lib/gloo_lang/objs/basic/text.rb +79 -0
  134. data/lib/gloo_lang/objs/basic/untyped.rb +41 -0
  135. data/lib/gloo_lang/objs/ctrl/each.rb +279 -0
  136. data/lib/gloo_lang/objs/ctrl/repeat.rb +108 -0
  137. data/lib/gloo_lang/objs/data/markdown.rb +79 -0
  138. data/lib/gloo_lang/objs/data/mysql.rb +192 -0
  139. data/lib/gloo_lang/objs/data/query.rb +176 -0
  140. data/lib/gloo_lang/objs/data/sqlite.rb +159 -0
  141. data/lib/gloo_lang/objs/data/table.rb +112 -0
  142. data/lib/gloo_lang/objs/dt/date.rb +50 -0
  143. data/lib/gloo_lang/objs/dt/datetime.rb +62 -0
  144. data/lib/gloo_lang/objs/dt/time.rb +50 -0
  145. data/lib/gloo_lang/objs/ror/erb.rb +116 -0
  146. data/lib/gloo_lang/objs/ror/eval.rb +107 -0
  147. data/lib/gloo_lang/objs/web/http_get.rb +159 -0
  148. data/lib/gloo_lang/objs/web/http_post.rb +183 -0
  149. data/lib/gloo_lang/objs/web/json.rb +135 -0
  150. data/lib/gloo_lang/objs/web/slack.rb +130 -0
  151. data/lib/gloo_lang/objs/web/teams.rb +117 -0
  152. data/lib/gloo_lang/objs/web/uri.rb +148 -0
  153. data/lib/gloo_lang/persist/file_loader.rb +191 -0
  154. data/lib/gloo_lang/persist/file_saver.rb +49 -0
  155. data/lib/gloo_lang/persist/file_storage.rb +45 -0
  156. data/lib/gloo_lang/persist/line_splitter.rb +81 -0
  157. data/lib/gloo_lang/persist/persist_man.rb +120 -0
  158. data/lib/gloo_lang/utils/format.rb +21 -0
  159. data/lib/gloo_lang/utils/stats.rb +205 -0
  160. data/lib/gloo_lang/utils/words.rb +19 -0
  161. data/lib/gloo_lang/verbs/context.rb +62 -0
  162. data/lib/gloo_lang/verbs/create.rb +68 -0
  163. data/lib/gloo_lang/verbs/execute.rb +56 -0
  164. data/lib/gloo_lang/verbs/help.rb +264 -0
  165. data/lib/gloo_lang/verbs/if.rb +92 -0
  166. data/lib/gloo_lang/verbs/list.rb +98 -0
  167. data/lib/gloo_lang/verbs/load.rb +45 -0
  168. data/lib/gloo_lang/verbs/move.rb +89 -0
  169. data/lib/gloo_lang/verbs/put.rb +94 -0
  170. data/lib/gloo_lang/verbs/quit.rb +40 -0
  171. data/lib/gloo_lang/verbs/run.rb +75 -0
  172. data/lib/gloo_lang/verbs/save.rb +39 -0
  173. data/lib/gloo_lang/verbs/show.rb +64 -0
  174. data/lib/gloo_lang/verbs/tell.rb +79 -0
  175. data/lib/gloo_lang/verbs/unless.rb +92 -0
  176. data/lib/gloo_lang/verbs/version.rb +37 -0
  177. data/lib/gloo_lang/verbs/wait.rb +42 -0
  178. metadata +192 -2
@@ -0,0 +1,176 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # A SQL database query.
5
+ # Relies on a database connection object.
6
+ #
7
+
8
+ module GlooLang
9
+ module Objs
10
+ class Query < GlooLang::Core::Obj
11
+
12
+ KEYWORD = 'query'.freeze
13
+ KEYWORD_SHORT = 'sql'.freeze
14
+
15
+ DB = 'database'.freeze
16
+ SQL = 'sql'.freeze
17
+ RESULT = 'result'.freeze
18
+ PARAMS = 'params'.freeze
19
+
20
+ DB_MISSING_ERR = 'The database connection is missing!'.freeze
21
+
22
+ #
23
+ # The name of the object type.
24
+ #
25
+ def self.typename
26
+ return KEYWORD
27
+ end
28
+
29
+ #
30
+ # The short name of the object type.
31
+ #
32
+ def self.short_typename
33
+ return KEYWORD_SHORT
34
+ end
35
+
36
+ # ---------------------------------------------------------------------
37
+ # Children
38
+ # ---------------------------------------------------------------------
39
+
40
+ #
41
+ # Does this object have children to add when an object
42
+ # is created in interactive mode?
43
+ # This does not apply during obj load, etc.
44
+ #
45
+ def add_children_on_create?
46
+ return true
47
+ end
48
+
49
+ #
50
+ # Add children to this object.
51
+ # This is used by containers to add children needed
52
+ # for default configurations.
53
+ #
54
+ def add_default_children
55
+ fac = $engine.factory
56
+ fac.create_alias DB, nil, self
57
+ fac.create_string SQL, nil, self
58
+ fac.create_can RESULT, self
59
+ end
60
+
61
+ # ---------------------------------------------------------------------
62
+ # Messages
63
+ # ---------------------------------------------------------------------
64
+
65
+ #
66
+ # Get a list of message names that this object receives.
67
+ #
68
+ def self.messages
69
+ return super + [ 'run' ]
70
+ end
71
+
72
+ #
73
+ # SSH to the host and execute the command, then update result.
74
+ #
75
+ def msg_run
76
+ db = db_obj
77
+ unless db
78
+ $engine.err DB_MISSING_ERR
79
+ return
80
+ end
81
+
82
+ result = db.query( sql_value, param_array )
83
+ process_result result
84
+ end
85
+
86
+ # ---------------------------------------------------------------------
87
+ # Private functions
88
+ # ---------------------------------------------------------------------
89
+
90
+ private
91
+
92
+ #
93
+ # Get the database connection.
94
+ #
95
+ def db_obj
96
+ o = find_child DB
97
+ return GlooLang::Objs::Alias.resolve_alias( o )
98
+ end
99
+
100
+ #
101
+ # Get the SQL from the child object.
102
+ # Returns nil if there is none.
103
+ #
104
+ def sql_value
105
+ o = find_child SQL
106
+ return nil unless o
107
+
108
+ return o.value
109
+ end
110
+
111
+ #
112
+ # Do something with the result of the SQL Query call.
113
+ # If there's a result container, we'll create objects in it.
114
+ # If not, we'll just show the output in the console.
115
+ #
116
+ def process_result( data )
117
+ r = find_child RESULT
118
+ if r
119
+ update_result_contaier data
120
+ else
121
+ show_result data
122
+ end
123
+ end
124
+
125
+ #
126
+ # Get the arrya of parameters.
127
+ # If there is no PARAM container of if it is empty,
128
+ # we'll return a nil value.
129
+ #
130
+ def param_array
131
+ o = find_child PARAMS
132
+ return nil unless o
133
+
134
+ return nil if o.child_count.zero?
135
+
136
+ params = []
137
+ o.children.each do |p|
138
+ params << p.value
139
+ end
140
+
141
+ return params
142
+ end
143
+
144
+ #
145
+ # Show the result of the query in the console.
146
+ #
147
+ def show_result( data )
148
+ return if data.nil?
149
+
150
+ data.each_with_index do |row, i|
151
+ # Show header for the first row
152
+ puts row.map { |k, _| k }.join( " \t " ).white if i.zero?
153
+
154
+ # Show the row data
155
+ puts row.map { |_, v| v }.join( " \t " )
156
+ end
157
+ end
158
+
159
+ #
160
+ # Update the result container with the data from the query.
161
+ #
162
+ def update_result_contaier( data )
163
+ r = find_child RESULT
164
+ r = GlooLang::Objs::Alias.resolve_alias( r )
165
+ data.each_with_index do |row, i|
166
+ can = r.find_add_child( i.to_s, 'can' )
167
+ row.each do |k, v|
168
+ o = can.find_add_child( k, 'untyped' )
169
+ o.set_value v
170
+ end
171
+ end
172
+ end
173
+
174
+ end
175
+ end
176
+ end
@@ -0,0 +1,159 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # A Sqlite3 database connection.
5
+ #
6
+ # https://www.rubydoc.info/gems/sqlite3/1.3.11
7
+ # https://www.devdungeon.com/content/ruby-sqlite-tutorial
8
+ #
9
+ # db.results_as_hash = true
10
+ # Set results to return as Hash object.
11
+ # This is slower but offers a huge convenience.
12
+ # Consider turning it off for high performance situations.
13
+ # Each row will have the column name as the hash key.
14
+ #
15
+ # # Alternatively, to only get one row and discard the rest,
16
+ # replace `db.query()` with `db.get_first_value()`.
17
+ #
18
+ require 'sqlite3'
19
+
20
+ module GlooLang
21
+ module Objs
22
+ class Sqlite < GlooLang::Core::Obj
23
+
24
+ KEYWORD = 'sqlite'.freeze
25
+ KEYWORD_SHORT = 'sqlite'.freeze
26
+
27
+ DB = 'database'.freeze
28
+ DEFAULT_DB = 'test.db'.freeze
29
+
30
+ DB_REQUIRED_ERR = 'The database name is required!'.freeze
31
+ DB_NOT_FOUND_ERR = 'The database file was not found!'.freeze
32
+
33
+ #
34
+ # The name of the object type.
35
+ #
36
+ def self.typename
37
+ return KEYWORD
38
+ end
39
+
40
+ #
41
+ # The short name of the object type.
42
+ #
43
+ def self.short_typename
44
+ return KEYWORD_SHORT
45
+ end
46
+
47
+ # ---------------------------------------------------------------------
48
+ # Children
49
+ # ---------------------------------------------------------------------
50
+
51
+ #
52
+ # Does this object have children to add when an object
53
+ # is created in interactive mode?
54
+ # This does not apply during obj load, etc.
55
+ #
56
+ def add_children_on_create?
57
+ return true
58
+ end
59
+
60
+ #
61
+ # Add children to this object.
62
+ # This is used by containers to add children needed
63
+ # for default configurations.
64
+ #
65
+ def add_default_children
66
+ fac = $engine.factory
67
+ fac.create_string DB, DEFAULT_DB, self
68
+ end
69
+
70
+ # ---------------------------------------------------------------------
71
+ # Messages
72
+ # ---------------------------------------------------------------------
73
+
74
+ #
75
+ # Get a list of message names that this object receives.
76
+ #
77
+ def self.messages
78
+ return super + [ 'verify' ]
79
+ end
80
+
81
+ #
82
+ # Verify access to the Sqlite database specified.
83
+ #
84
+ def msg_verify
85
+ name = db_value
86
+ if name.empty?
87
+ $engine.err DB_REQUIRED_ERR
88
+ $engine.heap.it.set_to false
89
+ return
90
+ end
91
+
92
+ unless File.exist? name
93
+ $engine.err DB_NOT_FOUND_ERR
94
+ $engine.heap.it.set_to false
95
+ return
96
+ end
97
+
98
+ return unless connects?
99
+
100
+ $engine.heap.it.set_to true
101
+ end
102
+
103
+ # ---------------------------------------------------------------------
104
+ # DB functions (all database connections)
105
+ # ---------------------------------------------------------------------
106
+
107
+ #
108
+ # Open a connection and execute the SQL statement.
109
+ # Return the resulting data.
110
+ #
111
+ def query( sql, params = nil )
112
+ name = db_value
113
+ unless name
114
+ $engine.err DB_REQUIRED_ERR
115
+ return
116
+ end
117
+
118
+ db = SQLite3::Database.open name
119
+ db.results_as_hash = true
120
+ return db.query( sql, params )
121
+ end
122
+
123
+ # ---------------------------------------------------------------------
124
+ # Private functions
125
+ # ---------------------------------------------------------------------
126
+
127
+ private
128
+
129
+ #
130
+ # Get the Database file from the child object.
131
+ # Returns nil if there is none.
132
+ #
133
+ def db_value
134
+ o = find_child DB
135
+ return nil unless o
136
+
137
+ return o.value
138
+ end
139
+
140
+ #
141
+ # Try the connection and make sure it works.
142
+ # Returns true if we can connect and do a query.
143
+ #
144
+ def connects?
145
+ begin
146
+ db = SQLite3::Database.open db_value
147
+ sql = "SELECT COUNT(name) FROM sqlite_master WHERE type='table'"
148
+ db.get_first_value sql
149
+ rescue => e
150
+ $engine.err e.message
151
+ $engine.heap.it.set_to false
152
+ return false
153
+ end
154
+ return true
155
+ end
156
+
157
+ end
158
+ end
159
+ end
@@ -0,0 +1,112 @@
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
+
8
+ module GlooLang
9
+ module Objs
10
+ class Table < GlooLang::Core::Obj
11
+
12
+ KEYWORD = 'table'.freeze
13
+ KEYWORD_SHORT = 'tbl'.freeze
14
+ HEADERS = 'headers'.freeze
15
+ DATA = 'data'.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 list of headers.
33
+ # Returns nil if there is none.
34
+ #
35
+ def headers
36
+ o = find_child HEADERS
37
+ return [] unless o
38
+
39
+ return o.children.map( &:value )
40
+ end
41
+
42
+ #
43
+ # Get the list of column names.
44
+ # Returns nil if there is none.
45
+ #
46
+ def columns
47
+ o = find_child HEADERS
48
+ return [] unless o
49
+
50
+ return o.children.map( &:name )
51
+ end
52
+
53
+ #
54
+ # Get the list of data elements.
55
+ #
56
+ def data
57
+ o = find_child DATA
58
+ return [] unless o
59
+
60
+ o = GlooLang::Objs::Alias.resolve_alias( o )
61
+ cols = self.columns
62
+ return o.children.map do |e|
63
+ cols.map { |h| e.find_child( h ).value }
64
+ end
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_can HEADERS, self
88
+ fac.create_can DATA, self
89
+ end
90
+
91
+ # ---------------------------------------------------------------------
92
+ # Messages
93
+ # ---------------------------------------------------------------------
94
+
95
+ #
96
+ # Get a list of message names that this object receives.
97
+ #
98
+ def self.messages
99
+ return super + %w[show]
100
+ end
101
+
102
+ #
103
+ # Show the table in the CLI.
104
+ #
105
+ def msg_show
106
+ title = self.value
107
+ $engine.platform.show_table headers, data, title
108
+ end
109
+
110
+ end
111
+ end
112
+ 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