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
@@ -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
71
+ def set_to( value )
56
72
  @src = value.strip unless value.nil?
57
- if @src.nil?
58
- @elements = []
59
- else
60
- @elements = @src.split( '.' )
61
- end
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,37 +108,39 @@ 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
143
+
129
144
  return parent.find_child( self.name )
130
145
  end
131
146
 
@@ -0,0 +1,26 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 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 Core
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
+ $engine.heap.error.start_tracking
20
+ verb&.run
21
+ $engine.heap.error.clear_if_no_errors
22
+ end
23
+
24
+ end
25
+ end
26
+ 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
@@ -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