gloo 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +73 -0
  3. data/Gemfile +2 -2
  4. data/Gemfile.lock +3 -3
  5. data/Rakefile +6 -6
  6. data/bin/console +4 -4
  7. data/gloo.gemspec +19 -18
  8. data/lib/gloo.rb +6 -6
  9. data/lib/gloo/app/args.rb +30 -31
  10. data/lib/gloo/app/engine.rb +33 -28
  11. data/lib/gloo/app/help.rb +17 -11
  12. data/lib/gloo/app/info.rb +3 -3
  13. data/lib/gloo/app/log.rb +17 -17
  14. data/lib/gloo/app/mode.rb +4 -4
  15. data/lib/gloo/app/settings.rb +43 -40
  16. data/lib/gloo/core/baseo.rb +7 -7
  17. data/lib/gloo/core/dictionary.rb +30 -27
  18. data/lib/gloo/core/error.rb +50 -0
  19. data/lib/gloo/core/event_manager.rb +17 -19
  20. data/lib/gloo/core/factory.rb +92 -39
  21. data/lib/gloo/core/gloo_system.rb +49 -54
  22. data/lib/gloo/core/heap.rb +15 -13
  23. data/lib/gloo/core/it.rb +5 -5
  24. data/lib/gloo/core/literal.rb +7 -7
  25. data/lib/gloo/core/obj.rb +89 -79
  26. data/lib/gloo/core/obj_finder.rb +9 -14
  27. data/lib/gloo/core/op.rb +8 -8
  28. data/lib/gloo/core/parser.rb +25 -26
  29. data/lib/gloo/core/pn.rb +65 -50
  30. data/lib/gloo/core/runner.rb +26 -0
  31. data/lib/gloo/core/script.rb +7 -7
  32. data/lib/gloo/core/tokens.rb +39 -41
  33. data/lib/gloo/core/verb.rb +30 -19
  34. data/lib/gloo/expr/expression.rb +35 -43
  35. data/lib/gloo/expr/l_boolean.rb +7 -6
  36. data/lib/gloo/expr/l_integer.rb +5 -4
  37. data/lib/gloo/expr/l_string.rb +13 -15
  38. data/lib/gloo/expr/op_div.rb +3 -5
  39. data/lib/gloo/expr/op_minus.rb +3 -5
  40. data/lib/gloo/expr/op_mult.rb +3 -5
  41. data/lib/gloo/expr/op_plus.rb +5 -7
  42. data/lib/gloo/objs/basic/boolean.rb +63 -38
  43. data/lib/gloo/objs/basic/container.rb +40 -12
  44. data/lib/gloo/objs/basic/integer.rb +40 -16
  45. data/lib/gloo/objs/basic/script.rb +62 -38
  46. data/lib/gloo/objs/basic/string.rb +39 -15
  47. data/lib/gloo/objs/basic/text.rb +43 -20
  48. data/lib/gloo/objs/basic/untyped.rb +35 -10
  49. data/lib/gloo/objs/cli/colorize.rb +53 -23
  50. data/lib/gloo/objs/cli/confirm.rb +63 -29
  51. data/lib/gloo/objs/cli/prompt.rb +63 -29
  52. data/lib/gloo/objs/ctrl/each.rb +98 -60
  53. data/lib/gloo/objs/dev/git.rb +98 -64
  54. data/lib/gloo/objs/ror/erb.rb +81 -41
  55. data/lib/gloo/objs/ror/eval.rb +73 -31
  56. data/lib/gloo/objs/snd/play.rb +71 -0
  57. data/lib/gloo/objs/snd/say.rb +120 -0
  58. data/lib/gloo/objs/system/file_handle.rb +80 -48
  59. data/lib/gloo/objs/system/system.rb +84 -38
  60. data/lib/gloo/objs/web/http_get.rb +83 -46
  61. data/lib/gloo/objs/web/http_post.rb +69 -43
  62. data/lib/gloo/objs/web/slack.rb +89 -58
  63. data/lib/gloo/objs/web/teams.rb +88 -53
  64. data/lib/gloo/persist/file_loader.rb +81 -82
  65. data/lib/gloo/persist/file_saver.rb +12 -12
  66. data/lib/gloo/persist/file_storage.rb +15 -15
  67. data/lib/gloo/persist/line_splitter.rb +74 -0
  68. data/lib/gloo/persist/persist_man.rb +29 -29
  69. data/lib/gloo/utils/words.rb +2 -2
  70. data/lib/gloo/verbs/alert.rb +67 -16
  71. data/lib/gloo/verbs/beep.rb +70 -0
  72. data/lib/gloo/verbs/context.rb +61 -21
  73. data/lib/gloo/verbs/create.rb +52 -21
  74. data/lib/gloo/verbs/help.rb +177 -27
  75. data/lib/gloo/verbs/if.rb +54 -21
  76. data/lib/gloo/verbs/list.rb +55 -24
  77. data/lib/gloo/verbs/load.rb +46 -12
  78. data/lib/gloo/verbs/put.rb +90 -34
  79. data/lib/gloo/verbs/quit.rb +43 -12
  80. data/lib/gloo/verbs/run.rb +42 -11
  81. data/lib/gloo/verbs/save.rb +45 -10
  82. data/lib/gloo/verbs/show.rb +56 -22
  83. data/lib/gloo/verbs/tell.rb +44 -12
  84. data/lib/gloo/verbs/unless.rb +55 -21
  85. data/lib/gloo/verbs/version.rb +42 -12
  86. data/lib/run.rb +5 -5
  87. metadata +19 -12
