gloo 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/.DS_Store +0 -0
  3. data/.rubocop.yml +1 -1
  4. data/Gemfile.lock +80 -81
  5. data/Rakefile +1 -0
  6. data/gloo.gemspec +2 -1
  7. data/lib/gloo/app/engine.rb +48 -3
  8. data/lib/gloo/app/info.rb +1 -1
  9. data/lib/gloo/app/settings.rb +12 -5
  10. data/lib/gloo/convert/string_to_datetime.rb +21 -0
  11. data/lib/gloo/convert/string_to_decimal.rb +20 -0
  12. data/lib/gloo/convert/string_to_integer.rb +20 -0
  13. data/lib/gloo/core/event_manager.rb +2 -6
  14. data/lib/gloo/core/factory.rb +58 -1
  15. data/lib/gloo/core/gloo_system.rb +72 -0
  16. data/lib/gloo/core/obj.rb +50 -1
  17. data/lib/gloo/core/parser.rb +3 -1
  18. data/lib/gloo/core/pn.rb +3 -2
  19. data/lib/gloo/exec/dispatch.rb +30 -0
  20. data/lib/gloo/exec/runner.rb +43 -0
  21. data/lib/gloo/expr/expression.rb +1 -0
  22. data/lib/gloo/expr/l_decimal.rb +34 -0
  23. data/lib/gloo/expr/op_div.rb +2 -0
  24. data/lib/gloo/expr/op_minus.rb +2 -0
  25. data/lib/gloo/expr/op_mult.rb +2 -0
  26. data/lib/gloo/expr/op_plus.rb +2 -0
  27. data/lib/gloo/objs/basic/alias.rb +111 -0
  28. data/lib/gloo/objs/basic/container.rb +11 -1
  29. data/lib/gloo/objs/basic/decimal.rb +96 -0
  30. data/lib/gloo/objs/basic/integer.rb +5 -0
  31. data/lib/gloo/objs/basic/string.rb +9 -1
  32. data/lib/gloo/objs/basic/text.rb +27 -2
  33. data/lib/gloo/objs/cli/banner.rb +137 -0
  34. data/lib/gloo/objs/cli/bar.rb +141 -0
  35. data/lib/gloo/objs/cli/colorize.rb +1 -1
  36. data/lib/gloo/objs/cli/menu.rb +236 -0
  37. data/lib/gloo/objs/cli/menu_item.rb +128 -0
  38. data/lib/gloo/objs/cli/pastel.rb +120 -0
  39. data/lib/gloo/objs/cli/prompt.rb +19 -11
  40. data/lib/gloo/objs/cli/select.rb +153 -0
  41. data/lib/gloo/objs/ctrl/each.rb +45 -16
  42. data/lib/gloo/objs/ctrl/repeat.rb +129 -0
  43. data/lib/gloo/objs/data/markdown.rb +109 -0
  44. data/lib/gloo/objs/data/table.rb +168 -0
  45. data/lib/gloo/objs/dt/date.rb +72 -0
  46. data/lib/gloo/objs/dt/datetime.rb +84 -0
  47. data/lib/gloo/objs/dt/time.rb +72 -0
  48. data/lib/gloo/objs/ror/erb.rb +1 -0
  49. data/lib/gloo/objs/system/file_handle.rb +50 -1
  50. data/lib/gloo/objs/web/http_get.rb +24 -4
  51. data/lib/gloo/objs/web/http_post.rb +1 -0
  52. data/lib/gloo/objs/web/json.rb +155 -0
  53. data/lib/gloo/objs/web/uri.rb +160 -0
  54. data/lib/gloo/persist/file_loader.rb +17 -6
  55. data/lib/gloo/persist/line_splitter.rb +7 -2
  56. data/lib/gloo/persist/persist_man.rb +37 -13
  57. data/lib/gloo/verbs/cls.rb +67 -0
  58. data/lib/gloo/verbs/help.rb +9 -0
  59. data/lib/gloo/verbs/if.rb +1 -0
  60. data/lib/gloo/verbs/load.rb +3 -2
  61. data/lib/gloo/verbs/move.rb +128 -0
  62. data/lib/gloo/verbs/run.rb +21 -7
  63. data/lib/gloo/verbs/tell.rb +1 -1
  64. data/lib/gloo/verbs/unless.rb +1 -0
  65. data/lib/gloo/verbs/wait.rb +73 -0
  66. metadata +36 -5
  67. data/lib/gloo/core/runner.rb +0 -26
