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,97 +7,89 @@
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
+
97
89
  # last chance: an Object reference
98
90
  return Gloo::Core::Pn.new( token )
99
91
  end
100
-
92
+
101
93
  end
102
94
  end
103
95
  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
 
@@ -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,10 @@ 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
16
14
  end
17
-
15
+
18
16
  end
19
17
  end
20
18
  end
@@ -9,12 +9,10 @@ module Gloo
9
9
  class OpMinus < 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
16
14
  end
17
-
15
+
18
16
  end
19
17
  end
20
18
  end
@@ -9,12 +9,10 @@ module Gloo
9
9
  class OpMult < 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
16
14
  end
17
-
15
+
18
16
  end
19
17
  end
20
18
  end
@@ -9,14 +9,12 @@ module Gloo
9
9
  class OpPlus < Gloo::Core::Op
10
10
 
11
11
  # Perform the operation and return the result.
12
- def perform left, right
13
- if left.is_a? String
14
- return left + right.to_s
15
- elsif left.is_a? Integer
16
- return left + right.to_i
17
- end
12
+ def perform( left, right )
13
+ return left + right.to_s if left.is_a? String
14
+
15
+ return left + right.to_i if left.is_a? Integer
18
16
  end
19
-
17
+
20
18
  end
21
19
  end
22
20
  end
@@ -7,88 +7,86 @@
7
7
  module Gloo
8
8
  module Objs
9
9
  class Boolean < Gloo::Core::Obj
10
-
11
- KEYWORD = 'boolean'
12
- KEYWORD_SHORT = 'bool'
13
- TRUE = 'true'
14
- FALSE = 'false'
15
10
 
16
- #
11
+ KEYWORD = 'boolean'.freeze
12
+ KEYWORD_SHORT = 'bool'.freeze
13
+ TRUE = 'true'.freeze
14
+ FALSE = 'false'.freeze
15
+
16
+ #
17
17
  # The name of the object type.
18
- #
18
+ #
19
19
  def self.typename
20
20
  return KEYWORD
21
21
  end
22
22
 
23
- #
23
+ #
24
24
  # The short name of the object type.
25
- #
25
+ #
26
26
  def self.short_typename
27
27
  return KEYWORD_SHORT
28
28
  end
29
29
 
30
- #
30
+ #
31
31
  # Set the value with any necessary type conversions.
32
- #
33
- def set_value new_value
32
+ #
33
+ def set_value( new_value )
34
34
  self.value = Gloo::Objs::Boolean.coerse_to_bool( new_value )
35
35
  end
36
-
37
- #
36
+
37
+ #
38
38
  # Coerse the new value to a boolean value.
39
- #
40
- def self.coerse_to_bool new_value
41
- if new_value.nil?
42
- return false
43
- elsif new_value.class.name == "String"
39
+ #
40
+ def self.coerse_to_bool( new_value )
41
+ return false if new_value.nil?
42
+
43
+ if new_value.class.name == 'String'
44
44
  return true if new_value.strip.downcase == TRUE
45
45
  return false if new_value.strip.downcase == FALSE
46
46
  return true if new_value.strip.downcase == 't'
47
47
  return false if new_value.strip.downcase == 'f'
48
- elsif new_value.class.name == "Integer"
49
- return false if new_value == 0
50
- return true
51
- else
52
- return new_value == true
48
+ elsif new_value.class.name == 'Integer'
49
+ return new_value.zero? ? false : true
53
50
  end
51
+
52
+ return new_value == true
54
53
  end
55
-
56
- #
54
+
55
+ #
57
56
  # Is the given token a boolean?
58
- #
59
- def self.is_boolean? token
57
+ #
58
+ def self.boolean?( token )
60
59
  return true if token == true
61
60
  return true if token == false
62
- if token.class.name == "String"
61
+
62
+ if token.class.name == 'String'
63
63
  return true if token.strip.downcase == TRUE
64
64
  return true if token.strip.downcase == FALSE
65
65
  end
66
66
  return false
67
67
  end
68
68
 
69
-
70
- #
69
+ #
71
70
  # Get the value for display purposes.
72
- #
71
+ #
73
72
  def value_display
74
73
  return value ? TRUE : FALSE
75
74
  end
76
75
 
77
-
78
76
  # ---------------------------------------------------------------------
79
77
  # Messages
80
78
  # ---------------------------------------------------------------------
81
79
 
82
- #
80
+ #
83
81
  # Get a list of message names that this object receives.
84
- #
82
+ #
85
83
  def self.messages
86
- return super + [ "not", "true", "false" ]
84
+ return super + %w[not true false]
87
85
  end
88
-
86
+
89
87
  # Set the value to the opposite of what it is.
90
88
  def msg_not
91
- v = ! value
89
+ v = !value
92
90
  set_value v
93
91
  $engine.heap.it.set_to v
94
92
  return v
@@ -108,6 +106,33 @@ module Gloo
108
106
  return false
109
107
  end
110
108
 
109
+ # ---------------------------------------------------------------------
110
+ # Help
111
+ # ---------------------------------------------------------------------
112
+
113
+ #
114
+ # Get help for this object type.
115
+ #
116
+ def self.help
117
+ return <<~TEXT
118
+ BOOLEAN OBJECT TYPE
119
+ NAME: boolean
120
+ SHORTCUT: bool
121
+
122
+ DESCRIPTION
123
+ A boolean value.
124
+ Value will be either true or false.
125
+
126
+ CHILDREN
127
+ None
128
+
129
+ MESSAGES
130
+ not - Set the boolean to the opposite of what it is now.
131
+ true - Set the boolean to true.
132
+ false - Set the boolean to false.
133
+ TEXT
134
+ end
135
+
111
136
  end
112
137
  end
113
138
  end