gloo 0.3.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 (88) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.travis.yml +5 -0
  4. data/CODE_OF_CONDUCT.md +74 -0
  5. data/Gemfile +6 -0
  6. data/Gemfile.lock +139 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +43 -0
  9. data/Rakefile +12 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +8 -0
  12. data/exe/gloo +4 -0
  13. data/exe/o +4 -0
  14. data/gloo.gemspec +38 -0
  15. data/lib/gloo.rb +19 -0
  16. data/lib/gloo/app/args.rb +71 -0
  17. data/lib/gloo/app/engine.rb +158 -0
  18. data/lib/gloo/app/help.rb +29 -0
  19. data/lib/gloo/app/info.rb +21 -0
  20. data/lib/gloo/app/log.rb +58 -0
  21. data/lib/gloo/app/mode.rb +25 -0
  22. data/lib/gloo/app/settings.rb +125 -0
  23. data/lib/gloo/core/baseo.rb +28 -0
  24. data/lib/gloo/core/dictionary.rb +101 -0
  25. data/lib/gloo/core/event_manager.rb +46 -0
  26. data/lib/gloo/core/factory.rb +67 -0
  27. data/lib/gloo/core/gloo_system.rb +190 -0
  28. data/lib/gloo/core/heap.rb +42 -0
  29. data/lib/gloo/core/it.rb +30 -0
  30. data/lib/gloo/core/literal.rb +25 -0
  31. data/lib/gloo/core/obj.rb +222 -0
  32. data/lib/gloo/core/obj_finder.rb +35 -0
  33. data/lib/gloo/core/op.rb +33 -0
  34. data/lib/gloo/core/parser.rb +52 -0
  35. data/lib/gloo/core/pn.rb +134 -0
  36. data/lib/gloo/core/script.rb +37 -0
  37. data/lib/gloo/core/tokens.rb +123 -0
  38. data/lib/gloo/core/verb.rb +63 -0
  39. data/lib/gloo/expr/expression.rb +103 -0
  40. data/lib/gloo/expr/l_boolean.rb +29 -0
  41. data/lib/gloo/expr/l_integer.rb +29 -0
  42. data/lib/gloo/expr/l_string.rb +53 -0
  43. data/lib/gloo/expr/op_div.rb +20 -0
  44. data/lib/gloo/expr/op_minus.rb +20 -0
  45. data/lib/gloo/expr/op_mult.rb +20 -0
  46. data/lib/gloo/expr/op_plus.rb +22 -0
  47. data/lib/gloo/objs/basic/boolean.rb +113 -0
  48. data/lib/gloo/objs/basic/container.rb +50 -0
  49. data/lib/gloo/objs/basic/integer.rb +65 -0
  50. data/lib/gloo/objs/basic/script.rb +101 -0
  51. data/lib/gloo/objs/basic/string.rb +65 -0
  52. data/lib/gloo/objs/basic/text.rb +64 -0
  53. data/lib/gloo/objs/basic/untyped.rb +42 -0
  54. data/lib/gloo/objs/cli/colorize.rb +73 -0
  55. data/lib/gloo/objs/cli/confirm.rb +92 -0
  56. data/lib/gloo/objs/cli/prompt.rb +92 -0
  57. data/lib/gloo/objs/ctrl/each.rb +212 -0
  58. data/lib/gloo/objs/dev/git.rb +112 -0
  59. data/lib/gloo/objs/ror/erb.rb +109 -0
  60. data/lib/gloo/objs/ror/eval.rb +92 -0
  61. data/lib/gloo/objs/system/file_handle.rb +86 -0
  62. data/lib/gloo/objs/system/system.rb +120 -0
  63. data/lib/gloo/objs/web/http_get.rb +128 -0
  64. data/lib/gloo/objs/web/http_post.rb +127 -0
  65. data/lib/gloo/objs/web/slack.rb +126 -0
  66. data/lib/gloo/objs/web/teams.rb +117 -0
  67. data/lib/gloo/persist/file_loader.rb +171 -0
  68. data/lib/gloo/persist/file_saver.rb +43 -0
  69. data/lib/gloo/persist/file_storage.rb +43 -0
  70. data/lib/gloo/persist/persist_man.rb +90 -0
  71. data/lib/gloo/utils/words.rb +19 -0
  72. data/lib/gloo/verbs/alert.rb +42 -0
  73. data/lib/gloo/verbs/context.rb +52 -0
  74. data/lib/gloo/verbs/create.rb +52 -0
  75. data/lib/gloo/verbs/help.rb +69 -0
  76. data/lib/gloo/verbs/if.rb +56 -0
  77. data/lib/gloo/verbs/list.rb +85 -0
  78. data/lib/gloo/verbs/load.rb +39 -0
  79. data/lib/gloo/verbs/put.rb +62 -0
  80. data/lib/gloo/verbs/quit.rb +40 -0
  81. data/lib/gloo/verbs/run.rb +46 -0
  82. data/lib/gloo/verbs/save.rb +37 -0
  83. data/lib/gloo/verbs/show.rb +55 -0
  84. data/lib/gloo/verbs/tell.rb +47 -0
  85. data/lib/gloo/verbs/unless.rb +56 -0
  86. data/lib/gloo/verbs/version.rb +37 -0
  87. data/lib/run.rb +13 -0
  88. metadata +254 -0
