gloo 0.3.0 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/.DS_Store +0 -0
  3. data/.rubocop.yml +73 -0
  4. data/Gemfile +2 -2
  5. data/Gemfile.lock +86 -83
  6. data/Rakefile +7 -6
  7. data/bin/console +4 -4
  8. data/gloo.gemspec +22 -18
  9. data/lib/gloo.rb +6 -6
  10. data/lib/gloo/app/args.rb +30 -31
  11. data/lib/gloo/app/engine.rb +80 -30
  12. data/lib/gloo/app/help.rb +17 -11
  13. data/lib/gloo/app/info.rb +3 -3
  14. data/lib/gloo/app/log.rb +17 -17
  15. data/lib/gloo/app/mode.rb +4 -4
  16. data/lib/gloo/app/settings.rb +51 -41
  17. data/lib/gloo/convert/string_to_datetime.rb +21 -0
  18. data/lib/gloo/convert/string_to_decimal.rb +20 -0
  19. data/lib/gloo/convert/string_to_integer.rb +20 -0
  20. data/lib/gloo/core/baseo.rb +7 -7
  21. data/lib/gloo/core/dictionary.rb +30 -27
  22. data/lib/gloo/core/error.rb +50 -0
  23. data/lib/gloo/core/event_manager.rb +17 -23
  24. data/lib/gloo/core/factory.rb +149 -39
  25. data/lib/gloo/core/gloo_system.rb +121 -54
  26. data/lib/gloo/core/heap.rb +15 -13
  27. data/lib/gloo/core/it.rb +5 -5
  28. data/lib/gloo/core/literal.rb +7 -7
  29. data/lib/gloo/core/obj.rb +138 -79
  30. data/lib/gloo/core/obj_finder.rb +9 -14
  31. data/lib/gloo/core/op.rb +8 -8
  32. data/lib/gloo/core/parser.rb +27 -26
  33. data/lib/gloo/core/pn.rb +68 -52
  34. data/lib/gloo/core/script.rb +7 -7
  35. data/lib/gloo/core/tokens.rb +39 -41
  36. data/lib/gloo/core/verb.rb +30 -19
  37. data/lib/gloo/exec/dispatch.rb +30 -0
  38. data/lib/gloo/exec/runner.rb +43 -0
  39. data/lib/gloo/expr/expression.rb +36 -43
  40. data/lib/gloo/expr/l_boolean.rb +7 -6
  41. data/lib/gloo/expr/l_decimal.rb +34 -0
  42. data/lib/gloo/expr/l_integer.rb +5 -4
  43. data/lib/gloo/expr/l_string.rb +13 -15
  44. data/lib/gloo/expr/op_div.rb +5 -5
  45. data/lib/gloo/expr/op_minus.rb +5 -5
  46. data/lib/gloo/expr/op_mult.rb +5 -5
  47. data/lib/gloo/expr/op_plus.rb +7 -7
  48. data/lib/gloo/objs/basic/alias.rb +111 -0
  49. data/lib/gloo/objs/basic/boolean.rb +63 -38
  50. data/lib/gloo/objs/basic/container.rb +71 -12
  51. data/lib/gloo/objs/basic/decimal.rb +96 -0
  52. data/lib/gloo/objs/basic/integer.rb +45 -16
  53. data/lib/gloo/objs/basic/script.rb +62 -38
  54. data/lib/gloo/objs/basic/string.rb +47 -15
  55. data/lib/gloo/objs/basic/text.rb +69 -21
  56. data/lib/gloo/objs/basic/untyped.rb +35 -10
  57. data/lib/gloo/objs/cli/banner.rb +137 -0
  58. data/lib/gloo/objs/cli/bar.rb +141 -0
  59. data/lib/gloo/objs/cli/colorize.rb +54 -24
  60. data/lib/gloo/objs/cli/confirm.rb +63 -29
  61. data/lib/gloo/objs/cli/menu.rb +236 -0
  62. data/lib/gloo/objs/cli/menu_item.rb +128 -0
  63. data/lib/gloo/objs/cli/pastel.rb +120 -0
  64. data/lib/gloo/objs/cli/prompt.rb +73 -31
  65. data/lib/gloo/objs/cli/select.rb +153 -0
  66. data/lib/gloo/objs/ctrl/each.rb +128 -61
  67. data/lib/gloo/objs/ctrl/repeat.rb +129 -0
  68. data/lib/gloo/objs/data/markdown.rb +109 -0
  69. data/lib/gloo/objs/data/table.rb +168 -0
  70. data/lib/gloo/objs/dev/git.rb +98 -64
  71. data/lib/gloo/objs/dt/date.rb +72 -0
  72. data/lib/gloo/objs/dt/datetime.rb +84 -0
  73. data/lib/gloo/objs/dt/time.rb +72 -0
  74. data/lib/gloo/objs/ror/erb.rb +82 -41
  75. data/lib/gloo/objs/ror/eval.rb +73 -31
  76. data/lib/gloo/objs/snd/play.rb +71 -0
  77. data/lib/gloo/objs/snd/say.rb +120 -0
  78. data/lib/gloo/objs/system/file_handle.rb +129 -48
  79. data/lib/gloo/objs/system/system.rb +84 -38
  80. data/lib/gloo/objs/web/http_get.rb +103 -46
  81. data/lib/gloo/objs/web/http_post.rb +70 -44
  82. data/lib/gloo/objs/web/json.rb +155 -0
  83. data/lib/gloo/objs/web/slack.rb +89 -58
  84. data/lib/gloo/objs/web/teams.rb +88 -53
  85. data/lib/gloo/objs/web/uri.rb +160 -0
  86. data/lib/gloo/persist/file_loader.rb +95 -85
  87. data/lib/gloo/persist/file_saver.rb +12 -12
  88. data/lib/gloo/persist/file_storage.rb +15 -15
  89. data/lib/gloo/persist/line_splitter.rb +79 -0
  90. data/lib/gloo/persist/persist_man.rb +63 -39
  91. data/lib/gloo/utils/words.rb +2 -2
  92. data/lib/gloo/verbs/alert.rb +67 -16
  93. data/lib/gloo/verbs/beep.rb +70 -0
  94. data/lib/gloo/verbs/cls.rb +67 -0
  95. data/lib/gloo/verbs/context.rb +61 -21
  96. data/lib/gloo/verbs/create.rb +52 -21
  97. data/lib/gloo/verbs/help.rb +186 -27
  98. data/lib/gloo/verbs/if.rb +55 -21
  99. data/lib/gloo/verbs/list.rb +55 -24
  100. data/lib/gloo/verbs/load.rb +47 -12
  101. data/lib/gloo/verbs/move.rb +128 -0
  102. data/lib/gloo/verbs/put.rb +90 -34
  103. data/lib/gloo/verbs/quit.rb +43 -12
  104. data/lib/gloo/verbs/run.rb +63 -18
  105. data/lib/gloo/verbs/save.rb +45 -10
  106. data/lib/gloo/verbs/show.rb +56 -22
  107. data/lib/gloo/verbs/tell.rb +45 -13
  108. data/lib/gloo/verbs/unless.rb +56 -21
  109. data/lib/gloo/verbs/version.rb +42 -12
  110. data/lib/gloo/verbs/wait.rb +73 -0
  111. data/lib/run.rb +5 -5
  112. metadata +90 -12
