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
@@ -10,52 +10,52 @@ require 'json'
10
10
  module Gloo
11
11
  module Objs
12
12
  class HttpPost < Gloo::Core::Obj
13
-
14
- KEYWORD = 'http_post'
15
- KEYWORD_SHORT = 'post'
16
- URL = 'uri'
17
- BODY = 'body'
18
13
 
19
- #
14
+ KEYWORD = 'http_post'.freeze
15
+ KEYWORD_SHORT = 'post'.freeze
16
+ URL = 'uri'.freeze
17
+ BODY = 'body'.freeze
18
+
19
+ #
20
20
  # The name of the object type.
21
- #
21
+ #
22
22
  def self.typename
23
23
  return KEYWORD
24
24
  end
25
25
 
26
- #
26
+ #
27
27
  # The short name of the object type.
28
- #
28
+ #
29
29
  def self.short_typename
30
30
  return KEYWORD_SHORT
31
31
  end
32
-
33
- #
32
+
33
+ #
34
34
  # Get the URI from the child object.
35
35
  # Returns nil if there is none.
36
- #
37
- def get_uri
36
+ #
37
+ def uri_value
38
38
  uri = find_child URL
39
39
  return nil unless uri
40
+
40
41
  return uri.value
41
42
  end
42
-
43
- #
44
- # Get all the children of the body container and
43
+
44
+ #
45
+ # Get all the children of the body container and
45
46
  # convert to JSON that will be sent in the HTTP body.
46
- #
47
- def get_body_as_json
47
+ #
48
+ def body_as_json
48
49
  h = {}
49
-
50
+
50
51
  body = find_child BODY
51
52
  body.children.each do |child|
52
53
  h[ child.name ] = child.value
53
54
  end
54
-
55
+
55
56
  return h.to_json
56
57
  end
57
58
 
58
-
59
59
  # ---------------------------------------------------------------------
60
60
  # Children
61
61
  # ---------------------------------------------------------------------
@@ -66,50 +66,48 @@ module Gloo
66
66
  def add_children_on_create?
67
67
  return true
68
68
  end
69
-
69
+
70
70
  # Add children to this object.
71
- # This is used by containers to add children needed
71
+ # This is used by containers to add children needed
72
72
  # for default configurations.
73
73
  def add_default_children
74
74
  fac = $engine.factory
75
- fac.create "uri", "string", "https://web.site/", self
76
- fac.create "body", "container", nil, self
75
+ fac.create( { :name => 'uri',
76
+ :type => 'string',
77
+ :value => 'https://web.site/',
78
+ :parent => self } )
79
+ fac.create( { :name => 'body',
80
+ :type => 'container',
81
+ :value => nil,
82
+ :parent => self } )
77
83
  end
78
84
 
79
-
80
85
  # ---------------------------------------------------------------------
81
86
  # Messages
82
87
  # ---------------------------------------------------------------------
83
88
 
84
- #
89
+ #
85
90
  # Get a list of message names that this object receives.
86
- #
91
+ #
87
92
  def self.messages
88
- return super + [ "run" ]
93
+ return super + [ 'run' ]
89
94
  end
90
-
95
+
91
96
  # Post the content to the endpoint.
92
97
  def msg_run
93
- uri = get_uri
98
+ uri = uri_value
94
99
  return unless uri
95
-
96
- body = get_body_as_json
97
-
98
- if uri.downcase.start_with?( "https" )
99
- use_ssl = true
100
- else
101
- use_ssl = false
102
- end
103
- Gloo::Objs::HttpPost.post_json uri, body, use_ssl
100
+
101
+ use_ssl = uri.downcase.start_with?( 'https' )
102
+ Gloo::Objs::HttpPost.post_json uri, body_as_json, use_ssl
104
103
  end
105
-
106
-
104
+
107
105
  # ---------------------------------------------------------------------
108
106
  # Static functions
109
107
  # ---------------------------------------------------------------------
110
108
 
111
109
  # Post the content to the endpoint.
112
- def self.post_json url, body, use_ssl=true
110
+ def self.post_json( url, body, use_ssl = true )
113
111
  # Structure the request
114
112
  uri = URI.parse( url )
115
113
  request = Net::HTTP::Post.new( uri.path )
@@ -122,6 +120,34 @@ module Gloo
122
120
  n.start { |http| http.request( request ) }
