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
@@ -7,29 +7,24 @@
7
7
  module Gloo
8
8
  module Core
9
9
  class ObjFinder
10
-
11
- #
10
+
11
+ #
12
12
  # Find all objects in the given container that have
13
13
  # the given name.
14
14
  # If the container isn't provided, root will be used.
15
- #
16
- def self.by_name name, container=nil
17
- if container.nil?
18
- container = $engine.heap.root
19
- end
15
+ #
16
+ def self.by_name( name, container = nil )
17
+ container = $engine.heap.root if container.nil?
20
18
  arr = []
21
-
19
+
22
20
  container.children.each do |o|
23
21
  arr << o if o.name == name
24
- if o.child_count > 0
25
- arr += by_name( name, o )
26
- end
22
+ arr += by_name( name, o ) if o.child_count.positive?
27
23
  end
28
-
24
+
29
25
  return arr
30
26
  end
31
-
32
-
27
+
33
28
  end
34
29
  end
35
30
  end
@@ -7,27 +7,27 @@
7
7
  module Gloo
8
8
  module Core
9
9
  class Op
10
-
10
+
11
11
  # Is the token an operator?
12
- def self.is_op? token
13
- return [ "+", "-", "*", "/" ].include?( token.strip )
12
+ def self.op?( token )
13
+ return [ '+', '-', '*', '/' ].include?( token.strip )
14
14
  end
15
-
15
+
16
16
  # Create the operator for the given token.
17
- def self.create_op token
17
+ def self.create_op( token )
18
18
  return Gloo::Expr::OpMinus.new if token == '-'
19
19
  return Gloo::Expr::OpMult.new if token == '*'
20
20
  return Gloo::Expr::OpDiv.new if token == '/'
21
21
  return Gloo::Expr::OpPlus.new if token == '+'
22
-
22
+
23
23
  return default_op
24
24
  end
25
-
25
+
26
26
  # Get the default operator (+).
27
27
  def self.default_op
28
28
  return Gloo::Expr::OpPlus.new
29
29
  end
30
-
30
+
31
31
  end
32
32
  end
33
33
  end
@@ -8,45 +8,46 @@
8
8
  module Gloo
9
9
  module Core
10
10
  class Parser
11
-
11
+
12
12
  # Set up the parser.
13
- def initialize()
14
- $log.debug "parser intialized..."
13
+ def initialize
14
+ $log.debug 'parser intialized...'
15
15
  end
16
-
17
-
16
+
18
17
  # Parse a command from the immediate execution context.
19
- def parse_immediate cmd
20
- cmd, params = split_params cmd
21
- params = Gloo::Core::Tokens.new( params ) if params
18
+ def parse_immediate( cmd )
19
+ cmd, params = split_params cmd
20
+ params = Gloo::Core::Tokens.new( params ) if params
22
21
  tokens = Gloo::Core::Tokens.new( cmd )
23
22
  dic = Gloo::Core::Dictionary.instance
24
23
  verb = dic.find_verb( tokens.verb )
25
24
  return verb.new( tokens, params ) if verb
26
-
25
+
27
26
  $log.error "Verb '#{tokens.verb}' was not found."
28
27
  return nil
29
28
  end
30
-
31
- # If additional params were provided, split them out
32
- # from the token list.
33
- def split_params cmd
34
- params = nil
35
- i = cmd.rindex( '(' )
36
- if i && cmd.strip.end_with?( ')' )
37
- pstr = cmd[i+1..-1]
38
- params = pstr.strip[0..-2] if pstr
39
- cmd = cmd[ 0, i-1]
40
- end
41
- return cmd, params
42
- end
43
-
29
+
30
+ # If additional params were provided, split them out
31
+ # from the token list.
32
+ def split_params( cmd )
33
+ params = nil
34
+ i = cmd.rindex( '(' )
35
+ if i && cmd.strip.end_with?( ')' )
36
+ pstr = cmd[ i + 1..-1 ]
37
+ params = pstr.strip[ 0..-2 ] if pstr
38
+ cmd = cmd[ 0, i - 1 ]
39
+ end
40
+ return cmd, params
41
+ end
42
+
43
+ #
44
44
  # Parse a command and then run it if it parsed correctly.