@@ -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
+ # Show colorized output with the pastel gem.
5
+ #
6
+ require 'pastel'
7
+
8
+ module Gloo
9
+ module Objs
10
+ class Pastel < Gloo::Core::Obj
11
+
12
+ KEYWORD = 'pastel'.freeze
13
+ KEYWORD_SHORT = 'pastel'.freeze
14
+ TEXT = 'text'.freeze
15
+ COLOR = 'color'.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 text from the child object.
33
+ #
34
+ def text_value
35
+ o = find_child TEXT
36
+ return '' unless o
37
+
38
+ return o.value
39
+ end
40
+
41
+ #
42
+ # Get the color from the child object.
43
+ #
44
+ def color_value
45
+ o = find_child COLOR
46
+ return '' 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 TEXT, '', self
68
+ fac.create_string COLOR, '', 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 + %w[show]
80
+ end
81
+
82
+ #
83
+ # Show the banner bar
84
+ #
85
+ def msg_show
86
+ pastel = ::Pastel.new
87
+ c = self.color_value.split( ' ' ).map( &:to_sym )
88
+ puts pastel.decorate( self.text_value, *c )
89
+ end
90
+
91
+ # ---------------------------------------------------------------------
92
+ # Help
93
+ # ---------------------------------------------------------------------
94
+
95
+ #
96
+ # Get help for this object type.
97
+ #
98
+ def self.help
99
+ return <<~TEXT
100
+ PASTEL OBJECT TYPE
101
+ NAME: pastel
102
+ SHORTCUT: pastel
103
+
104
+ DESCRIPTION
105
+ Show colorized text with the pastel gem.
106
+
107
+ CHILDREN
108
+ text - string
109
+ The text that will be colorized.
110
+ color - string
111
+ The colors. See pastel for options.
112
+
113
+ MESSAGES
114
+ show - Show the colorized text.
115
+ TEXT
116
+ end
117
+
118
+ end
119
+ end
120
+ end
@@ -28,7 +28,7 @@ module Gloo
28
28
  end
29
29
 
30
30
  #
31
- # Get the URI from the child object.
31
+ # Get the prompt from the child object.
32
32
  # Returns nil if there is none.
33
33
  #
34
34
  def prompt_value
@@ -64,14 +64,8 @@ module Gloo
64
64
  # for default configurations.
65
65
  def add_default_children
66
66
  fac = $engine.factory
67
- fac.create( { :name => 'prompt',
68
- :type => 'string',
69
- :value => '> ',
70
- :parent => self } )
71
- fac.create( { :name => 'result',
72
- :type => 'string',
73
- :value => nil,
74
- :parent => self } )
67
+ fac.create_string PROMPT, '>', self
68
+ fac.create_string RESULT, nil, self
75
69
  end
76
70
 
77
71
  # ---------------------------------------------------------------------
@@ -82,10 +76,23 @@ module Gloo
82
76
  # Get a list of message names that this object receives.
83
77
  #
84
78
  def self.messages
85
- return super + [ 'run' ]
79
+ return super + %w[run multiline]
86
80
  end
87
81
 
88
- # Run the system command.
82
+ #
83
+ # Show a multiline prompt and get the user's input.
84
+ #
85
+ def msg_multiline
86
+ prompt = prompt_value
87
+ return unless prompt
88
+
89
+ result = $prompt.multiline( prompt )
90
+ set_result result.join
91
+ end
92
+
93
+ #
94
+ # Show the prompt and get the user's input.
95
+ #
89
96
  def msg_run
90
97
  prompt = prompt_value
91
98
  return unless prompt
@@ -118,6 +125,7 @@ module Gloo
118
125
 
119
126
  MESSAGES
120
127
  run - Prompt the user and then set the result.
128
+ multiline - Show a multiline prompt.
121
129
  TEXT
122
130
  end
123
131
 