123
121
  end
124
122
 
123
+ # ---------------------------------------------------------------------
124
+ # Help
125
+ # ---------------------------------------------------------------------
126
+
127
+ #
128
+ # Get help for this object type.
129
+ #
130
+ def self.help
131
+ return <<~TEXT
132
+ HTTP_POST OBJECT TYPE
133
+ NAME: http_post
134
+ SHORTCUT: post
135
+
136
+ DESCRIPTION
137
+ Perform an HTTP Post.
138
+
139
+ CHILDREN
140
+ uri - string - 'https://web.site/'
141
+ The URI for the HTTP Post.
142
+ body - container
143
+ Collection of parameters for the HTTP Post.
144
+
145
+ MESSAGES
146
+ run - Run the HTTP Post sending the body data to the
147
+ endpoint specified in the URI.
148
+ TEXT
149
+ end
150
+
125
151
  end
126
152
  end
127
153
  end
@@ -10,73 +10,73 @@ require 'json'
10
10
  module Gloo
11
11
  module Objs
12
12
  class Slack < Gloo::Core::Obj
13
-
14
- KEYWORD = 'slack'
15
- KEYWORD_SHORT = 'slack'
16
- URL = 'uri'
17
- MSG = 'message'
18
- USER = 'username'
19
- CHANNEL = 'channel'
20
- ICON = 'icon_emoji'
21
-
22
- ATTACHMENT = 'attachment'
23
- TITLE = 'title'
24
- TEXT = 'text'
25
-
26
- #
13
+
14
+ KEYWORD = 'slack'.freeze
15
+ KEYWORD_SHORT = 'slack'.freeze
16
+ URL = 'uri'.freeze
17
+ MSG = 'message'.freeze
18
+ USER = 'username'.freeze
19
+ CHANNEL = 'channel'.freeze
20
+ ICON = 'icon_emoji'.freeze
21
+
22
+ ATTACHMENT = 'attachment'.freeze
23
+ TITLE = 'title'.freeze
24
+ TEXT = 'text'.freeze
25
+
26
+ #
27
27
  # The name of the object type.
28
- #
28
+ #
29
29
  def self.typename
30
30
  return KEYWORD
31
31
  end
32
32
 
33
- #
33
+ #
34
34
  # The short name of the object type.
35
- #
35
+ #
36
36
  def self.short_typename
37
37
  return KEYWORD_SHORT
38
38
  end
39
-
40
- #
39
+
40
+ #
41
41
  # Get the URI from the child object.
42
42
  # Returns nil if there is none.
43
- #
44
- def get_uri
43
+ #
44
+ def uri_value
45
45
  uri = find_child URL
46
46
  return nil unless uri
47
+
47
48
  return uri.value
48
49
  end
49
50
 
50
- #
51
+ #
51
52
  # Get the URI from the child object.
52
53
  # Returns nil if there is none.
53
- #
54
- def get_attachment
54
+ #
55
+ def attachment_value
55
56
  o = find_child ATTACHMENT
56
57
  return nil unless o
57
-
58
- title = o.find_child TITLE
59
- text = o.find_child TEXT
60
- return [{ 'title' => title.value, 'text' => text.value }]
58
+
59
+ title = o.find_child TITLE
60
+ text = o.find_child TEXT
61
+ return [ { 'title' => title.value,
62
+ 'text' => text.value } ]
61
63
  end
62
-
63
- #
64
- # Get all the children of the body container and
64
+
65
+ #
66
+ # Get all the children of the body container and
65
67
  # convert to JSON that will be sent in the HTTP body.
66
- #
67
- def get_body_as_json
68
+ #
69
+ def body_as_json
68
70
  h = { 'text' => find_child( MSG ).value,
69
- 'username' => find_child( USER ).value,
70
- 'channel' => find_child( CHANNEL ).value,
71
- 'icon_emoji' => find_child( ICON ).value,
72
- }
73
-
74
- o = get_attachment
75
- h[ 'attachments' ] = o if o
71
+ 'username' => find_child( USER ).value,
72
+ 'channel' => find_child( CHANNEL ).value,
73
+ 'icon_emoji' => find_child( ICON ).value }
74
+
75
+ o = attachment_value
76
+ h[ 'attachments' ] = o if o
76
77
  return h.to_json