45
- def run cmd
45
+ #
46
+ def run( cmd )
46
47
  v = parse_immediate( cmd )
47
- v.run if v
48
+ Gloo::Exec::Runner.go( v ) if v
48
49
  end
49
-
50
+
50
51
  end
51
52
  end
52
53
  end
@@ -9,40 +9,56 @@ module Gloo
9
9
  module Core
10
10
  class Pn < Baseo
11
11
 
12
+ ROOT = 'root'.freeze
13
+ IT = 'it'.freeze
14
+ ERROR = 'error'.freeze
15
+
12
16
  attr_reader :src, :elements
13
-
17
+
14
18
  # Set up the object given a source string,
15
19
  # ie: the full path and name.
16
20
  def initialize( src )
17
21
  set_to src
18
22
  end
19
-
23
+
20
24
  # Reference to the root object path.
21
25
  def self.root
22
- return Pn.new( "root" )
26
+ return Pn.new( ROOT )
23
27
  end
24
28
 
25
29
  # Reference to it.
26
30
  def self.it
27
- return Pn.new( "it" )
31
+ return Pn.new( IT )
28
32
  end
29
-
30
- # Does the pathname reference refer to the root?
31
- def is_root?
32
- return @src.downcase == "root"
33
+
34
+ # Reference to the error message.
35
+ def self.error
36
+ return Pn.new( ERROR )
33
37
  end
34
-
38
+
35
39
  # Does the pathname reference refer to the root?
36
- def is_it?
37
- return @src.downcase == "it"
40
+ def root?
41
+ return @src.downcase == ROOT
42
+ end
43
+
44
+ # Does the pathname reference refer to it?
45
+ def it?
46
+ return @src.downcase == IT
38
47
  end
39
-
48
+
49
+ # Does the pathname reference refer to error?
50
+ def error?
51
+ return @src.downcase == ERROR
52
+ end
53
+
40
54
  # Does the pathname reference refer to the gloo system object?
41
- def is_gloo_sys?
42
- return false unless @elements && @elements.count > 0
55
+ def gloo_sys?
56
+ return false unless @elements&.count&.positive?
57
+
43
58
  o = @elements.first.downcase
44
59
  return true if o == Gloo::Core::GlooSystem.typename
45
60
  return true if o == Gloo::Core::GlooSystem.short_typename
61
+
46
62
  return false
47
63
  end
48
64
 
@@ -52,42 +68,39 @@ module Gloo
52
68
  end
53
69
 
54
70
  # Set the object pathname to the given value.
55
- def set_to value
56
- @src = value.strip unless value.nil?
57
- if @src.nil?
58
- @elements = []
59
- else
60
- @elements = @src.split( '.' )
61
- end
71
+ def set_to( value )
72
+ @src = value.nil? ? nil : value.strip
73
+ @elements = @src.nil? ? [] : @src.split( '.' )
62
74
  end
63
-
75
+
64
76
  # Convert the raw string to a list of segments.
65
77
  def segments
66
78
  return @elements
67
79
  end
68
-
80
+
69
81
  # Get the name element.
70
82
  def name
71
- return "" unless self.has_name?
83
+ return '' unless self.named?
84
+
72
85
  return @elements.last
73
86
  end
74
87
 
75
88
  # Does the value include path elements?
76
- def has_name?
77
- return @elements.count > 0
89
+ def named?
90
+ return @elements.count.positive?
78
91
  end
79
92
 
80
93
  # Does the value include a name?
81
- def has_path?
94
+ def includes_path?
82
95
  return @elements.count > 1
83
96
  end
84
-
97
+
85
98
  # Get the parent that contains the object referenced.
86
99
  def get_parent
87
100
  o = $engine.heap.root