@@ -7,33 +7,68 @@
7
7
  module Gloo
8
8
  module Verbs
9
9
  class Load < Gloo::Core::Verb
10
-
11
- KEYWORD = 'load'
12
- KEYWORD_SHORT = '<'
13
10
 
14
- #
11
+ KEYWORD = 'load'.freeze
12
+ KEYWORD_SHORT = '<'.freeze
13
+
14
+ #
15
15
  # Run the verb.
16
- #
16
+ #
17
17
  def run
18
- fn = @tokens.second
19
- $log.debug "Getting ready to load file: #{fn}"
18
+ fn = @tokens.second
19
+ $log.debug "Getting ready to load file: #{fn}"
20
20
  $engine.persist_man.load fn
21
21
  end
22
-
23
- #
22
+
23
+ #
24
24
  # Get the Verb's keyword.
25
- #
25
+ #
26
26
  def self.keyword
27
27
  return KEYWORD
28
28
  end
29
29
 
30
- #
30
+ #
31
31
  # Get the Verb's keyword shortcut.
32
- #
32
+ #
33
33
  def self.keyword_shortcut
34
34
  return KEYWORD_SHORT
35
35
  end
36
36
 
37
+ # ---------------------------------------------------------------------
38
+ # Help
39
+ # ---------------------------------------------------------------------
40
+
41
+ #
42
+ # Get help for this verb.
43
+ #
44
+ def self.help
45
+ return <<~TEXT
46
+ LOAD VERB
47
+ NAME: load
48
+ SHORTCUT: <
49
+
50
+ DESCRIPTION
51
+ Load an object file.
52
+ There are two ways to specify the file. Give either the full path and file name or use a relative path from the gloo project folder. For the latter, the extension is not needed. For the former, the
53
+ file extension is necessary.
54
+ Using * instead of a file name will load all gloo files in the folder.
55
+
56
+ SYNTAX
57
+ load <file_name>
58
+
59
+ PARAMETERS
60
+ file_name - Name of the object file that is to be loaded.
61
+
62
+ RESULT
63
+ Objects are loaded into the heap.
64
+ on_load scripts are run within the loaded objects.
65
+
66
+ ERRORS
67
+ If the file specified can't be found or can't be loaded,
68
+ an error condition will result.
69
+ TEXT
70
+ end
71
+
37
72
  end