77
78
  end
78
79
 
79
-
80
80
  # ---------------------------------------------------------------------
81
81
  # Children
82
82
  # ---------------------------------------------------------------------
@@ -87,40 +87,71 @@ module Gloo
87
87
  def add_children_on_create?
88
88
  return true
89
89
  end
90
-
90
+
91
91
  # Add children to this object.
92
- # This is used by containers to add children needed
92
+ # This is used by containers to add children needed
93
93
  # for default configurations.
94
94
  def add_default_children
95
95
  fac = $engine.factory
96
- fac.create URL, "string", "https://hooks.slack.com/services/...", self
97
- fac.create MSG, "string", "textual message", self
98
- fac.create USER, "string", "Slack Bot", self
99
- fac.create CHANNEL, "string", "general", self
100
- fac.create ICON, "string", ":ghost:", self
96
+ fac.create_string URL, 'https://hooks.slack.com/services/...', self
97
+ fac.create_string MSG, 'textual message', self
98
+ fac.create_string USER, 'Slack Bot', self
99
+ fac.create_string CHANNEL, 'general', self
100
+ fac.create_string ICON, ':ghost:', self
101
101
  end
102
102
 
103
-
104
103
  # ---------------------------------------------------------------------
105
104
  # Messages
106
105
  # ---------------------------------------------------------------------
107
106
 
108
- #
107
+ #
109
108
  # Get a list of message names that this object receives.
110
- #
109
+ #
111
110
  def self.messages
112
- return super + [ "run" ]
111
+ return super + [ 'run' ]
113
112
  end
114
-
113
+
115
114
  # Post the content to the endpoint.
116
115
  def msg_run
117
- uri = get_uri
116
+ uri = uri_value
118
117
  return unless uri
119
-
120
- body = get_body_as_json
121
- Gloo::Objs::HttpPost.post_json uri, body, true
118
+
119
+ Gloo::Objs::HttpPost.post_json uri, body_as_json, true
120
+ end
121
+
122
+ # ---------------------------------------------------------------------
123
+ # Help
124
+ # ---------------------------------------------------------------------
125
+
126
+ #
127
+ # Get help for this object type.
128
+ #
129
+ def self.help
130
+ return <<~TEXT
131
+ SLACK OBJECT TYPE
132
+ NAME: slack
133
+ SHORTCUT: slack
134
+
135
+ DESCRIPTION
136
+ Send message to channel in Slack.
137
+
138
+ CHILDREN
139
+ uri - string - 'https://hooks.slack.com/services/...'
140
+ The URI with access to the Slack channel.
141
+ message - string - 'textual message'
142
+ Message to send to Slack.
143
+ username - string - 'Slack Bot'
144
+ Attribute the message to this user.
145
+ channel - string - 'general'
146
+ The name of the channel for the post.
147
+ icon_emoji - string - ':ghost:'
148
+ The emoji to use for the attribution.
149
+
150
+ MESSAGES
151
+ run - Post the message to Slack.
152
+ TEXT
122
153
  end
123
-
154
+
124
155
  end
125
156
  end
126
157
  end
@@ -10,63 +10,59 @@ require 'json'
10
10
  module Gloo
11
11
  module Objs
12
12
  class Teams < Gloo::Core::Obj
13
-
14
- KEYWORD = 'teams'
15
- KEYWORD_SHORT = 'team'
16
- URL = 'uri'
17
- MSG = 'message'
18
- TITLE = 'title'
19
- COLOR = 'color'
20
-
21
- #
13
+
14
+ KEYWORD = 'teams'.freeze
15
+ KEYWORD_SHORT = 'team'.freeze
16
+ URL = 'uri'.freeze
17
+ MSG = 'message'.freeze
18
+ TITLE = 'title'.freeze
19
+ COLOR = 'color'.freeze
20
+
21
+ #
22
22
  # The name of the object type.
23
- #
23
+ #
24
24
  def self.typename
25
25
  return KEYWORD
26
26
  end
27
27
 
28
- #
28
+ #
29
29
  # The short name of the object type.
30
- #
30
+ #
31
31
  def self.short_typename
32
32
  return KEYWORD_SHORT
33
33
  end
34
-
35
- #
34
+
35
+ #
36
36
  # Get the URI from the child object.
37
37
  # Returns nil if there is none.