88
-
89
- if self.has_path?
90
- @elements[0..-2].each do |e|
101
+
102
+ if self.includes_path?
103
+ @elements[ 0..-2 ].each do |e|
91
104
  o = o.find_child( e )
92
105
  if o.nil?
93
106
  $log.error "Object '#{e}' was not found."
@@ -95,38 +108,41 @@ module Gloo
95
108
  end
96
109
  end
97
110
  end
98
-
111
+
99
112
  return o
100
113
  end
101
-
114
+
102
115
  # Does the object at the path exist?
103
116
  def exists?
104
- return true if self.is_root?
105
- return true if self.is_it?
106
-
117
+ return true if self.root?
118
+ return true if self.it?
119
+ return true if self.error?
120
+
107
121
  parent = self.get_parent
108
122
  return false unless parent
109
- return parent.has_child? name
110
- end
111
-
112
- # Is the reference to a color?
113
- def is_color?
114
- colors = [ "red", "blue", "green", "white", "black", "yellow" ]
115
- return true if colors.include?( @src.downcase )
116
- end
117
-
123
+
124
+ return parent.contains_child? name
125
+ end
126
+
127
+ # Is the reference to a color?
128
+ def named_color?
129
+ colors = %w[red blue green white black yellow]
130
+ return true if colors.include?( @src.downcase )
131
+ end
132
+
118
133
  # Resolve the pathname reference.
119
134
  # Find the object referenced or return nil if it is not found.
120
135
  def resolve
121
- return $engine.heap.root if self.is_root?
122
- return $engine.heap.it if self.is_it?
123
- if self.is_gloo_sys?
124
- return Gloo::Core::GlooSystem.new( self )
125
- end
126
-
136
+ return $engine.heap.root if self.root?
137
+ return $engine.heap.it if self.it?
138
+ return $engine.heap.error if self.error?
139
+ return Gloo::Core::GlooSystem.new( self ) if self.gloo_sys?
140
+
127
141
  parent = self.get_parent
128
142
  return nil unless parent
129
- return parent.find_child( self.name )
143
+
144
+ obj = parent.find_child( self.name )
145
+ return Gloo::Objs::Alias.resolve_alias( obj, self.src )
130
146
  end
131
147
 
132
148
  end
@@ -7,13 +7,12 @@
7
7
  module Gloo
8
8
  module Core
9
9
  class Script
10
-
10
+
11
11
  # Set up the script.
12
- def initialize obj
12
+ def initialize( obj )
13
13
  @obj = obj
14
14
  end
15
-
16
-
15
+
17
16
  # Run the script.
18
17
  def run
19
18
  if @obj.value.is_a? String
@@ -24,14 +23,15 @@ module Gloo
24
23
  end
25
24
  end
26
25
  end
27
-
26
+
28
27
  # Run a single line of the script.
29
- def run_line line
28
+ def run_line( line )
30
29
  i = $engine.parser.parse_immediate line
31
30
  return unless i
31
+
32
32
  i.run
33
33
  end
34
-
34
+
35
35
  end
36
36
  end
37
37
  end
@@ -8,44 +8,44 @@
8
8
  module Gloo
9
9
  module Core
10
10
  class Tokens
11
-
11
+
12
12
  attr_reader :cmd, :tokens
13
-
13
+
14
14
  # Set up the tokens.
15
15
  def initialize( cmd_string )
16
16
  @cmd = cmd_string
17
17
  @tokens = []
18
18
  tokenize @cmd
19
19
  end
20
-
20
+
21
21
  # Create a list of token from the given string.
22
- def tokenize str
22
+ def tokenize( str )
23
23
  if str.index( '"' )
24
24
  i = str.index( '"' )
25
- j = str.index( '"', i+1 )
26
- j = str.length unless j
27
-
28
- tokenize( str[ 0..i-1 ] ) if i > 1
25
+ j = str.index( '"', i + 1 )
26
+ j ||= str.length
27
+
28
+ tokenize( str[ 0..i - 1 ] ) if i > 1
29
29
  @tokens << str[ i..j ]