@@ -0,0 +1,153 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # Show a CLI prompt and user selection from a list.
5
+ #
6
+
7
+ module Gloo
8
+ module Objs
9
+ class Select < Gloo::Core::Obj
10
+
11
+ KEYWORD = 'select'.freeze
12
+ KEYWORD_SHORT = 'sel'.freeze
13
+ PROMPT = 'prompt'.freeze
14
+ OPTIONS = 'options'.freeze
15
+ RESULT = 'result'.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 prompt from the child object.
33
+ # Returns nil if there is none.
34
+ #
35
+ def prompt_value
36
+ o = find_child PROMPT
37
+ return nil unless o
38
+
39
+ return o.value
40
+ end
41
+
42
+ #
43
+ # Get the list of options for selection.
44
+ #
45
+ def options
46
+ o = find_child OPTIONS
47
+ return [] unless o
48
+
49
+ return o.children.map( &:name )
50
+ end
51
+
52
+ #
53
+ # Get the value of the selected item.
54
+ #
55
+ def key_for_option( selected )
56
+ o = find_child OPTIONS
57
+ return nil unless o
58
+
59
+ o.children.each do |c|
60
+ return c.value if c.name == selected
61
+ end
62
+
63
+ return nil
64
+ end
65
+
66
+ #
67
+ # Set the result of the system call.
68
+ #
69
+ def set_result( data )
70
+ r = find_child RESULT
71
+ return nil unless r
72
+
73
+ r.set_value data
74
+ end
75
+
76
+ # ---------------------------------------------------------------------
77
+ # Children
78
+ # ---------------------------------------------------------------------
79
+
80
+ # Does this object have children to add when an object
81
+ # is created in interactive mode?
82
+ # This does not apply during obj load, etc.
83
+ def add_children_on_create?
84
+ return true
85
+ end
86
+
87
+ # Add children to this object.
88
+ # This is used by containers to add children needed
89
+ # for default configurations.
90
+ def add_default_children
91
+ fac = $engine.factory
92
+ fac.create_string PROMPT, '>', self
93
+ fac.create_can OPTIONS, self
94
+ fac.create_string RESULT, nil, self
95
+ end
96
+
97
+ # ---------------------------------------------------------------------
98
+ # Messages
99
+ # ---------------------------------------------------------------------
100
+
101
+ #
102
+ # Get a list of message names that this object receives.
103
+ #
104
+ def self.messages
105
+ return super + %w[run]
106
+ end
107
+
108
+ #
109
+ # Show the prompt and get the user's selection.
110
+ #
111
+ def msg_run
112
+ prompt = prompt_value
113
+ return unless prompt
114
+
115
+ per = Gloo::App::Settings.page_size
116
+ result = $prompt.select( prompt, options, :per_page => per )
117
+ set_result self.key_for_option( result )
118
+ end
119
+
120
+ # ---------------------------------------------------------------------
121
+ # Help
122
+ # ---------------------------------------------------------------------
123
+
124
+ #
125
+ # Get help for this object type.
126
+ #
127
+ def self.help
128
+ return <<~TEXT
129
+ SELECT OBJECT TYPE
130
+ NAME: select
131
+ SHORTCUT: sel
132
+
133
+ DESCRIPTION
134
+ Prompt for user to select from a list of options.
135
+
136
+ CHILDREN
137
+ prompt - string - '> '
138
+ The prompt displayed to the user.
139
+ options - container
140
+ The list of options for the selection list.
141
+ The name of each option will be presented to the user, but
142
+ the value will be put in the result.
143
+ result - string - none
144
+ The result with the user's selection.
145
+
146
+ MESSAGES
147
+ run - Prompt the user for a selection and then set the result.
148
+ TEXT
149
+ end
150
+
151
+ end
152
+ end
153
+ end
@@ -15,6 +15,7 @@ module Gloo
15
15
 
16
16
  KEYWORD = 'each'.freeze
17
17
  KEYWORD_SHORT = 'each'.freeze
18
+ CHILD = 'child'.freeze
18
19
  WORD = 'word'.freeze
19
20
  LINE = 'line'.freeze
20
21
  FILE = 'file'.freeze
@@ -48,7 +49,9 @@ module Gloo
48
49
  # Run the do script once.
49
50
  def run_do
50
51
  o = find_child DO
51
- o.send_message( 'run' ) if o.can_receive_message? 'run'
52
+ return unless o
53
+
54
+ Gloo::Exec::Dispatch.message 'run', o
52
55
  end
53
56
 
54
57
  # ---------------------------------------------------------------------
@@ -67,18 +70,9 @@ module Gloo
67
70
  # for default configurations.
68
71
  def add_default_children
69
72
  fac = $engine.factory
70
- fac.create( { :name => 'word',
71
- :type => 'string',
72
- :value => '',
73
- :parent => self } )
74
- fac.create( { :name => 'in',
75
- :type => 'string',
76
- :value => '',
77
- :parent => self } )
78
- fac.create( { :name => 'do',
79
- :type => 'script',
80
- :value => '',
81
- :parent => self } )
73
+ fac.create_string WORD, '', self
74
+ fac.create_string IN, '', self
75
+ fac.create_script DO, '', self
82
76
  end
83
77
 
84
78
  # ---------------------------------------------------------------------
@@ -94,7 +88,9 @@ module Gloo
94
88
 
95
89
  # Run the system command.
96
90
  def msg_run
97
- if each_word?
91
+ if each_child?
92
+ run_each_child
93
+ elsif each_word?
98
94
  run_each_word
99
95
  elsif each_line?
100
96
  run_each_line
@@ -103,6 +99,39 @@ module Gloo
103
99
  end
104
100
  end
105
101
 