38
- #
39
- def get_uri
38
+ #
39
+ def uri_value
40
40
  uri = find_child URL
41
41
  return nil unless uri
42
+
42
43
  return uri.value
43
44
  end
44
-
45
- # Get the color value.
46
- def get_color
47
- c = find_child COLOR
45
+
46
+ # Get the color value.
47
+ def color_value
48
+ c = find_child COLOR
48
49
  return nil unless c
50
+
49
51
  return c.value
50
- end
51
-
52
- #
53
- # Get all the children of the body container and
52
+ end
53
+
54
+ #
55
+ # Get all the children of the body container and
54
56
  # convert to JSON that will be sent in the HTTP body.
55
- #
56
- def get_body_as_json
57
+ #
58
+ def body_as_json
57
59
  h = { 'title' => find_child( TITLE ).value,
58
- 'text' => find_child( MSG ).value
59
- }
60
-
61
- color = get_color
62
- if color
63
- h[ 'themeColor' ] = color
64
- end
65
-
60
+ 'text' => find_child( MSG ).value }
61
+ color = color_value
62
+ h[ 'themeColor' ] = color if color
66
63
  return h.to_json
67
64
  end
68
65
 
69
-
70
66
  # ---------------------------------------------------------------------
71
67
  # Children
72
68
  # ---------------------------------------------------------------------
@@ -77,41 +73,80 @@ module Gloo
77
73
  def add_children_on_create?
78
74
  return true
79
75
  end
80
-
76
+
81
77
  # Add children to this object.
82
- # This is used by containers to add children needed
78
+ # This is used by containers to add children needed
83
79
  # for default configurations.
84
80
  def add_default_children
85
81
  fac = $engine.factory
86
- fac.create URL, "string", "https://outlook.office.com/webhook/...", self
87
- fac.create TITLE, "string", "", self
88
- fac.create COLOR, "color", "008000", self
89
- fac.create MSG, "string", "", self
82
+ fac.create( { :name => URL,
83
+ :type => 'string',
84
+ :value => 'https://outlook.office.com/webhook/...',
85
+ :parent => self } )
86
+ fac.create( { :name => TITLE,
87
+ :type => 'string',
88
+ :value => '',
89
+ :parent => self } )
90
+ fac.create( { :name => COLOR,
91
+ :type => 'color',
92
+ :value => '008000',
93
+ :parent => self } )
94
+ fac.create( { :name => MSG,
95
+ :type => 'string',
96
+ :value => '',
97
+ :parent => self } )
90
98
  end
91
99
 
92
-
93
100
  # ---------------------------------------------------------------------
94
101
  # Messages
95
102
  # ---------------------------------------------------------------------
96
103
 
97
- #
104
+ #
98
105
  # Get a list of message names that this object receives.
99
- #
106
+ #
100
107
  def self.messages
101
- return super + [ "run" ]
108
+ return super + [ 'run' ]
102
109
  end
103
-
110
+
104
111
  # Post the content to the endpoint.
105
112
  def msg_run
106
- uri = get_uri
113
+ uri = uri_value
107
114
  return unless uri
108
-
109
- body = get_body_as_json
110
- # puts body
111
-
112
- Gloo::Objs::HttpPost.post_json uri, body, true
115
+
116
+ Gloo::Objs::HttpPost.post_json uri, body_as_json, true
117
+ end
118
+
119
+ # ---------------------------------------------------------------------
120
+ # Help
121
+ # ---------------------------------------------------------------------
122
+
123
+ #
124
+ # Get help for this object type.
125
+ #
126
+ def self.help
127
+ return <<~TEXT
128
+ TEAMS OBJECT TYPE
129
+ NAME: teams
130
+ SHORTCUT: team
131
+
132
+ DESCRIPTION
133
+ Send message to channel in Teams.
134
+
135
+ CHILDREN
136
+ uri - string - 'https://outlook.office.com/webhook/...'
137
+ The URI with access to the Teams channel.
138
+ title - string
139
+ Message title; header.
140
+ color - string - '008000'
141
+ Color theme for the message.
142
+ message - string
143
+ The message to post in Teams.
144
+
145
+ MESSAGES
146
+ run - Post the message to Teams.
147
+ TEXT
113
148
  end
114
-
149
+
115
150
  end
116
151
  end
117
152
  end