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
@@ -0,0 +1,71 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # Play an audio file (MP3).
5
+ #
6
+
7
+ module Gloo
8
+ module Objs
9
+ class Play < Gloo::Core::Obj
10
+
11
+ KEYWORD = 'play'.freeze
12
+ KEYWORD_SHORT = 'play'.freeze
13
+
14
+ #
15
+ # The name of the object type.
16
+ #
17
+ def self.typename
18
+ return KEYWORD
19
+ end
20
+
21
+ #
22
+ # The short name of the object type.
23
+ #
24
+ def self.short_typename
25
+ return KEYWORD_SHORT
26
+ end
27
+
28
+ # ---------------------------------------------------------------------
29
+ # Messages
30
+ # ---------------------------------------------------------------------
31
+
32
+ #
33
+ # Get a list of message names that this object receives.
34
+ #
35
+ def self.messages
36
+ return super + [ 'run' ]
37
+ end
38
+
39
+ # Play the audio file.
40
+ def msg_run
41
+ system "afplay #{value}"
42
+ end
43
+
44
+ # ---------------------------------------------------------------------
45
+ # Help
46
+ # ---------------------------------------------------------------------
47
+
48
+ #
49
+ # Get help for this object type.
50
+ #
51
+ def self.help
52
+ return <<~TEXT
53
+ PLAY OBJECT TYPE
54
+ NAME: play
55
+ SHORTCUT: play
56
+
57
+ DESCRIPTION
58
+ Play an audio file, an MP3 for example.
59
+ The value of the play object is the path to the audio file.
60
+
61
+ CHILDREN
62
+ None.
63
+
64
+ MESSAGES
65
+ run - Play the audio file.
66
+ TEXT
67
+ end
68
+
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,120 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # Wrapper for the 'say something' function on the Mac.
5
+ #
6
+ require 'erb'
7
+
8
+ module Gloo
9
+ module Objs
10
+ class Say < Gloo::Core::Obj
11
+
12
+ KEYWORD = 'say'.freeze
13
+ KEYWORD_SHORT = 'say'.freeze
14
+ VOICE = 'voice'.freeze
15
+ MSG = 'message'.freeze
16
+
17
+ #
18
+ # The name of the object type.
19
+ #
20
+ def self.typename
21
+ return KEYWORD
22
+ end
23
+
24
+ #
25
+ # The short name of the object type.
26
+ #
27
+ def self.short_typename
28
+ return KEYWORD_SHORT
29
+ end
30
+
31
+ #
32
+ # Get the voice to use.
33
+ #
34
+ def voice_value
35
+ v = find_child VOICE
36
+ return nil unless v
37
+
38
+ return v.value
39
+ end
40
+
41
+ #
42
+ # Get the message to speak.
43
+ #
44
+ def msg_value
45
+ o = find_child MSG
46
+ return nil unless o
47
+
48
+ return o.value
49
+ end
50
+
51
+ # ---------------------------------------------------------------------
52
+ # Children
53
+ # ---------------------------------------------------------------------
54
+
55
+ # Does this object have children to add when an object
56
+ # is created in interactive mode?
57
+ # This does not apply during obj load, etc.
58
+ def add_children_on_create?
59
+ return true
60
+ end
61
+
62
+ # Add children to this object.
63
+ # This is used by containers to add children needed
64
+ # for default configurations.
65
+ def add_default_children
66
+ fac = $engine.factory
67
+ fac.create_string VOICE, '', self
68
+ fac.create_string MSG, 'talk to me', self
69
+ end
70
+
71
+ # ---------------------------------------------------------------------
72
+ # Messages
73
+ # ---------------------------------------------------------------------
74
+
75
+ #
76
+ # Get a list of message names that this object receives.
77
+ #
78
+ def self.messages
79
+ return super + [ 'run' ]
80
+ end
81
+
82
+ # Run the system command.
83
+ def msg_run
84
+ v = voice_value.empty? ? '' : "-v '#{voice_value}'"
85
+ cmd = "say #{v} '#{msg_value}'"
86
+ system cmd
87
+ end
88
+
89
+ # ---------------------------------------------------------------------
90
+ # Help
91
+ # ---------------------------------------------------------------------
92
+
93
+ #
94
+ # Get help for this object type.
95
+ #
96
+ def self.help
97
+ return <<~TEXT
98
+ SAY OBJECT TYPE
99
+ NAME: say
100
+ SHORTCUT: say
101
+
102
+ DESCRIPTION
103
+ Use the Mac text to speach function to say the .
104
+ From the Mac CLI, run this to get a list of voices:
105
+ say -v '?'
106
+
107
+ CHILDREN
108
+ voice - string
109
+ The Voice to use. If left blank, the default voice will be used.
110
+ message - string - 'talk to me'
111
+ The message to speak.
112
+
113
+ MESSAGES
114
+ run - Speak the message, optionally in the voice specified.
115
+ TEXT
116
+ end
117
+
118
+ end
119
+ end
120
+ end
@@ -1,84 +1,165 @@
1
1
  # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
