gloo 0.3.0 → 0.5.3

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 (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
@@ -10,54 +10,65 @@
10
10
  module Gloo
11
11
  module Core
12
12
  class Verb < Baseo
13
-
14
- attr_reader :tokens, :params
15
-
13
+
14
+ attr_reader :tokens, :params
15
+
16
16
  # Set up the verb.
17
- def initialize( tokens, params=[] )
17
+ def initialize( tokens, params = [] )
18
18
  @tokens = tokens
19
- @params = params
19
+ @params = params
20
20
  end
21
-
21
+
22
22
  # Register verbs when they are loaded.
23
23
  def self.inherited( subclass )
24
24
  Dictionary.instance.register_verb( subclass )
25
25
  end
26
-
27
- #
26
+
27
+ #
28
28
  # Run the verb.
29
- #
29
+ #
30
30
  # We'll mark the application as not running and let the
31
31
  # engine stop gracefully next time through the loop.
32
- #
32
+ #
33
33
  def run
34
34
  raise 'this method should be overriden'
35
35
  end
36
-
37
- #
36
+
37
+ #
38
38
  # Get the Verb's keyword.
39
- #
39
+ #
40
40
  # The keyword will be in lower case only.
41
41
  # It is used by the parser.
42
- #
42
+ #
43
43
  def self.keyword
44
44
  raise 'this method should be overriden'
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
  raise 'this method should be overriden'
52
52
  end
53
-
54
- #
53
+
54
+ #
55
55
  # The object type, suitable for display.
56
- #
56
+ #
57
57
  def type_display
58
58
  return self.class.keyword
59
59
  end
60
60
 
61
+ # ---------------------------------------------------------------------
62
+ # Help
63
+ # ---------------------------------------------------------------------
64
+
65
+ #
66
+ # Get help for this verb.
67
+ #
68
+ def self.help
69
+ return 'No help found.'
70
+ end
71
+
61
72
  end
62
73
  end
63
74
  end
@@ -0,0 +1,30 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # Central Message Dispatch.
5
+ # Responsible for sending message to objects.
6
+ # All object messaging goes through here so we can uniformly
7
+ # manage things like checking to make sure object can
8
+ # receive the messages sent, handling errors, etc.
9
+ #
10
+
11
+ module Gloo
12
+ module Exec
13
+ class Dispatch
14
+
15
+ #
16
+ # Dispatch the given message to the given object.
17
+ #
18
+ def self.message( msg, to_obj, params = nil )
19
+ $log.debug "----- Sending message #{msg} to #{to_obj.name}"
20
+
21
+ if to_obj.can_receive_message? msg
22
+ to_obj.send_message msg, params
23
+ else
24
+ $log.warn "Object #{to_obj.name} does not respond to #{msg}"
25
+ end
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,43 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # The Runner is a static helper function.
5
+ # It is used to send the run command to verbs.
6
+ #
7
+
8
+ module Gloo
9
+ module Exec
10
+ class Runner
11
+
12
+ #
13
+ # Dispatch run command to a verb.
14
+ # We abstract this out in case there are things
15
+ # that need to be done before or after a verb
16
+ # is done running.
17
+ #
18
+ def self.go( verb )
19
+ $log.debug "**** Running verb #{verb.type_display}"
20
+ $engine.heap.error.start_tracking
21
+ verb&.run
22
+ $engine.heap.error.clear_if_no_errors
23
+ end
24
+
25
+ #
26
+ # Send 'run' message to the object.
27
+ # Resolve the path_name and then send the run message.
28
+ #
29
+ def self.run( path_name )
30
+ $log.debug "**** Running script at #{path_name}"
31
+ pn = Gloo::Core::Pn.new path_name
32
+ o = pn.resolve
33
+
34
+ if o
35
+ o.send_message 'run'
36
+ else
37
+ $log.error "Could not send message to object. Bad path: #{path_name}"
38
+ end
39
+ end
40
+
41
+ end
42
+ end
43
+ end
@@ -7,97 +7,90 @@
7
7
  module Gloo
8
8
  module Expr
9
9
  class Expression
10
-
10
+
11
11
  # Create the expression from a list of tokens.
12
- def initialize tokens
12
+ def initialize( tokens )
13
13
  @tokens = tokens
14
14
  @symbols = []
15
15
  @left = nil
16
16
  @right = nil
17
17
  @op = nil
18
18
  end
19
-
19
+
20
20
  # Evaluate the expression and return the value.
21
21
  def evaluate
22
22
  identify_tokens
23
-
23
+
24
24
  @symbols.each do |sym|
25
25
  if sym.is_a? Gloo::Core::Op
26
26
  @op = sym
27
- elsif @left == nil
27
+ elsif @left.nil?
28
28
  @left = sym
29
29
  else
30
30
  @right = sym
31
31
  end
32
-
32
+
33
33
  perform_op if @left && @right
34
34
  end
35
-
36
- if @left.is_a? Gloo::Core::Literal
37
- return @left.value
38
- elsif @left.is_a? Gloo::Core::Pn
39
- return resolve_ref @left
40
- else
41
- return @left
42
- end
35
+
36
+ return @left.value if @left.is_a? Gloo::Core::Literal
37
+ return resolve_ref @left if @left.is_a? Gloo::Core::Pn
38
+
39
+ return @left
43
40
  end
44
-
41
+
45
42
  # Perform the operation.
46
43
  def perform_op
47
- @op = Gloo::Core::Op.default_op unless @op
44
+ @op ||= Gloo::Core::Op.default_op
48
45
  l = evaluate_sym @left
49
46
  r = evaluate_sym @right
50
47
  @left = @op.perform l, r
51
48
  @right = nil
52
49
  @op = nil
53
50
  end
54
-
51
+
55
52
  # Evaluate the symbol and get a simple value.
56
- def evaluate_sym sym
57
- if sym.is_a? Gloo::Core::Literal
58
- return sym.value
59
- elsif sym.is_a? Gloo::Core::Pn
60
- return resolve_ref sym
61
- else
62
- return sym
63
- end
53
+ def evaluate_sym( sym )
54
+ return sym.value if sym.is_a? Gloo::Core::Literal
55
+ return resolve_ref sym if sym.is_a? Gloo::Core::Pn
56
+
57
+ return sym
64
58
  end
65
-
59
+
66
60
  # resolve an object reference and get the value.
67
- def resolve_ref ref
68
- return ref.src if ref.is_color?
61
+ def resolve_ref( ref )
62
+ return ref.src if ref.named_color?
69
63
 
70
64
  ob = ref.resolve
71
65
  return ob.value if ob
72
66
  end
73
-
67
+
74
68
  # Identify each token in the list.
75
69
  def identify_tokens
76
70
  @tokens.each do |o|
77
71
  @symbols << identify_token( o )
78
72
  end
79
-
73
+
80
74
  # @symbols.each do |o|
81
75
  # puts o.class.name
82
76
  # end
83
77
  end
84
-
85
- #
78
+
79
+ #
86
80
  # Identify the tokens and create appropriate symbols.
87
- #
88
- def identify_token token
89
- if Gloo::Core::Op.is_op?( token )
90
- return Gloo::Core::Op.create_op( token )
91
- end
92
-
93
- return LBoolean.new( token ) if LBoolean.is_boolean?( token )
94
- return LInteger.new( token ) if LInteger.is_integer?( token )
95
- return LString.new( token ) if LString.is_string?( token )
96
-
81
+ #
82
+ def identify_token( token )
83
+ return Gloo::Core::Op.create_op( token ) if Gloo::Core::Op.op?( token )
84
+
85
+ return LBoolean.new( token ) if LBoolean.boolean?( token )
86
+ return LInteger.new( token ) if LInteger.integer?( token )
87
+ return LString.new( token ) if LString.string?( token )
88
+ return LDecimal.new( token ) if LDecimal.decimal?( token )
89
+
97
90
  # last chance: an Object reference
98
91
  return Gloo::Core::Pn.new( token )
99
92
  end
100
-
93
+
101
94
  end
102
95
  end
103
96
  end
@@ -7,20 +7,21 @@
7
7
  module Gloo
8
8
  module Expr
9
9
  class LBoolean < Gloo::Core::Literal
10
-
10
+
11
11
  # Is the given token a boolean?
12
- def self.is_boolean? token
13
- return Gloo::Objs::Boolean.is_boolean? token
12
+ def self.boolean?( token )
13
+ return Gloo::Objs::Boolean.boolean? token
14
14
  end
15
-
15
+
16
16
  # Set the value, converting to an boolean.
17
- def set_value value
17
+ def set_value( value )
18
18
  @value = Gloo::Objs::Boolean.coerse_to_bool value
19
19
  end
20
20
 
21
21
  # Get string representation
22
22
  def to_s
23
- return "false" unless @value
23
+ return 'false' unless @value
24
+
24
25
  return @value.to_s
25
26
  end
26
27
 
@@ -0,0 +1,34 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # A literal decimal value.
5
+ #
6
+
7
+ module Gloo
8
+ module Expr
9
+ class LDecimal < Gloo::Core::Literal
10
+
11
+ #
12
+ # Is the given token a decimal?
13
+ #
14
+ def self.decimal?( token )
15
+ return true if token.is_a? Numeric
16
+
17
+ s = token.strip
18
+ return s.to_f.to_s == s
19
+ end
20
+
21
+ # Set the value, converting to an integer.
22
+ def set_value( value )
23
+ value = value.to_s if value.is_a? Numeric
24
+
25
+ @value = value.to_f
26
+ end
27
+
28
+ def to_s
29
+ return self.value.to_s
30
+ end
31
+
32
+ end
33
+ end
34
+ end
@@ -7,16 +7,17 @@
7
7
  module Gloo
8
8
  module Expr
9
9
  class LInteger < Gloo::Core::Literal
10
-
10
+
11
11
  # Is the given token an integer?
12
- def self.is_integer? token
12
+ def self.integer?( token )
13
13
  return true if token.is_a? Integer
14
+
14
15
  s = token.strip
15
16
  return s.to_i.to_s == s
16
17
  end
17
-
18
+
18
19
  # Set the value, converting to an integer.
19
- def set_value value
20
+ def set_value( value )
20
21
  @value = value.to_i
21
22
  end
22
23
 
@@ -7,47 +7,45 @@
7
7
  module Gloo
8
8
  module Expr
9
9
  class LString < Gloo::Core::Literal
10
-
10
+
11
11
  # Set the value, triming opening and closing
12
12
  # quotations if necessary.
13
- def set_value value
13
+ def set_value( value )
14
14
  @value = value
15
15
  return unless value
16
+
16
17
  @value = LString.strip_quotes( @value )
17
18
  end
18
-
19
+
19
20
  # Is the given token a string?
20
- def self.is_string? token
21
+ def self.string?( token )
21
22
  return false unless token.is_a? String
22
23
  return true if token.start_with?( '"' )
23
24
  return true if token.start_with?( "'" )
25
+
24
26
  return false
25
27
  end
26
28
 
27
- #
29
+ #
28
30
  # Given a string with leading and trailing quotes,
29
31
  # strip them out.
30
- #
31
- def self.strip_quotes str
32
+ #
33
+ def self.strip_quotes( str )
32
34
  if str.start_with?( '"' )
33
35
  str = str[ 1..-1 ]
34
- if str.end_with?( '"' )
35
- str = str[ 0..-2 ]
36
- end
36
+ str = str[ 0..-2 ] if str.end_with?( '"' )
37
37
  return str
38
38
  elsif str.start_with?( "'" )
39
39
  str = str[ 1..-1 ]
40
- if str.end_with?( "'" )
41
- str = str[ 0..-2 ]
42
- end
40
+ str = str[ 0..-2 ] if str.end_with?( "'" )
43
41
  return str
44
42
  end
45
43
  end
46
-
44
+
47
45
  def to_s
48
46
  return self.value
49
47
  end
50
-
48
+
51
49
  end
52
50
  end
53
51
  end
@@ -9,12 +9,12 @@ module Gloo
9
9
  class OpDiv < Gloo::Core::Op
10
10
 
11
11
  # Perform the operation and return the result.
12
- def perform left, right
13
- if left.is_a? Integer
14
- return left / right.to_i
15
- end
12
+ def perform( left, right )
13
+ return left / right.to_i if left.is_a? Integer
14
+
15
+ return left / right.to_f if left.is_a? Numeric
16
16
  end
17
-
17
+
18
18
  end
19
19
  end
20
20
  end