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.
- checksums.yaml +4 -4
- data/.DS_Store +0 -0
- data/.rubocop.yml +73 -0
- data/Gemfile +2 -2
- data/Gemfile.lock +86 -83
- data/Rakefile +7 -6
- data/bin/console +4 -4
- data/gloo.gemspec +22 -18
- data/lib/gloo.rb +6 -6
- data/lib/gloo/app/args.rb +30 -31
- data/lib/gloo/app/engine.rb +80 -30
- data/lib/gloo/app/help.rb +17 -11
- data/lib/gloo/app/info.rb +3 -3
- data/lib/gloo/app/log.rb +17 -17
- data/lib/gloo/app/mode.rb +4 -4
- data/lib/gloo/app/settings.rb +51 -41
- data/lib/gloo/convert/string_to_datetime.rb +21 -0
- data/lib/gloo/convert/string_to_decimal.rb +20 -0
- data/lib/gloo/convert/string_to_integer.rb +20 -0
- data/lib/gloo/core/baseo.rb +7 -7
- data/lib/gloo/core/dictionary.rb +30 -27
- data/lib/gloo/core/error.rb +50 -0
- data/lib/gloo/core/event_manager.rb +17 -23
- data/lib/gloo/core/factory.rb +149 -39
- data/lib/gloo/core/gloo_system.rb +121 -54
- data/lib/gloo/core/heap.rb +15 -13
- data/lib/gloo/core/it.rb +5 -5
- data/lib/gloo/core/literal.rb +7 -7
- data/lib/gloo/core/obj.rb +138 -79
- data/lib/gloo/core/obj_finder.rb +9 -14
- data/lib/gloo/core/op.rb +8 -8
- data/lib/gloo/core/parser.rb +27 -26
- data/lib/gloo/core/pn.rb +68 -52
- data/lib/gloo/core/script.rb +7 -7
- data/lib/gloo/core/tokens.rb +39 -41
- data/lib/gloo/core/verb.rb +30 -19
- data/lib/gloo/exec/dispatch.rb +30 -0
- data/lib/gloo/exec/runner.rb +43 -0
- data/lib/gloo/expr/expression.rb +36 -43
- data/lib/gloo/expr/l_boolean.rb +7 -6
- data/lib/gloo/expr/l_decimal.rb +34 -0
- data/lib/gloo/expr/l_integer.rb +5 -4
- data/lib/gloo/expr/l_string.rb +13 -15
- data/lib/gloo/expr/op_div.rb +5 -5
- data/lib/gloo/expr/op_minus.rb +5 -5
- data/lib/gloo/expr/op_mult.rb +5 -5
- data/lib/gloo/expr/op_plus.rb +7 -7
- data/lib/gloo/objs/basic/alias.rb +111 -0
- data/lib/gloo/objs/basic/boolean.rb +63 -38
- data/lib/gloo/objs/basic/container.rb +71 -12
- data/lib/gloo/objs/basic/decimal.rb +96 -0
- data/lib/gloo/objs/basic/integer.rb +45 -16
- data/lib/gloo/objs/basic/script.rb +62 -38
- data/lib/gloo/objs/basic/string.rb +47 -15
- data/lib/gloo/objs/basic/text.rb +69 -21
- data/lib/gloo/objs/basic/untyped.rb +35 -10
- data/lib/gloo/objs/cli/banner.rb +137 -0
- data/lib/gloo/objs/cli/bar.rb +141 -0
- data/lib/gloo/objs/cli/colorize.rb +54 -24
- data/lib/gloo/objs/cli/confirm.rb +63 -29
- data/lib/gloo/objs/cli/menu.rb +236 -0
- data/lib/gloo/objs/cli/menu_item.rb +128 -0
- data/lib/gloo/objs/cli/pastel.rb +120 -0
- data/lib/gloo/objs/cli/prompt.rb +73 -31
- data/lib/gloo/objs/cli/select.rb +153 -0
- data/lib/gloo/objs/ctrl/each.rb +128 -61
- data/lib/gloo/objs/ctrl/repeat.rb +129 -0
- data/lib/gloo/objs/data/markdown.rb +109 -0
- data/lib/gloo/objs/data/table.rb +168 -0
- data/lib/gloo/objs/dev/git.rb +98 -64
- data/lib/gloo/objs/dt/date.rb +72 -0
- data/lib/gloo/objs/dt/datetime.rb +84 -0
- data/lib/gloo/objs/dt/time.rb +72 -0
- data/lib/gloo/objs/ror/erb.rb +82 -41
- data/lib/gloo/objs/ror/eval.rb +73 -31
- data/lib/gloo/objs/snd/play.rb +71 -0
- data/lib/gloo/objs/snd/say.rb +120 -0
- data/lib/gloo/objs/system/file_handle.rb +129 -48
- data/lib/gloo/objs/system/system.rb +84 -38
- data/lib/gloo/objs/web/http_get.rb +103 -46
- data/lib/gloo/objs/web/http_post.rb +70 -44
- data/lib/gloo/objs/web/json.rb +155 -0
- data/lib/gloo/objs/web/slack.rb +89 -58
- data/lib/gloo/objs/web/teams.rb +88 -53
- data/lib/gloo/objs/web/uri.rb +160 -0
- data/lib/gloo/persist/file_loader.rb +95 -85
- data/lib/gloo/persist/file_saver.rb +12 -12
- data/lib/gloo/persist/file_storage.rb +15 -15
- data/lib/gloo/persist/line_splitter.rb +79 -0
- data/lib/gloo/persist/persist_man.rb +63 -39
- data/lib/gloo/utils/words.rb +2 -2
- data/lib/gloo/verbs/alert.rb +67 -16
- data/lib/gloo/verbs/beep.rb +70 -0
- data/lib/gloo/verbs/cls.rb +67 -0
- data/lib/gloo/verbs/context.rb +61 -21
- data/lib/gloo/verbs/create.rb +52 -21
- data/lib/gloo/verbs/help.rb +186 -27
- data/lib/gloo/verbs/if.rb +55 -21
- data/lib/gloo/verbs/list.rb +55 -24
- data/lib/gloo/verbs/load.rb +47 -12
- data/lib/gloo/verbs/move.rb +128 -0
- data/lib/gloo/verbs/put.rb +90 -34
- data/lib/gloo/verbs/quit.rb +43 -12
- data/lib/gloo/verbs/run.rb +63 -18
- data/lib/gloo/verbs/save.rb +45 -10
- data/lib/gloo/verbs/show.rb +56 -22
- data/lib/gloo/verbs/tell.rb +45 -13
- data/lib/gloo/verbs/unless.rb +56 -21
- data/lib/gloo/verbs/version.rb +42 -12
- data/lib/gloo/verbs/wait.rb +73 -0
- data/lib/run.rb +5 -5
- metadata +90 -12
|
@@ -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
|
data/lib/gloo/objs/cli/prompt.rb
CHANGED
|
@@ -7,45 +7,46 @@
|
|
|
7
7
|
module Gloo
|
|
8
8
|
module Objs
|
|
9
9
|
class Prompt < Gloo::Core::Obj
|
|
10
|
-
|
|
11
|
-
KEYWORD = 'prompt'
|
|
12
|
-
KEYWORD_SHORT = 'ask'
|
|
13
|
-
PROMPT = 'prompt'
|
|
14
|
-
RESULT = 'result'
|
|
15
10
|
|
|
16
|
-
|
|
11
|
+
KEYWORD = 'prompt'.freeze
|
|
12
|
+
KEYWORD_SHORT = 'ask'.freeze
|
|
13
|
+
PROMPT = 'prompt'.freeze
|
|
14
|
+
RESULT = 'result'.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
|
-
|
|
30
|
-
#
|
|
31
|
-
# Get the
|
|
29
|
+
|
|
30
|
+
#
|
|
31
|
+
# Get the prompt from the child object.
|
|
32
32
|
# Returns nil if there is none.
|
|
33
|
-
#
|
|
34
|
-
def
|
|
33
|
+
#
|
|
34
|
+
def prompt_value
|
|
35
35
|
o = find_child PROMPT
|
|
36
36
|
return nil unless o
|
|
37
|
+
|
|
37
38
|
return o.value
|
|
38
39
|
end
|
|
39
|
-
|
|
40
|
-
#
|
|
40
|
+
|
|
41
|
+
#
|
|
41
42
|
# Set the result of the system call.
|
|
42
|
-
#
|
|
43
|
-
def set_result data
|
|
43
|
+
#
|
|
44
|
+
def set_result( data )
|
|
44
45
|
r = find_child RESULT
|
|
45
46
|
return nil unless r
|
|
47
|
+
|
|
46
48
|
r.set_value data
|
|
47
49
|
end
|
|
48
|
-
|
|
49
50
|
|
|
50
51
|
# ---------------------------------------------------------------------
|
|
51
52
|
# Children
|
|
@@ -57,36 +58,77 @@ module Gloo
|
|
|
57
58
|
def add_children_on_create?
|
|
58
59
|
return true
|
|
59
60
|
end
|
|
60
|
-
|
|
61
|
+
|
|
61
62
|
# Add children to this object.
|
|
62
|
-
# This is used by containers to add children needed
|
|
63
|
+
# This is used by containers to add children needed
|
|
63
64
|
# for default configurations.
|
|
64
65
|
def add_default_children
|
|
65
66
|
fac = $engine.factory
|
|
66
|
-
fac.
|
|
67
|
-
fac.
|
|
67
|
+
fac.create_string PROMPT, '>', self
|
|
68
|
+
fac.create_string RESULT, nil, self
|
|
68
69
|
end
|
|
69
70
|
|
|
70
|
-
|
|
71
71
|
# ---------------------------------------------------------------------
|
|
72
72
|
# Messages
|
|
73
73
|
# ---------------------------------------------------------------------
|
|
74
74
|
|
|
75
|
-
#
|
|
75
|
+
#
|
|
76
76
|
# Get a list of message names that this object receives.
|
|
77
|
-
#
|
|
77
|
+
#
|
|
78
78
|
def self.messages
|
|
79
|
-
return super + [
|
|
79
|
+
return super + %w[run multiline]
|
|
80
80
|
end
|
|
81
|
-
|
|
82
|
-
#
|
|
81
|
+
|
|
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
|
+
#
|
|
83
96
|
def msg_run
|
|
84
|
-
prompt =
|
|
97
|
+
prompt = prompt_value
|
|
85
98
|
return unless prompt
|
|
99
|
+
|
|
86
100
|
result = $prompt.ask( prompt )
|
|
87
101
|
set_result result
|
|
88
102
|
end
|
|
89
|
-
|
|
103
|
+
|
|
104
|
+
# ---------------------------------------------------------------------
|
|
105
|
+
# Help
|
|
106
|
+
# ---------------------------------------------------------------------
|
|
107
|
+
|
|
108
|
+
#
|
|
109
|
+
# Get help for this object type.
|
|
110
|
+
#
|
|
111
|
+
def self.help
|
|
112
|
+
return <<~TEXT
|
|
113
|
+
PROMPT OBJECT TYPE
|
|
114
|
+
NAME: prompt
|
|
115
|
+
SHORTCUT: ask
|
|
116
|
+
|
|
117
|
+
DESCRIPTION
|
|
118
|
+
CLI prompt for user input.
|
|
119
|
+
|
|
120
|
+
CHILDREN
|
|
121
|
+
prompt - string - '> '
|
|
122
|
+
The prompt displayed to the user.
|
|
123
|
+
result - string - none
|
|
124
|
+
The result with the user's input.
|
|
125
|
+
|
|
126
|
+
MESSAGES
|
|
127
|
+
run - Prompt the user and then set the result.
|
|
128
|
+
multiline - Show a multiline prompt.
|
|
129
|
+
TEXT
|
|
130
|
+
end
|
|
131
|
+
|
|
90
132
|
end
|
|
91
133
|
end
|
|
92
134
|
end
|
|
@@ -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
|
data/lib/gloo/objs/ctrl/each.rb
CHANGED
|
@@ -12,49 +12,47 @@
|
|
|
12
12
|
module Gloo
|
|
13
13
|
module Objs
|
|
14
14
|
class Each < Gloo::Core::Obj
|
|
15
|
-
|
|
16
|
-
KEYWORD = 'each'
|
|
17
|
-
KEYWORD_SHORT = 'each'
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
15
|
+
|
|
16
|
+
KEYWORD = 'each'.freeze
|
|
17
|
+
KEYWORD_SHORT = 'each'.freeze
|
|
18
|
+
CHILD = 'child'.freeze
|
|
19
|
+
WORD = 'word'.freeze
|
|
20
|
+
LINE = 'line'.freeze
|
|
21
|
+
FILE = 'file'.freeze
|
|
22
|
+
REPO = 'repo'.freeze
|
|
23
|
+
IN = 'IN'.freeze
|
|
24
|
+
DO = 'do'.freeze
|
|
25
|
+
|
|
26
|
+
#
|
|
26
27
|
# The name of the object type.
|
|
27
|
-
#
|
|
28
|
+
#
|
|
28
29
|
def self.typename
|
|
29
30
|
return KEYWORD
|
|
30
31
|
end
|
|
31
32
|
|
|
32
|
-
#
|
|
33
|
+
#
|
|
33
34
|
# The short name of the object type.
|
|
34
|
-
#
|
|
35
|
+
#
|
|
35
36
|
def self.short_typename
|
|
36
37
|
return KEYWORD_SHORT
|
|
37
38
|
end
|
|
38
|
-
|
|
39
|
-
#
|
|
39
|
+
|
|
40
|
+
#
|
|
40
41
|
# Get the URI from the child object.
|
|
41
42
|
# Returns nil if there is none.
|
|
42
|
-
#
|
|
43
|
-
def
|
|
43
|
+
#
|
|
44
|
+
def in_value
|
|
44
45
|
o = find_child IN
|
|
45
|
-
return
|
|
46
|
-
return o.value
|
|
46
|
+
return o ? o.value : nil
|
|
47
47
|
end
|
|
48
|
-
|
|
48
|
+
|
|
49
49
|
# Run the do script once.
|
|
50
50
|
def run_do
|
|
51
51
|
o = find_child DO
|
|
52
|
-
|
|
53
|
-
o.send_message "run"
|
|
54
|
-
end
|
|
55
|
-
end
|
|
52
|
+
return unless o
|
|
56
53
|
|
|
57
|
-
|
|
54
|
+
Gloo::Exec::Dispatch.message 'run', o
|
|
55
|
+
end
|
|
58
56
|
|
|
59
57
|
# ---------------------------------------------------------------------
|
|
60
58
|
# Children
|
|
@@ -66,32 +64,33 @@ module Gloo
|
|
|
66
64
|
def add_children_on_create?
|
|
67
65
|
return true
|
|
68
66
|
end
|
|
69
|
-
|
|
67
|
+
|
|
70
68
|
# Add children to this object.
|
|
71
|
-
# This is used by containers to add children needed
|
|
69
|
+
# This is used by containers to add children needed
|
|
72
70
|
# for default configurations.
|
|
73
71
|
def add_default_children
|
|
74
72
|
fac = $engine.factory
|
|
75
|
-
fac.
|
|
76
|
-
fac.
|
|
77
|
-
fac.
|
|
73
|
+
fac.create_string WORD, '', self
|
|
74
|
+
fac.create_string IN, '', self
|
|
75
|
+
fac.create_script DO, '', self
|
|
78
76
|
end
|
|
79
77
|
|
|
80
|
-
|
|
81
78
|
# ---------------------------------------------------------------------
|
|
82
79
|
# Messages
|
|
83
80
|
# ---------------------------------------------------------------------
|
|
84
81
|
|
|
85
|
-
#
|
|
82
|
+
#
|
|
86
83
|
# Get a list of message names that this object receives.
|
|
87
|
-
#
|
|
84
|
+
#
|
|
88
85
|
def self.messages
|
|
89
|
-
return super + [
|
|
86
|
+
return super + [ 'run' ]
|
|
90
87
|
end
|
|
91
|
-
|
|
88
|
+
|
|
92
89
|
# Run the system command.
|
|
93
90
|
def msg_run
|
|
94
|
-
if
|
|
91
|
+
if each_child?
|
|
92
|
+
run_each_child
|
|
93
|
+
elsif each_word?
|
|
95
94
|
run_each_word
|
|
96
95
|
elsif each_line?
|
|
97
96
|
run_each_line
|
|
@@ -99,8 +98,40 @@ module Gloo
|
|
|
99
98
|
run_each_repo
|
|
100
99
|
end
|
|
101
100
|
end
|
|
102
|
-
|
|
103
|
-
|
|
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
|
+
|
|
104
135
|
# ---------------------------------------------------------------------
|
|
105
136
|
# Word
|
|
106
137
|
# ---------------------------------------------------------------------
|
|
@@ -109,28 +140,29 @@ module Gloo
|
|
|
109
140
|
# If there is a child object by the name "word"
|
|
110
141
|
# then we will loop for each word in the string.
|
|
111
142
|
def each_word?
|
|
112
|
-
|
|
113
|
-
|
|
143
|
+
return true if find_child WORD
|
|
144
|
+
|
|
114
145
|
return false
|
|
115
146
|
end
|
|
116
147
|
|
|
117
148
|
# Run for each word.
|
|
118
149
|
def run_each_word
|
|
119
|
-
str =
|
|
150
|
+
str = in_value
|
|
120
151
|
return unless str
|
|
121
|
-
|
|
152
|
+
|
|
153
|
+
str.split( ' ' ).each do |word|
|
|
122
154
|
set_word word
|
|
123
155
|
run_do
|
|
124
156
|
end
|
|
125
157
|
end
|
|
126
|
-
|
|
158
|
+
|
|
127
159
|
# Set the value of the word.
|
|
128
|
-
def set_word word
|
|
160
|
+
def set_word( word )
|
|
129
161
|
o = find_child WORD
|
|
130
162
|
return unless o
|
|
163
|
+
|
|
131
164
|
o.set_value word
|
|
132
165
|
end
|
|
133
|
-
|
|
134
166
|
|
|
135
167
|
# ---------------------------------------------------------------------
|
|
136
168
|
# Line
|
|
@@ -140,30 +172,30 @@ module Gloo
|
|
|
140
172
|
# If there is a child object by the name "line"
|
|
141
173
|
# then we will loop for each line in the string.
|
|
142
174
|
def each_line?
|
|
143
|
-
|
|
144
|
-
|
|
175
|
+
return true if find_child LINE
|
|
176
|
+
|
|
145
177
|
return false
|
|
146
178
|
end
|
|
147
|
-
|
|
179
|
+
|
|
148
180
|
# Run for each line.
|
|
149
181
|
def run_each_line
|
|
150
|
-
str =
|
|
182
|
+
str = in_value
|
|
151
183
|
return unless str
|
|
152
|
-
|
|
184
|
+
|
|
185
|
+
str.each_line do |line|
|
|
153
186
|
set_line line
|
|
154
187
|
run_do
|
|
155
188
|
end
|
|
156
189
|
end
|
|
157
|
-
|
|
190
|
+
|
|
158
191
|
# Set the value of the word.
|
|
159
|
-
def set_line line
|
|
192
|
+
def set_line( line )
|
|
160
193
|
o = find_child LINE
|
|
161
194
|
return unless o
|
|
195
|
+
|
|
162
196
|
o.set_value line
|
|
163
197
|
end
|
|
164
198
|
|
|
165
|
-
|
|
166
|
-
|
|
167
199
|
# ---------------------------------------------------------------------
|
|
168
200
|
# Git Repo
|
|
169
201
|
# ---------------------------------------------------------------------
|
|
@@ -172,11 +204,11 @@ module Gloo
|
|
|
172
204
|
# If there is a child object by the name "repo"
|
|
173
205
|
# then we will loop for each repo in the directory.
|
|
174
206
|
def each_repo?
|
|
175
|
-
|
|
176
|
-
|
|
207
|
+
return true if find_child REPO
|
|
208
|
+
|
|
177
209
|
return false
|
|
178
210
|
end
|
|
179
|
-
|
|
211
|
+
|
|
180
212
|
def find_all_git_projects( path )
|
|
181
213
|
path.children.collect do |f|
|
|
182
214
|
if f.directory? && ( File.basename( f ) == '.git' )
|
|
@@ -189,8 +221,9 @@ module Gloo
|
|
|
189
221
|
|
|
190
222
|
# Run for each line.
|
|
191
223
|
def run_each_repo
|
|
192
|
-
path =
|
|
224
|
+
path = in_value
|
|
193
225
|
return unless path
|
|
226
|
+
|
|
194
227
|
path = Pathname.new( path )
|
|
195
228
|
repos = find_all_git_projects( path )
|
|
196
229
|
repos.each do |o|
|
|
@@ -198,15 +231,49 @@ module Gloo
|
|
|
198
231
|
run_do
|
|
199
232
|
end
|
|
200
233
|
end
|
|
201
|
-
|
|
234
|
+
|
|
202
235
|
# Set the value of the repo.
|
|
203
236
|
# This is a path to the repo.
|
|
204
|
-
def set_repo path
|
|
237
|
+
def set_repo( path )
|
|
205
238
|
o = find_child REPO
|
|
206
239
|
return unless o
|
|
240
|
+
|
|
207
241
|
o.set_value path
|
|
208
242
|
end
|
|
209
243
|
|
|
244
|
+
# ---------------------------------------------------------------------
|
|
245
|
+
# Help
|
|
246
|
+
# ---------------------------------------------------------------------
|
|
247
|
+
|
|
248
|
+
#
|
|
249
|
+
# Get help for this object type.
|
|
250
|
+
#
|
|
251
|
+
def self.help
|
|
252
|
+
return <<~TEXT
|
|
253
|
+
EACH OBJECT TYPE
|
|
254
|
+
NAME: each
|
|
255
|
+
SHORTCUT: each
|
|
256
|
+
|
|
257
|
+
DESCRIPTION
|
|
258
|
+
Perform an action for each item in a collection.
|
|
259
|
+
|
|
260
|
+
CHILDREN
|
|
261
|
+
child | word | line | repo - string - none
|
|
262
|
+
The entity we want to loop for.
|
|
263
|
+
It will hold the current value while the script is running.
|
|
264
|
+
in - string - none
|
|
265
|
+
The collection we will iterate in.
|
|
266
|
+
In the case of <word> or <line> this will be a string or text.
|
|
267
|
+
In the case of <repo> this will be the root path.
|
|
268
|
+
do - script - none
|
|
269
|
+
The action we want to perform for each found item.
|
|
270
|
+
|
|
271
|
+
MESSAGES
|
|
272
|
+
run - Look through the collecion and perform this for each
|
|
273
|
+
found item.
|
|
274
|
+
TEXT
|
|
275
|
+
end
|
|
276
|
+
|
|
210
277
|
end
|
|
211
278
|
end
|
|
212
279
|
end
|