2
  # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
3
  #
4
- # An object that can make a system call.
4
+ # An object that points to a file in the system.
5
5
  #
6
+ require 'tty-pager'
6
7
 
7
8
  module Gloo
8
9
  module Objs
9
10
  class FileHandle < Gloo::Core::Obj
10
-
11
- KEYWORD = 'file'
12
- KEYWORD_SHORT = 'dir'
13
11
 
14
- #
12
+ KEYWORD = 'file'.freeze
13
+ KEYWORD_SHORT = 'dir'.freeze
14
+
15
+ #
15
16
  # The name of the object type.
16
- #
17
+ #
17
18
  def self.typename
18
19
  return KEYWORD
19
20
  end
20
21
 
21
- #
22
+ #
22
23
  # The short name of the object type.
23
- #
24
+ #
24
25
  def self.short_typename
25
26
  return KEYWORD_SHORT
26
27
  end
27
-
28
-
28
+
29
29
  # ---------------------------------------------------------------------
30
30
  # Messages
31
31
  # ---------------------------------------------------------------------
32
32
 
33
- #
33
+ #
34
34
  # Get a list of message names that this object receives.
35
- #
35
+ #
36
36
  def self.messages
37
- return super + [ "read", "write",
38
- "check_exists", "check_is_file", "check_is_dir" ]
37
+ basic = %w[read write]
38
+ checks = %w[check_exists check_is_file check_is_dir]
39
+ show = %w[show page open]
40
+ return super + basic + show + checks
41
+ end
42
+
43
+ #
44
+ # Open the file in the default application for the file type.
45
+ #
46
+ def msg_open
47
+ return unless value && File.exist?( value )
48
+
49
+ cmd = Gloo::Core::GlooSystem.open_for_platform
50
+ cmd_with_param = "#{cmd} \"#{value}\""
51
+ `#{cmd_with_param}`
52
+ end
53
+
54
+ #
55
+ # Show the contents of the file, paginated.
56
+ #
57
+ def msg_page
58
+ return unless value && File.file?( value )
59
+
60
+ pager = TTY::Pager.new
61
+ pager.page( path: value )
62
+ end
63
+
64
+ #
65
+ # Show the contents of the file.
66
+ #
67
+ def msg_show
68
+ return unless value && File.file?( value )
69
+
70
+ puts File.read( value )
71
+ end
72
+
73
+ #
74
+ # Read the contents of the file into the object.
75
+ #
76
+ def msg_read
77
+ return unless value && File.file?( value )
78
+
79
+ data = File.read( value )
80
+ if @params&.token_count&.positive?
81
+ pn = Gloo::Core::Pn.new @params.first
82
+ o = pn.resolve
83
+ o.set_value data
84
+ else
85
+ $engine.heap.it.set_to data
86
+ end
87
+ end
88
+
89
+ #
90
+ # Write the given data out to the file.
91
+ #
92
+ def msg_write
93
+ data = ''
94
+ return unless value
95
+
96
+ if @params&.token_count&.positive?
97
+ expr = Gloo::Expr::Expression.new( @params.tokens )
98
+ data = expr.evaluate
99
+ end
100
+ File.write( value, data )
39
101
  end