30
- tokenize( str[ j+1..-1 ] ) if j+1 < str.length
30
+ tokenize( str[ j + 1..-1 ] ) if j + 1 < str.length
31
31
  elsif str.index( "'" )
32
32
  i = str.index( "'" )
33
- j = str.index( "'", i+1 )
34
- j = str.length unless j
33
+ j = str.index( "'", i + 1 )
34
+ j ||= str.length
35
35
 
36
- tokenize( str[ 0..i-1 ] ) if i > 1
36
+ tokenize( str[ 0..i - 1 ] ) if i > 1
37
37
  @tokens << str[ i..j ]
38
- tokenize( str[ j+1..-1 ] ) if j+1 < str.length
38
+ tokenize( str[ j + 1..-1 ] ) if j + 1 < str.length
39
39
  else
40
- str.strip.split( " " ).each { |t| @tokens << t }
40
+ str.strip.split( ' ' ).each { |t| @tokens << t }
41
41
  end
42
42
  end
43
-
43
+
44
44
  # Get the number of tokens
45
45
  def token_count
46
46
  return @tokens.size
47
47
  end
48
-
48
+
49
49
  # Get the verb (the first word)
50
50
  def verb
51
51
  return first
@@ -65,59 +65,57 @@ module Gloo
65
65
  def last
66
66
  return @tokens.last if @tokens
67
67
  end
68
-
68
+
69
69
  # Get the second token.
70
70
  def second
71
- return @tokens[1] if @tokens && @tokens.size > 0
71
+ return @tokens[ 1 ] if @tokens&.size&.positive?
72
72
  end
73
73
 
74
- def at index
75
- return @tokens[index] if @tokens && @tokens.size >= index
74
+ def at( index )
75
+ return @tokens[ index ] if @tokens && @tokens.size >= index
76
76
  end
77
-
77
+
78
78
  # Get the index of the given token.
79
- def index_of token
79
+ def index_of( token )
80
80
  return nil unless @tokens
81
- return @tokens.find_index { |o| o.casecmp( token ) == 0 }
81
+
82
+ return @tokens.find_index { |o| o.casecmp( token ).zero? }
82
83
  end
83
84
 
84
85
  # Get the list of tokens after the given token
85
- def tokens_after token
86
+ def tokens_after( token )
86
87
  i = index_of token
87
- if i && @tokens && @tokens.size > ( i+1 )
88
- return @tokens[ i+1..-1 ]
89
- end
88
+ return @tokens[ i + 1..-1 ] if i && @tokens && @tokens.size > ( i + 1 )
89
+
90
90
  return nil
91
91
  end
92
92
 
93
93
  # Get the expression after the given token
94
- def expr_after token
95
- str = ""
94
+ def expr_after( token )
95
+ str = ''
96
96
  tokens_after( token ).each do |t|
97
- str << " " if ( str.length > 0 )
98
- str << "#{t}"
97
+ str << ' ' unless str.empty?
98
+ str << t.to_s
99
99
  end
100
100
  return str
101
101
  end
102
-
102
+
103
103
  # Get the item after a given token.
104
- def after_token token
104
+ def after_token( token )
105
105
  i = index_of token
106
- if i && @tokens && @tokens.size > ( i+1 )
107
- return @tokens[ i+1 ]
108
- end
106
+ return @tokens[ i + 1 ] if i && @tokens && @tokens.size > ( i + 1 )
107
+
109
108
  return nil
110
109
  end
111
110
 
112
111
  # Get the item after a given token.
113
- def before_token token
112
+ def before_token( token )
114
113
  i = index_of token
115
- if i && @tokens && @tokens.size >= ( i )
116
- return @tokens[ 0..i-1 ]
117
- end
114
+ return @tokens[ 0..i - 1 ] if i && @tokens && @tokens.size >= i
115
+
118
116
  return nil
119
117
  end
120
-
118
+
121
119
  end
122
120
  end
123
121
  end