@@ -0,0 +1,112 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # An object that interacts with a git repository
5
+ #
6
+
7
+ module Gloo
8
+ module Objs
9
+ class Git < Gloo::Core::Obj
10
+
11
+ KEYWORD = 'git_repo'
12
+ KEYWORD_SHORT = 'git'
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
+ # Get the path to the git repo (locally).
30
+ #
31
+ def get_path
32
+ return value
33
+ end
34
+
35
+
36
+ # ---------------------------------------------------------------------
37
+ # Messages
38
+ # ---------------------------------------------------------------------
39
+
40
+ #
41
+ # Get a list of message names that this object receives.
42
+ #
43
+ def self.messages
44
+ return super + [ "validate", "check_changes", "get_changes",
45
+ "commit", "get_branch" ]
46
+ end
47
+
48
+ # Get the current working branch.
49
+ def msg_get_branch
50
+ branch = ""
51
+ path = get_path
52
+ if path and File.directory?( path )
53
+ branch = `cd #{path}; git rev-parse --abbrev-ref HEAD`
54
+ branch = branch.strip
55
+ end
56
+
57
+ $engine.heap.it.set_to branch
58
+ end
59
+
60
+
61
+ # Check to see if the repo has changes.
62
+ def msg_commit
63
+ msg = "Commit"
64
+ path = get_path
65
+ if path && File.directory?( path )
66
+ if @params && @params.token_count > 0
67
+ expr = Gloo::Expr::Expression.new( @params.tokens )
68
+ msg = expr.evaluate
69
+ end
70
+ branch = `cd #{path}; git rev-parse --abbrev-ref HEAD`
71
+ branch = branch.strip
72
+ result = `cd #{path}; git add .; git commit -m "#{msg}";git push origin #{branch}`
73
+ end
74
+ $engine.heap.it.set_to msg
75
+ end
76
+
77
+ # Check to see if the repo has changes.
78
+ def msg_get_changes
79
+ path = get_path
80
+ if path and File.directory?( path )
81
+ result = `cd #{path}; git status -s`
82
+ end
83
+ result = result ? result : ""
84
+ $engine.heap.it.set_to result
85
+ end
86
+
87
+ # Check to see if the repo has changes.
88
+ def msg_check_changes
89
+ result = false
90
+ path = get_path
91
+ if path and File.directory?( path )
92
+ data = `cd #{path}; git status -s`
93
+ result = true unless ( data.strip.length == 0 )
94
+ end
95
+
96
+ $engine.heap.it.set_to result
97
+ end
98
+
99
+ # Check to make sure this is a valide git repo.
100
+ def msg_validate
101
+ result = false
102
+ path = get_path
103
+ if path and File.directory?( path )
104
+ result = File.exists? File.join( path, '.git' )
105
+ end
106
+
107
+ $engine.heap.it.set_to result
108
+ end
109
+
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,109 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # An object that evaluate a ruby statement.
5
+ #
6
+ require 'erb'
7
+
8
+ module Gloo
9
+ module Objs
10
+ class Erb < Gloo::Core::Obj
11
+
12
+ KEYWORD = 'erb'
13
+ KEYWORD_SHORT = 'erb'
14
+ TEMPLATE = 'template'
15
+ PARAMS = 'params'
16
+ RESULT = 'result'
17
+
18
+ #
19
+ # The name of the object type.
20
+ #
21
+ def self.typename
22
+ return KEYWORD
23
+ end
24
+
25
+ #
26
+ # The short name of the object type.
27
+ #
28
+ def self.short_typename
29
+ return KEYWORD_SHORT
30
+ end
31
+
32
+ #
33
+ # Get the ERB template.
34
+ #
35
+ def get_template
36
+ tmpl = find_child TEMPLATE
37
+ return nil unless tmpl
38
+ return tmpl.value
39
+ end
40
+
41
+ #
42
+ # Set the result of the system call.
43
+ #
44
+ def set_result data
45
+ r = find_child RESULT
46
+ return nil unless r
47
+ r.set_value data
48
+ end
49
+
50
+ #
51
+ # Get a hash with parameters for the ERB render.
52
+ #
53
+ def get_param_hash
54
+ h = {}
55
+
56
+ body = find_child PARAMS
57
+ body.children.each do |child|
58
+ h[ child.name ] = child.value
59
+ end
60
+
61
+ return h
62
+ end
63
+
64
+
65
+
66
+ # ---------------------------------------------------------------------
67
+ # Children
68
+ # ---------------------------------------------------------------------
69
+
70
+ # Does this object have children to add when an object
71
+ # is created in interactive mode?
72
+ # This does not apply during obj load, etc.
73
+ def add_children_on_create?
74
+ return true
75
+ end
76
+
77
+ # Add children to this object.
78
+ # This is used by containers to add children needed
79
+ # for default configurations.
80
+ def add_default_children
81
+ fac = $engine.factory
82
+ fac.create "template", "text", "", self
83
+ fac.create "params", "container", nil, self
84
+ fac.create "result", "text", nil, self
85
+ end
86
+
87
+
88
+ # ---------------------------------------------------------------------
89
+ # Messages
90
+ # ---------------------------------------------------------------------
91
+
92
+ #
93
+ # Get a list of message names that this object receives.
94
+ #
95
+ def self.messages
96
+ return super + [ "run" ]
97
+ end
98
+
99
+ # Run the system command.
100
+ def msg_run
101
+ tmpl = get_template
102
+ return unless tmpl
103
+ render = ERB.new( tmpl )
104
+ set_result render.result_with_hash( get_param_hash )
105
+ end
106
+
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,92 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # An object that evaluate a ruby statement.
5
+ #
6
+
7
+ module Gloo
8
+ module Objs
9
+ class Eval < Gloo::Core::Obj
10
+
11
+ KEYWORD = 'eval'
12
+ KEYWORD_SHORT = 'ruby'
13
+ CMD = 'command'
14
+ RESULT = 'result'
15
+
16
+ #
17
+ # The name of the object type.
18
+ #
19
+ def self.typename
20
+ return KEYWORD
21
+ end
22
+
23
+ #
24
+ # The short name of the object type.
25
+ #
26
+ def self.short_typename
27
+ return KEYWORD_SHORT
28
+ end
29
+
30
+ #
31
+ # Get the URI from the child object.
32
+ # Returns nil if there is none.
33
+ #
34
+ def get_cmd
35
+ cmd = find_child CMD
36
+ return nil unless cmd
37
+ return cmd.value
38
+ end
39
+
40
+ #
41
+ # Set the result of the system call.
42
+ #
43
+ def set_result data
44
+ r = find_child RESULT
45
+ return nil unless r
46
+ r.set_value data
47
+ end
48
+
49
+
50
+ # ---------------------------------------------------------------------
51
+ # Children
52
+ # ---------------------------------------------------------------------
53
+
54
+ # Does this object have children to add when an object
55
+ # is created in interactive mode?
56
+ # This does not apply during obj load, etc.
57
+ def add_children_on_create?
58
+ return true
59
+ end
60
+
61
+ # Add children to this object.
62
+ # This is used by containers to add children needed
63
+ # for default configurations.
64
+ def add_default_children
65
+ fac = $engine.factory
66
+ fac.create "command", "string", "date", self
67
+ fac.create "result", "string", nil, self
68
+ end
69
+
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
+ cmd = get_cmd
85
+ return unless cmd
86
+ result = eval cmd
87
+ set_result result
88
+ end
89
+
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,86 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # An object that can make a system call.
5
+ #
6
+
7
+ module Gloo
8
+ module Objs
9
+ class FileHandle < Gloo::Core::Obj
10
+
11
+ KEYWORD = 'file'
12
+ KEYWORD_SHORT = 'dir'
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
+ # ---------------------------------------------------------------------
30
+ # Messages
31
+ # ---------------------------------------------------------------------
32
+
33
+ #
34
+ # Get a list of message names that this object receives.
35
+ #
36
+ def self.messages
37
+ return super + [ "read", "write",
38
+ "check_exists", "check_is_file", "check_is_dir" ]
39
+ 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
+
66
+ # Check to see if the file exists.
67
+ def msg_check_exists
68
+ result = File.exists? value
69
+ $engine.heap.it.set_to result
70
+ end
71
+
72
+ # Check to see if the file is a file.
73
+ def msg_check_is_file
74
+ result = File.file? value
75
+ $engine.heap.it.set_to result
76
+ end
77
+
78
+ # Check to see if the file is a directory.
79
+ def msg_check_is_dir
80
+ result = File.directory? value
81
+ $engine.heap.it.set_to result
82
+ end
83
+
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,120 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # An object that can make a system call.
5
+ #
6
+
7
+ module Gloo
8
+ module Objs
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
+ #
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 get_cmd
36
+ cmd = find_child CMD
37
+ return nil unless cmd
38
+ return cmd.value
39
+ end
40
+
41
+ #
42
+ # Set the result of the system call.
43
+ #
44
+ def set_result data
45
+ r = find_child RESULT
46
+ return nil unless r
47
+ r.set_value data
48
+ end
49
+
50
+ #
51
+ # Should the system call get output?
52
+ # If so, the system call will run and get output,
53
+ # otherwise it will just get the result of the call.
54
+ #
55
+ def has_output?
56
+ o = find_child GET_OUTPUT
57
+ return false unless o
58
+ return o.value
59
+ end
60
+
61
+
62
+ # ---------------------------------------------------------------------
63
+ # Children
64
+ # ---------------------------------------------------------------------
65
+
66
+ # Does this object have children to add when an object
67
+ # is created in interactive mode?
68
+ # This does not apply during obj load, etc.
69
+ def add_children_on_create?
70
+ return true
71
+ end
72
+
73
+ # Add children to this object.
74
+ # This is used by containers to add children needed
75
+ # for default configurations.
76
+ def add_default_children
77
+ 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
81
+ end
82
+
83
+
84
+ # ---------------------------------------------------------------------
85
+ # Messages
86
+ # ---------------------------------------------------------------------
87
+
88
+ #
89
+ # Get a list of message names that this object receives.
90
+ #
91
+ def self.messages
92
+ return super + [ "run" ]
93
+ end
94
+
95
+ # Run the system command.
96
+ def msg_run
97
+ if has_output?
98
+ run_with_output
99
+ else
100
+ run_with_result
101
+ end
102
+ end
103
+
104
+ def run_with_output
105
+ cmd = get_cmd
106
+ return unless cmd
107
+ result = `#{cmd}`
108
+ set_result result
109
+ end
110
+
111
+ def run_with_result
112
+ cmd = get_cmd
113
+ return unless cmd
114
+ result = system cmd
115
+ set_result result
116
+ end
117
+
118
+ end
119
+ end
120
+ end