40
-
41
- def msg_read
42
- data = ""
43
- if value && File.file?( value )
44
- data = File.read( value )
45
- if @params && @params.token_count > 0
46
- pn = Gloo::Core::Pn.new @params.first
47
- o = pn.resolve
48
- o.set_value data
49
- else
50
- $engine.heap.it.set_to data
51
- end
52
- end
53
- end
54
-
55
- def msg_write
56
- data = ""
57
- if value
58
- if @params && @params.token_count > 0
59
- expr = Gloo::Expr::Expression.new( @params.tokens )
60
- data = expr.evaluate
61
- end
62
- File.write( value, data )
63
- end
64
- end
65
-
102
+
103
+ #
66
104
  # Check to see if the file exists.
105
+ #
67
106
  def msg_check_exists
68
- result = File.exists? value
69
- $engine.heap.it.set_to result
107
+ result = File.exist? value
108
+ $engine.heap.it.set_to result
70
109
  end
71
110
 
72
- # Check to see if the file is a file.
111
+ #
112
+ # Check to see if the file is a file.
113
+ #
73
114
  def msg_check_is_file
74
- result = File.file? value
75
- $engine.heap.it.set_to result
115
+ result = File.file? value
116
+ $engine.heap.it.set_to result
76
117
  end
77
118
 
78
- # Check to see if the file is a directory.
119
+ #
120
+ # Check to see if the file is a directory.
121
+ #
79
122
  def msg_check_is_dir
80
- result = File.directory? value
81
- $engine.heap.it.set_to result
123
+ result = File.directory? value
124
+ $engine.heap.it.set_to result
125
+ end
126
+
127
+ # ---------------------------------------------------------------------
128
+ # Help
129
+ # ---------------------------------------------------------------------
130
+
131
+ #
132
+ # Get help for this object type.
133
+ #
134
+ def self.help
135
+ return <<~TEXT
136
+ FILE OBJECT TYPE
137
+ NAME: file
138
+ SHORTCUT: dir
139
+
140
+ DESCRIPTION
141
+ Reference to a file or folder (directory) on disk.
142
+ The string value of the file object is the path and name
143
+ of the file.
144
+
145
+ CHILDREN
146
+ None.
147
+
148
+ MESSAGES
149
+ read <into.obj> - Read file and put data in the specified object.
150
+ If the <into.obj> is not specified, the data will be in <it>.
151
+ write <from.obj> - Write the data in the <from.object> into
152
+ the file.
153
+ show - Show the contents of the file.
154
+ page - Show the contents of the file, paginated
155
+ open - Open the file with the default application for the type.
156
+ check_exists - Check to see if the file exists.
157
+ <It> will be true or false.
158
+ check_is_file - Check to see if the file specified is a
159
+ regular file. <It> will be true or false.
160
+ check_is_dir - Check to see if the file specified is a
161
+ diretory. <It> will be true or false.
162
+ TEXT
82
163
  end
83
164
 
84
165
  end
@@ -7,57 +7,59 @@
7
7
  module Gloo
8
8
  module Objs
9
9
  class System < Gloo::Core::Obj
10
-
11
- KEYWORD = 'system'
12
- KEYWORD_SHORT = 'sys'
13
- CMD = 'command'
14
- RESULT = 'result'
15
- GET_OUTPUT = 'get_output'
16
-
17
- #
10
+
11
+ KEYWORD = 'system'.freeze
12
+ KEYWORD_SHORT = 'sys'.freeze
13
+ CMD = 'command'.freeze
14
+ RESULT = 'result'.freeze
15
+ GET_OUTPUT = 'get_output'.freeze
16
+
17
+ #
18
18
  # The name of the object type.
19
- #
19
+ #
20
20
  def self.typename
21
21
  return KEYWORD
22
22
  end
23
23
 
24
- #
24
+ #
25
25
  # The short name of the object type.
26
- #
26
+ #
27
27
  def self.short_typename
28
28
  return KEYWORD_SHORT
29
29
  end
30
-
31
- #
30
+
31
+ #
32
32
  # Get the URI from the child object.