38
73
  end
39
74
  end
@@ -0,0 +1,128 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # Move an object to a new parent.
5
+ #
6
+
7
+ module Gloo
8
+ module Verbs
9
+ class Move < Gloo::Core::Verb
10
+
11
+ KEYWORD = 'move'.freeze
12
+ KEYWORD_SHORT = 'mv'.freeze
13
+ TO = 'to'.freeze
14
+
15
+ #
16
+ # Run the verb.
17
+ #
18
+ def run
19
+ dst = lookup_dst
20
+ return if dst.nil?
21
+
22
+ o = lookup_obj
23
+ return unless o
24
+
25
+ o.parent.remove_child o
26
+ dst.add_child o
27
+ end
28
+
29
+ #
30
+ # Get the Verb's keyword.
31
+ #
32
+ def self.keyword
33
+ return KEYWORD
34
+ end
35
+
36
+ #
37
+ # Get the Verb's keyword shortcut.
38
+ #
39
+ def self.keyword_shortcut
40
+ return KEYWORD_SHORT
41
+ end
42
+
43
+ # ---------------------------------------------------------------------
44
+ # Helper functions
45
+ # ---------------------------------------------------------------------
46
+
47
+ #
48
+ # Lookup the object that we're moving.
49
+ #
50
+ def lookup_obj
51
+ arr = @tokens.before_token( TO )
52
+ if arr.count == 1
53
+ msg = 'object to move was not specified'
54
+ $log.error msg, nil, $engine
55
+ end
56
+
57
+ name = arr[ 1 ]
58
+ pn = Gloo::Core::Pn.new name
59
+ o = pn.resolve
60
+
61
+ unless o
62
+ msg = "could not find object to move: #{name}"
63
+ $log.error msg, nil, $engine
64
+ end
65
+
66
+ return o
67
+ end
68
+
69
+ #
70
+ # Lookup destination, the new parent object.
71
+ #
72
+ def lookup_dst
73
+ dst = @tokens.after_token( TO )
74
+ unless dst
75
+ msg = "'move' must include 'to' parent object"
76
+ $log.error msg, nil, $engine
77
+ return nil
78
+ end
79
+
80
+ pn = Gloo::Core::Pn.new dst
81
+ o = pn.resolve
82
+ unless o
83
+ msg = "could not resolve '#{dst}'"
84
+ $log.error msg, nil, $engine
85
+ return nil
86
+ end
87
+
88
+ return o
89
+ end
90
+
91
+ # ---------------------------------------------------------------------
92
+ # Help
93
+ # ---------------------------------------------------------------------
94
+
95
+ #
96
+ # Get help for this verb.
97
+ #
98
+ def self.help
99
+ return <<~TEXT
100
+ MOVE VERB
101
+ NAME: move
102
+ SHORTCUT: mv
103
+
104
+ DESCRIPTION
105
+ Move an object to a new parent.
106
+
107
+ SYNTAX
108
+ move <path.to.object> to <new.parent>
109
+
110
+ PARAMETERS
111
+ path.to.object - The object that we want to move.
112
+ new.parent - The new location for the object.
113
+
114
+ RESULT
115
+ The object will now be in the new location.
116
+
117
+ ERRORS
118
+ The <path.to.object> is not specified.
119
+ The <path.to.object> cannot be resolved.
120
+ The <new.parent> is not specified.
121
+ The <new.parent> cannot be resolved.
122
+ The 'to' keyword is missing.
123
+ TEXT
124
+ end
125
+
126
+ end
127
+ end
128
+ end
@@ -7,56 +7,112 @@
7
7
  module Gloo