@@ -7,50 +7,83 @@
7
7
  module Gloo
8
8
  module Verbs
9
9
  class If < Gloo::Core::Verb
10
-
11
- KEYWORD = 'if'
12
- KEYWORD_SHORT = 'if'
13
- THEN = 'then'
14
-
15
- #
10
+
11
+ KEYWORD = 'if'.freeze
12
+ KEYWORD_SHORT = 'if'.freeze
13
+ THEN = 'then'.freeze
14
+
15
+ #
16
16
  # Run the verb.
17
- #
17
+ #
18
18
  def run
19
19
  value = @tokens.before_token( THEN )
20
20
  if value.count > 1
21
21
  # The first token is the verb, so we drop it.
22
- value = value[1..-1]
22
+ value = value[ 1..-1 ]
23
23
  end
24
24
 
25
25
  evals_true = false
26
- if value.count > 0
26
+ if value.count.positive?
27
27
  expr = Gloo::Expr::Expression.new( value )
28
28
  result = expr.evaluate
29
29
  evals_true = true if result == true
30
30
  end
31
-
32
- if evals_true
33
- cmd = @tokens.expr_after( THEN )
34
- i = $engine.parser.parse_immediate cmd
35
- return unless i
36
- i.run
37
- end
31
+ return unless evals_true
32
+
33
+ cmd = @tokens.expr_after( THEN )
34
+ i = $engine.parser.parse_immediate cmd
35
+ return unless i
36
+
37
+ i.run
38
38
  end
39
-
40
- #
39
+
40
+ #
41
41
  # Get the Verb's keyword.
42
- #
42
+ #
43
43
  def self.keyword
44
44
  return KEYWORD
45
45
  end
46
46
 
47
- #
47
+ #
48
48
  # Get the Verb's keyword shortcut.
49
- #
49
+ #
50
50
  def self.keyword_shortcut
51
51
  return KEYWORD_SHORT
52
52
  end
53
53
 
54
+ # ---------------------------------------------------------------------
55
+ # Help
56
+ # ---------------------------------------------------------------------
57
+
58
+ #
59
+ # Get help for this verb.
60
+ #
61
+ def self.help
62
+ return <<~TEXT
63
+ IF VERB
64
+ NAME: if
65
+ SHORTCUT: if
66
+
67
+ DESCRIPTION
68
+ If an expression is true then do something.
69
+
70
+ SYNTAX
71
+ if <true> then <do>
72
+
73
+ PARAMETERS
74
+ true - Does the expression evaluate to true?
75
+ do - Execute command if the expression is true.
76
+
77
+ RESULT
78
+ Unchanged if the expression is not true.
79
+ If true, then the result will be based on the command
80
+ specified after the 'then' keyword.
81
+
82
+ ERRORS
83
+ The errors depend on the object that is run.
84
+ TEXT
85
+ end
86
+
54
87
  end
55
88
  end
56
89
  end
@@ -7,13 +7,13 @@
7
7
  module Gloo
8
8
  module Verbs