33
33
  # Returns nil if there is none.
34
- #
35
- def get_cmd
34
+ #
35
+ def cmd_value
36
36
  cmd = find_child CMD
37
37
  return nil unless cmd
38
+
38
39
  return cmd.value
39
40
  end
40
-
41
- #
41
+
42
+ #
42
43
  # Set the result of the system call.
43
- #
44
- def set_result data
44
+ #
45
+ def set_result( data )
45
46
  r = find_child RESULT
46
47
  return nil unless r
48
+
47
49
  r.set_value data
48
50
  end
49
-
50
- #
51
+
52
+ #
51
53
  # Should the system call get output?
52
54
  # If so, the system call will run and get output,
53
55
  # otherwise it will just get the result of the call.
54
- #
55
- def has_output?
56
+ #
57
+ def output?
56
58
  o = find_child GET_OUTPUT
57
59
  return false unless o
60
+
58
61
  return o.value
59
62
  end
60
-
61
63
 
62
64
  # ---------------------------------------------------------------------
63
65
  # Children
@@ -69,52 +71,96 @@ module Gloo
69
71
  def add_children_on_create?
70
72
  return true
71
73
  end
72
-
74
+
73
75
  # Add children to this object.
74
- # This is used by containers to add children needed
76
+ # This is used by containers to add children needed
75
77
  # for default configurations.
76
78
  def add_default_children
77
79
  fac = $engine.factory
78
- fac.create "command", "string", "date", self
79
- fac.create "get_output", "boolean", true, self
80
- fac.create "result", "string", nil, self
80
+ fac.create( { :name => 'command',
81
+ :type => 'string',
82
+ :value => 'date',
83
+ :parent => self } )
84
+ fac.create( { :name => 'get_output',
85
+ :type => 'boolean',
86
+ :value => true,
87
+ :parent => self } )
88
+ fac.create( { :name => 'result',
89
+ :type => 'string',
90
+ :value => nil,
91
+ :parent => self } )
81
92
  end
82
93
 
83
-
84
94
  # ---------------------------------------------------------------------
85
95
  # Messages
86
96
  # ---------------------------------------------------------------------
87
97
 
88
- #
98
+ #
89
99
  # Get a list of message names that this object receives.
90
- #
100
+ #
91
101
  def self.messages
92
- return super + [ "run" ]
102
+ return super + [ 'run' ]
93
103
  end
94
-
104
+
95
105
  # Run the system command.
96
106
  def msg_run
97
- if has_output?
107
+ if output?
98
108
  run_with_output
99
109
  else
100
110
  run_with_result
101
111
  end
102
112
  end
103
-
113
+
104
114
  def run_with_output
105
- cmd = get_cmd
115
+ cmd = cmd_value
106
116
  return unless cmd
117
+
107
118
  result = `#{cmd}`
108
119
  set_result result
109
120
  end
110
121
 
111
122
  def run_with_result
112
- cmd = get_cmd
123
+ cmd = cmd_value
113
124
  return unless cmd
125
+
114
126
  result = system cmd
115
127
  set_result result
116
128
  end
117
129
 
130
+ # ---------------------------------------------------------------------
131
+ # Help
132
+ # ---------------------------------------------------------------------
133
+
134
+ #
135
+ # Get help for this object type.
136
+ #
137
+ def self.help
138
+ return <<~TEXT
139
+ SYSTEM OBJECT TYPE
140
+ NAME: system
141
+ SHORTCUT: sys
142
+
143
+ DESCRIPTION
144
+ Execute a system command.
145
+
146
+ CHILDREN
147
+ command - string - 'date'
148
+ The command that will be sent to the system.
149
+ get_output - boolean - true
150
+ Should executing the command get the output and put it
151
+ in the result object?
152
+ result - string
153
+ The result of running the command.
154
+ The result will only be set if the 'get_output' child
155
+ is set to true.
156
+
157
+ MESSAGES
158
+ run - Run the system level command.
159
+ Set the result value to the output of the command if the
160
+ 'get_output' child is marked as true.
161
+ TEXT
162
+ end
163
+
118
164
  end
119
165
  end
120
166
  end