8
8
  module Verbs
9
9
  class Put < Gloo::Core::Verb
10
-
11
- KEYWORD = 'put'
12
- KEYWORD_SHORT = 'p'
13
- INTO = 'into'
14
-
15
- #
10
+
11
+ KEYWORD = 'put'.freeze
12
+ KEYWORD_SHORT = 'p'.freeze
13
+ INTO = 'into'.freeze
14
+
15
+ #
16
16
  # Run the verb.
17
- #
17
+ #
18
18
  def run
19
- value = @tokens.before_token( INTO )
20
- if value.nil?
21
- $log.error "'put' must include 'into'"
22
- end
23
- if value.count > 1
24
- # The first token is the verb, so we drop it.
25
- value = value[1..-1]
26
- end
19
+ value = fetch_value_tokens
20
+ return if value.nil?
21
+
22
+ target = lookup_target
23
+ return if target.nil?
27
24
 
28
- target = @tokens.after_token( INTO )
29
- if target.nil?
30
- $log.error "'put' must include 'into' target"
31
- end
32
25
  pn = Gloo::Core::Pn.new target
33
26
  o = pn.resolve
34
- if o.nil?
35
- $log.error "could not find target of put: #{target}"
36
- else
37
- if value.count > 0
38
- expr = Gloo::Expr::Expression.new( value )
39
- result = expr.evaluate
40
- o.set_value result
41
- $engine.heap.it.set_to result
42
- end
43
- end
27
+ if o.nil?
28
+ msg = "could not find target of put: #{target}"
29
+ $log.error msg, nil, $engine
30
+ elsif value.count.positive?
31
+ expr = Gloo::Expr::Expression.new( value )
32
+ result = expr.evaluate
33
+ o.set_value result
34
+ $engine.heap.it.set_to result
35
+ end
44
36
  end
45
-
46
- #
37
+
38
+ #
47
39
  # Get the Verb's keyword.
48
- #
40
+ #
49
41
  def self.keyword
50
42
  return KEYWORD
51
43
  end
52
44
 
53
- #
45
+ #
54
46
  # Get the Verb's keyword shortcut.
55
- #
47
+ #
56
48
  def self.keyword_shortcut
57
49
  return KEYWORD_SHORT
58
50
  end
59
51
 
52
+ # ---------------------------------------------------------------------
53
+ # Helper functions
54
+ # ---------------------------------------------------------------------
55
+
56
+ # Get the value that is being put.
57
+ def fetch_value_tokens
58
+ value = @tokens.before_token( INTO )
59
+ if value.nil?
60
+ msg = "'put' must include 'into'"
61
+ $log.error msg, nil, $engine
62
+ return nil
63
+ end
64
+
65
+ if value.count > 1
66
+ # The first token is the verb, so we drop it.
67
+ value = value[ 1..-1 ]
68
+ end
69
+ return value
70
+ end
71
+
72
+ # Lookup the target of the put command.
73
+ def lookup_target
74
+ target = @tokens.after_token( INTO )
75
+ return target if target
76
+
77
+ msg = "'put' must include 'into' target"
78
+ $log.error msg, nil, $engine
79
+ return nil
80
+ end
81
+
82
+ # ---------------------------------------------------------------------
83
+ # Help
84
+ # ---------------------------------------------------------------------
85
+
86
+ #
87
+ # Get help for this verb.
88
+ #
89
+ def self.help
90
+ return <<~TEXT
91
+ PUT VERB
92
+ NAME: put
93
+ SHORTCUT: p
94
+
95
+ DESCRIPTION
96
+ Put a value into an object.
97
+ The value is the result of an expression.
98
+
99
+ SYNTAX
100
+ put <expression> into <dst.path>
101
+
102
+ PARAMETERS
103
+ expression - The expression that is evaluated.
104
+ dst.path - The path to the destination object.
105
+
106
+ RESULT
107
+ <it> will contain the result of the evaluation.
108
+
109
+ ERRORS
110
+ The destination is not specified.
111
+ The destination cannot be resolved.
112
+ The 'into' keyword is missing.
113
+ TEXT
114
+ end
115
+
60
116
  end
61
117
  end
62
118
  end
@@ -7,34 +7,65 @@
7
7
  module Gloo
8
8
  module Verbs
9
9
  class Quit < Gloo::Core::Verb
10
-
11
- KEYWORD = 'quit'
12
- KEYWORD_SHORT = 'q'
13
10
 