102
+ # ---------------------------------------------------------------------
103
+ # Child Object
104
+ # ---------------------------------------------------------------------
105
+
106
+ # Is it set up to run for each word?
107
+ # If there is a child object by the name "word"
108
+ # then we will loop for each word in the string.
109
+ def each_child?
110
+ return true if contains_child? CHILD
111
+
112
+ return false
113
+ end
114
+
115
+ # Run for each word.
116
+ def run_each_child
117
+ o = find_child IN
118
+ return unless o
119
+
120
+ o = Gloo::Objs::Alias.resolve_alias( o )
121
+ o.children.each do |child|
122
+ set_child child
123
+ run_do
124
+ end
125
+ end
126
+
127
+ # Set the child alias.
128
+ def set_child( obj )
129
+ o = find_child CHILD
130
+ return unless o
131
+
132
+ o.set_value obj.pn
133
+ end
134
+
106
135
  # ---------------------------------------------------------------------
107
136
  # Word
108
137
  # ---------------------------------------------------------------------
@@ -153,7 +182,7 @@ module Gloo
153
182
  str = in_value
154
183
  return unless str
155
184
 
156
- str.split( '\n' ).each do |line|
185
+ str.each_line do |line|
157
186
  set_line line
158
187
  run_do
159
188
  end
@@ -229,7 +258,7 @@ module Gloo
229
258
  Perform an action for each item in a collection.
230
259
 
231
260
  CHILDREN
232
- word | line | repo - string - none
261
+ child | word | line | repo - string - none
233
262
  The entity we want to loop for.
234
263
  It will hold the current value while the script is running.
235
264
  in - string - none
@@ -0,0 +1,129 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # A looping construct...do something x times.
5
+ #
6
+
7
+ module Gloo
8
+ module Objs
9
+ class Repeat < Gloo::Core::Obj
10
+
11
+ KEYWORD = 'repeat'.freeze
12
+ KEYWORD_SHORT = 'repeat'.freeze
13
+ TIMES = 'times'.freeze
14
+ INDEX = 'index'.freeze
15
+ DO = 'do'.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 URI from the child object.
33
+ # Returns nil if there is none.
34
+ #
35
+ def times
36
+ o = find_child TIMES
37
+ return o ? o.value : 0
38
+ end
39
+
40
+ # Run the do script once.
41
+ def run_do
42
+ o = find_child DO
43
+ return unless o
44
+
45
+ Gloo::Exec::Dispatch.message 'run', o
46
+ end
47
+
48
+ # Set the index of the current iteration.
49
+ def set_index( index )
50
+ o = find_child INDEX
51
+ return unless o
52
+
53
+ o.set_value index
54
+ end
55
+
56
+ # ---------------------------------------------------------------------
57
+ # Children
58
+ # ---------------------------------------------------------------------
59
+
60
+ # Does this object have children to add when an object
61
+ # is created in interactive mode?
62
+ # This does not apply during obj load, etc.
63
+ def add_children_on_create?
64
+ return true
65
+ end
66
+
67
+ # Add children to this object.
68
+ # This is used by containers to add children needed
69
+ # for default configurations.
70
+ def add_default_children
71
+ fac = $engine.factory
72
+ fac.create_int TIMES, 0, self
73
+ fac.create_int INDEX, 0, self
74
+ fac.create_script DO, '', self
75
+ end
76
+
77
+ # ---------------------------------------------------------------------
78
+ # Messages
79
+ # ---------------------------------------------------------------------
80
+
81
+ #
82
+ # Get a list of message names that this object receives.
83
+ #
84
+ def self.messages
85
+ return super + [ 'run' ]
86
+ end
87
+
88
+ #
89
+ # Run the repeat loop.
90
+ #
91
+ def msg_run
92
+ times.times do |index|
93
+ set_index index
94
+ run_do
95
+ end
96
+ end
97
+
98
+ # ---------------------------------------------------------------------
99
+ # Help
100
+ # ---------------------------------------------------------------------
101
+
102
+ #
103
+ # Get help for this object type.
104
+ #
105
+ def self.help
106
+ return <<~TEXT
107
+ REPEAT OBJECT TYPE
108
+ NAME: repeat
109
+ SHORTCUT: repeat
110
+
111
+ DESCRIPTION
112
+ Run a script a given number of times.
113
+
114
+ CHILDREN
115
+ times integer - 0
116
+ The number of times to run the script.
117
+ index integer - 0
118
+ The current iteration when the repeat loop is running.
119
+ do - script - none
120
+ The action we want to perform for iteration of the loop.
121
+
122
+ MESSAGES
123
+ run - Run the script for the given number of times.
124
+ TEXT
125
+ end
126
+
127
+ end
128
+ end
129
+ end