9
9
  class List < Gloo::Core::Verb
10
-
11
- KEYWORD = 'list'
12
- KEYWORD_SHORT = '.'
13
10
 
14
- #
11
+ KEYWORD = 'list'.freeze
12
+ KEYWORD_SHORT = '.'.freeze
13
+
14
+ #
15
15
  # Run the verb.
16
- #
16
+ #
17
17
  def run
18
18
  levels = determine_levels
19
19
  target = self.determine_target
@@ -30,33 +30,31 @@ module Gloo
30
30
  # Check settings for the default value.
31
31
  levels = $settings.list_indent
32
32
  return levels if levels
33
-
33
+
34
34
  # Last chance: use the default
35
35
  return 1
36
36
  end
37
-
37
+
38
38
  # Determine the target object for the show command.
39
39
  def determine_target
40
- if @tokens.token_count == 1
41
- return $engine.heap.context
42
- else
43
- return Gloo::Core::Pn.new( @tokens.second )
44
- end
40
+ return $engine.heap.context if @tokens.token_count == 1
41
+
42
+ return Gloo::Core::Pn.new( @tokens.second )
45
43
  end
46
44
 
47
45
  # Show the target object.
48
- def show_target( obj, levels, indent="" )
46
+ def show_target( obj, levels, indent = '' )
49
47
  show_obj( obj, indent )
50
-
51
- return if levels == 0
52
- obj.children.each do |o|
48
+ return if levels.zero?
49
+
50
+ obj.children.each do |o|
53
51
  show_target( o, levels - 1, "#{indent} " )
54
52
  end
55
53
  end
56
-
54
+
57
55
  # Show object in standard format.
58
- def show_obj obj, indent=" "
59
- if obj.has_multiline_value? && obj.value_is_array?
56
+ def show_obj( obj, indent = ' ' )
57
+ if obj.multiline_value? && obj.value_is_array?
60
58
  $log.show "#{indent}#{obj.name} [#{obj.type_display}] :"
61
59
  obj.value.each do |line|
62
60
  $log.show "#{indent} #{line}"
@@ -65,21 +63,54 @@ module Gloo
65
63
  $log.show "#{indent}#{obj.name} [#{obj.type_display}] : #{obj.value}"
66
64
  end
67
65
  end
68
-
69
- #
66
+
67
+ #
70
68
  # Get the Verb's keyword.
71
- #
69
+ #
72
70
  def self.keyword
73
71
  return KEYWORD
74
72
  end
75
73
 
76
- #
74
+ #
77
75
  # Get the Verb's keyword shortcut.
78
- #
76
+ #
79
77
  def self.keyword_shortcut
80
78
  return KEYWORD_SHORT
81
79
  end
82
80
 
81
+ # ---------------------------------------------------------------------
82
+ # Help
83
+ # ---------------------------------------------------------------------
84
+
85
+ #
86
+ # Get help for this verb.
87
+ #
88
+ def self.help
89
+ return <<~TEXT
90
+ LIST VERB
91
+ NAME: list
92
+ SHORTCUT: .
93
+
94
+ DESCRIPTION
95
+ List out objects (and children) at the current context.
96
+ When a path is provided, it will be listed instead of the
97
+ current context.
98
+
99
+ SYNTAX
100
+ list <path.to.object>
101
+
102
+ PARAMETERS
103
+ path.to.object - Optional path to object that will be listed.
104
+ When no path is provided, the current context is used.
105
+
106
+ RESULT
107
+ Object and children are listed out in the CLI.
108
+
109
+ ERRORS
110
+ None
111
+ TEXT
112
+ end
113
+
83
114
  end
84
115
  end
85
116
  end
@@ -7,33 +7,67 @@
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
+ The file's path should be provided from the gloo project folder
53
+ as the root directory.
54
+
55
+ SYNTAX
56
+ load <file_name>
57
+
58
+ PARAMETERS
59
+ file_name - Name of the object file that is to be loaded.
60
+
61
+ RESULT
62
+ Objects are loaded into the heap.
63
+ on_load scripts are run within the loaded objects.
64
+
65
+ ERRORS
66
+ If the file specified can't be found or can't be loaded,
67
+ an error condition will result.
68
+ TEXT
69
+ end
70
+
37
71
  end
38
72
  end
39
73
  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