14
- #
11
+ KEYWORD = 'quit'.freeze
12
+ KEYWORD_SHORT = 'q'.freeze
13
+
14
+ #
15
15
  # Run the verb.
16
- #
16
+ #
17
17
  # We'll mark the application as not running and let the
18
18
  # engine stop gracefully next time through the loop.
19
- #
19
+ #
20
20
  def run
21
21
  $engine.stop_running
22
22
  end
23
-
24
- #
23
+
24
+ #
25
25
  # Get the Verb's keyword.
26
- #
26
+ #
27
27
  def self.keyword
28
28
  return KEYWORD
29
29
  end
30
-
31
- #
30
+
31
+ #
32
32
  # Get the Verb's keyword shortcut.
33
- #
33
+ #
34
34
  def self.keyword_shortcut
35
35
  return KEYWORD_SHORT
36
36
  end
37
37
 
38
+ # ---------------------------------------------------------------------
39
+ # Help
40
+ # ---------------------------------------------------------------------
41
+
42
+ #
43
+ # Get help for this verb.
44
+ #
45
+ def self.help
46
+ return <<~TEXT
47
+ QUIT VERB
48
+ NAME: quit
49
+ SHORTCUT: q
50
+
51
+ DESCRIPTION
52
+ Stop running the gloo application.
53
+ Cleanup and shutdown.
54
+
55
+ SYNTAX
56
+ quit
57
+
58
+ PARAMETERS
59
+ None
60
+
61
+ RESULT
62
+ None
63
+
64
+ ERRORS
65
+ None
66
+ TEXT
67
+ end
68
+
38
69
  end
39
70
  end
40
71
  end
@@ -8,39 +8,84 @@
8
8
  module Gloo
9
9
  module Verbs
10
10
  class Run < Gloo::Core::Verb
11
-
12
- KEYWORD = 'run'
13
- KEYWORD_SHORT = 'r'
14
-
15
- #
11
+
12
+ KEYWORD = 'run'.freeze
13
+ KEYWORD_SHORT = 'r'.freeze
14
+ EVALUATE_RUN = '~>'.freeze
15
+
16
+ #
16
17
  # Run the verb.
17
- #
18
+ #
18
19
  def run
19
- name = @tokens.second
20
- pn = Gloo::Core::Pn.new name
21
- o = pn.resolve
22
-
23
- if o
24
- o.send_message 'run'
20
+ if @tokens.second == EVALUATE_RUN
21
+ run_expression
25
22
  else
26
- $log.error "Could not send message to object. Bad path: #{name}"
23
+ run_script
27
24
  end
28
25
  end
29
-
30
- #
26
+
27
+ #
28
+ # Run a script specified by pathname
29
+ #
30
+ def run_script
31
+ Gloo::Exec::Runner.run @tokens.second
32
+ end
33
+
34
+ #
35
+ # Evaluate an expression and run that.
36
+ #
37
+ def run_expression
38
+ return unless @tokens.token_count > 2
39
+
40
+ expr = Gloo::Expr::Expression.new( @tokens.params[ 1..-1 ] )
41
+ $engine.parser.run expr.evaluate
42
+ end
43
+
44
+ #
31
45
  # Get the Verb's keyword.
32
- #
46
+ #
33
47
  def self.keyword
34
48
  return KEYWORD
35
49
  end
36
50
 
37
- #
51
+ #
38
52
  # Get the Verb's keyword shortcut.
39
- #
53
+ #
40
54
  def self.keyword_shortcut
41
55
  return KEYWORD_SHORT
42
56
  end
43
57
 
58
+ # ---------------------------------------------------------------------
59
+ # Help
60
+ # ---------------------------------------------------------------------
61
+
62
+ #
63
+ # Get help for this verb.
64
+ #
65
+ def self.help
66
+ return <<~TEXT
67
+ RUN VERB
68
+ NAME: run
69
+ SHORTCUT: r
70
+
71
+ DESCRIPTION
72
+ Run a script or other object.
73
+ This is the same as sending a 'run' message to the object.
74
+
75
+ SYNTAX
76
+ run <path.to.object>
77
+
78
+ PARAMETERS
79
+ path.to.object - Reference to the object which will be run.
80
+
81
+ RESULT
82
+ The result depends on the object that is run.
83
+
84
+ ERRORS
85
+ The errors depend on the object that is run.
86
+ TEXT
87
+ end
88
+
44
89
  end
45
90
  end
46
91
  end