gloo 0.8.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.DS_Store +0 -0
- data/.gitignore +2 -1
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/LICENSE.txt +1 -1
- data/gloo.gemspec +12 -4
- data/lib/VERSION +1 -1
- data/lib/dependencies.rb +4 -4
- data/lib/gloo/app/info.rb +3 -1
- data/lib/gloo/app/log.rb +1 -29
- data/lib/gloo/app/platform.rb +142 -0
- data/lib/gloo/objs/cli/banner.rb +2 -2
- data/lib/gloo/objs/cli/bar.rb +4 -4
- data/lib/gloo/objs/cli/colorize.rb +3 -3
- data/lib/gloo/objs/cli/confirm.rb +3 -3
- data/lib/gloo/objs/cli/menu.rb +9 -9
- data/lib/gloo/objs/cli/menu_item.rb +2 -2
- data/lib/gloo/objs/cli/pastel.rb +2 -2
- data/lib/gloo/objs/cli/prompt.rb +4 -4
- data/lib/gloo/objs/cli/select.rb +4 -4
- data/lib/gloo/objs/data/mysql.rb +9 -9
- data/lib/gloo/objs/data/sqlite.rb +10 -10
- data/lib/gloo/objs/dev/git.rb +7 -7
- data/lib/gloo/objs/dev/stats.rb +8 -5
- data/lib/gloo/objs/snd/play.rb +1 -1
- data/lib/gloo/objs/snd/say.rb +2 -2
- data/lib/gloo/objs/system/file_handle.rb +9 -9
- data/lib/gloo/objs/system/ssh_exec.rb +3 -3
- data/lib/gloo/objs/system/system.rb +2 -2
- data/lib/gloo/verbs/alert.rb +7 -7
- data/lib/gloo/verbs/beep.rb +1 -1
- data/lib/gloo/verbs/cls.rb +2 -2
- data/lib/gloo/verbs/help.rb +7 -189
- data/lib/gloo/verbs/version.rb +3 -3
- data/lib/gloo.rb +5 -1
- data/lib/run.rb +5 -1
- metadata +41 -177
- data/Gemfile.lock +0 -171
- data/lib/gloo/app/args.rb +0 -112
- data/lib/gloo/app/engine.rb +0 -230
- data/lib/gloo/app/help.rb +0 -156
- data/lib/gloo/app/mode.rb +0 -27
- data/lib/gloo/app/settings.rb +0 -186
- data/lib/gloo/convert/converter.rb +0 -35
- data/lib/gloo/convert/string_to_datetime.rb +0 -21
- data/lib/gloo/convert/string_to_decimal.rb +0 -20
- data/lib/gloo/convert/string_to_integer.rb +0 -20
- data/lib/gloo/core/baseo.rb +0 -30
- data/lib/gloo/core/dictionary.rb +0 -181
- data/lib/gloo/core/error.rb +0 -61
- data/lib/gloo/core/event_manager.rb +0 -44
- data/lib/gloo/core/factory.rb +0 -210
- data/lib/gloo/core/gloo_system.rb +0 -266
- data/lib/gloo/core/heap.rb +0 -52
- data/lib/gloo/core/here.rb +0 -36
- data/lib/gloo/core/it.rb +0 -36
- data/lib/gloo/core/literal.rb +0 -30
- data/lib/gloo/core/obj.rb +0 -303
- data/lib/gloo/core/obj_finder.rb +0 -30
- data/lib/gloo/core/op.rb +0 -40
- data/lib/gloo/core/parser.rb +0 -59
- data/lib/gloo/core/pn.rb +0 -188
- data/lib/gloo/core/tokens.rb +0 -165
- data/lib/gloo/core/verb.rb +0 -86
- data/lib/gloo/exec/action.rb +0 -48
- data/lib/gloo/exec/dispatch.rb +0 -40
- data/lib/gloo/exec/exec_env.rb +0 -74
- data/lib/gloo/exec/runner.rb +0 -45
- data/lib/gloo/exec/script.rb +0 -49
- data/lib/gloo/exec/stack.rb +0 -78
- data/lib/gloo/expr/expression.rb +0 -118
- data/lib/gloo/expr/l_boolean.rb +0 -36
- data/lib/gloo/expr/l_decimal.rb +0 -39
- data/lib/gloo/expr/l_integer.rb +0 -37
- data/lib/gloo/expr/l_string.rb +0 -58
- data/lib/gloo/expr/op_div.rb +0 -22
- data/lib/gloo/expr/op_minus.rb +0 -22
- data/lib/gloo/expr/op_mult.rb +0 -22
- data/lib/gloo/expr/op_plus.rb +0 -24
- data/lib/gloo/help/app/application.txt +0 -22
- data/lib/gloo/help/app/configuration.txt +0 -7
- data/lib/gloo/help/app/default_help.txt +0 -14
- data/lib/gloo/help/app/logging.txt +0 -16
- data/lib/gloo/help/core/color.txt +0 -31
- data/lib/gloo/help/core/error.txt +0 -33
- data/lib/gloo/help/core/events.txt +0 -21
- data/lib/gloo/help/core/gloo_system.txt +0 -57
- data/lib/gloo/help/core/here.txt +0 -30
- data/lib/gloo/help/core/it.txt +0 -23
- data/lib/gloo/help/core/ops.txt +0 -16
- data/lib/gloo/help/core/pathname.txt +0 -29
- data/lib/gloo/help/objs/basic/alias.txt +0 -36
- data/lib/gloo/help/objs/basic/boolean.txt +0 -28
- data/lib/gloo/help/objs/basic/container.txt +0 -33
- data/lib/gloo/help/objs/basic/decimal.txt +0 -28
- data/lib/gloo/help/objs/basic/integer.txt +0 -27
- data/lib/gloo/help/objs/basic/script.txt +0 -29
- data/lib/gloo/help/objs/basic/string.txt +0 -28
- data/lib/gloo/help/objs/basic/text.txt +0 -27
- data/lib/gloo/help/objs/basic/untyped.txt +0 -22
- data/lib/gloo/help/objs/cli/banner.txt +0 -49
- data/lib/gloo/help/objs/cli/bar.txt +0 -37
- data/lib/gloo/help/objs/cli/colorize.txt +0 -33
- data/lib/gloo/help/objs/cli/confirm.txt +0 -26
- data/lib/gloo/help/objs/cli/menu.txt +0 -44
- data/lib/gloo/help/objs/cli/menu_item.txt +0 -26
- data/lib/gloo/help/objs/cli/pastel.txt +0 -43
- data/lib/gloo/help/objs/cli/prompt.txt +0 -27
- data/lib/gloo/help/objs/cli/select.txt +0 -34
- data/lib/gloo/help/objs/ctrl/each.txt +0 -48
- data/lib/gloo/help/objs/ctrl/repeat.txt +0 -38
- data/lib/gloo/help/objs/data/markdown.txt +0 -25
- data/lib/gloo/help/objs/data/mysql.txt +0 -40
- data/lib/gloo/help/objs/data/query.txt +0 -37
- data/lib/gloo/help/objs/data/sqlite.txt +0 -26
- data/lib/gloo/help/objs/data/table.txt +0 -46
- data/lib/gloo/help/objs/dev/git_repo.txt +0 -36
- data/lib/gloo/help/objs/dev/stats.txt +0 -36
- data/lib/gloo/help/objs/dt/date.txt +0 -23
- data/lib/gloo/help/objs/dt/datetime.txt +0 -24
- data/lib/gloo/help/objs/dt/time.txt +0 -23
- data/lib/gloo/help/objs/ror/erb.txt +0 -37
- data/lib/gloo/help/objs/ror/eval.txt +0 -24
- data/lib/gloo/help/objs/snd/play.txt +0 -23
- data/lib/gloo/help/objs/snd/say.txt +0 -28
- data/lib/gloo/help/objs/system/file.txt +0 -48
- data/lib/gloo/help/objs/system/ssh_exec.txt +0 -30
- data/lib/gloo/help/objs/system/system.txt +0 -32
- data/lib/gloo/help/objs/web/http_get.txt +0 -35
- data/lib/gloo/help/objs/web/http_post.txt +0 -34
- data/lib/gloo/help/objs/web/json.txt +0 -34
- data/lib/gloo/help/objs/web/slack.txt +0 -33
- data/lib/gloo/help/objs/web/teams.txt +0 -30
- data/lib/gloo/help/objs/web/uri.txt +0 -38
- data/lib/gloo/help/verbs/alert.txt +0 -33
- data/lib/gloo/help/verbs/beep.txt +0 -25
- data/lib/gloo/help/verbs/cls.txt +0 -24
- data/lib/gloo/help/verbs/context.txt +0 -43
- data/lib/gloo/help/verbs/create.txt +0 -33
- data/lib/gloo/help/verbs/execute.txt +0 -27
- data/lib/gloo/help/verbs/help.txt +0 -34
- data/lib/gloo/help/verbs/if.txt +0 -37
- data/lib/gloo/help/verbs/list.txt +0 -34
- data/lib/gloo/help/verbs/load.txt +0 -38
- data/lib/gloo/help/verbs/move.txt +0 -42
- data/lib/gloo/help/verbs/put.txt +0 -38
- data/lib/gloo/help/verbs/quit.txt +0 -25
- data/lib/gloo/help/verbs/run.txt +0 -41
- data/lib/gloo/help/verbs/save.txt +0 -26
- data/lib/gloo/help/verbs/show.txt +0 -30
- data/lib/gloo/help/verbs/tell.txt +0 -34
- data/lib/gloo/help/verbs/unless.txt +0 -38
- data/lib/gloo/help/verbs/version.txt +0 -32
- data/lib/gloo/help/verbs/wait.txt +0 -29
- data/lib/gloo/objs/basic/alias.rb +0 -78
- data/lib/gloo/objs/basic/boolean.rb +0 -120
- data/lib/gloo/objs/basic/container.rb +0 -76
- data/lib/gloo/objs/basic/decimal.rb +0 -76
- data/lib/gloo/objs/basic/integer.rb +0 -73
- data/lib/gloo/objs/basic/script.rb +0 -99
- data/lib/gloo/objs/basic/string.rb +0 -77
- data/lib/gloo/objs/basic/text.rb +0 -87
- data/lib/gloo/objs/basic/untyped.rb +0 -41
- data/lib/gloo/objs/ctrl/each.rb +0 -279
- data/lib/gloo/objs/ctrl/repeat.rb +0 -108
- data/lib/gloo/objs/data/markdown.rb +0 -84
- data/lib/gloo/objs/data/query.rb +0 -176
- data/lib/gloo/objs/data/table.rb +0 -140
- data/lib/gloo/objs/dt/date.rb +0 -50
- data/lib/gloo/objs/dt/datetime.rb +0 -62
- data/lib/gloo/objs/dt/time.rb +0 -50
- data/lib/gloo/objs/ror/erb.rb +0 -116
- data/lib/gloo/objs/ror/eval.rb +0 -107
- data/lib/gloo/objs/web/http_get.rb +0 -159
- data/lib/gloo/objs/web/http_post.rb +0 -183
- data/lib/gloo/objs/web/json.rb +0 -135
- data/lib/gloo/objs/web/slack.rb +0 -130
- data/lib/gloo/objs/web/teams.rb +0 -117
- data/lib/gloo/objs/web/uri.rb +0 -148
- data/lib/gloo/persist/file_loader.rb +0 -191
- data/lib/gloo/persist/file_saver.rb +0 -49
- data/lib/gloo/persist/file_storage.rb +0 -45
- data/lib/gloo/persist/line_splitter.rb +0 -81
- data/lib/gloo/persist/persist_man.rb +0 -120
- data/lib/gloo/utils/format.rb +0 -21
- data/lib/gloo/utils/stats.rb +0 -205
- data/lib/gloo/utils/words.rb +0 -19
- data/lib/gloo/verbs/context.rb +0 -62
- data/lib/gloo/verbs/create.rb +0 -68
- data/lib/gloo/verbs/execute.rb +0 -56
- data/lib/gloo/verbs/if.rb +0 -92
- data/lib/gloo/verbs/list.rb +0 -98
- data/lib/gloo/verbs/load.rb +0 -45
- data/lib/gloo/verbs/move.rb +0 -89
- data/lib/gloo/verbs/put.rb +0 -94
- data/lib/gloo/verbs/quit.rb +0 -40
- data/lib/gloo/verbs/run.rb +0 -75
- data/lib/gloo/verbs/save.rb +0 -39
- data/lib/gloo/verbs/show.rb +0 -64
- data/lib/gloo/verbs/tell.rb +0 -79
- data/lib/gloo/verbs/unless.rb +0 -92
- data/lib/gloo/verbs/wait.rb +0 -42
data/lib/gloo/core/baseo.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
-
# Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
|
3
|
-
#
|
4
|
-
# An abstract base object.
|
5
|
-
# All objects and verbs derive from this.
|
6
|
-
#
|
7
|
-
|
8
|
-
module Gloo
|
9
|
-
module Core
|
10
|
-
class Baseo
|
11
|
-
|
12
|
-
attr_accessor :name
|
13
|
-
|
14
|
-
NOT_IMPLEMENTED_ERR = 'Not implemented yet!'.freeze
|
15
|
-
|
16
|
-
# Set up the object.
|
17
|
-
def initialize
|
18
|
-
@name = ''
|
19
|
-
end
|
20
|
-
|
21
|
-
#
|
22
|
-
# The object type, suitable for display.
|
23
|
-
#
|
24
|
-
def type_display
|
25
|
-
raise 'this method should be overriden'
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
data/lib/gloo/core/dictionary.rb
DELETED
@@ -1,181 +0,0 @@
|
|
1
|
-
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
-
# Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
|
3
|
-
#
|
4
|
-
# A dictionary of Objects and Verbs.
|
5
|
-
#
|
6
|
-
require 'singleton'
|
7
|
-
|
8
|
-
module Gloo
|
9
|
-
module Core
|
10
|
-
class Dictionary
|
11
|
-
|
12
|
-
include Singleton
|
13
|
-
|
14
|
-
attr_reader :verbs, :objs, :keywords
|
15
|
-
|
16
|
-
#
|
17
|
-
# Set up the object dictionary.
|
18
|
-
#
|
19
|
-
def initialize
|
20
|
-
@verbs = {}
|
21
|
-
@objs = {}
|
22
|
-
@verb_references = []
|
23
|
-
@obj_references = []
|
24
|
-
@keywords = []
|
25
|
-
end
|
26
|
-
|
27
|
-
#
|
28
|
-
# Register a verb.
|
29
|
-
#
|
30
|
-
def register_verb( subclass )
|
31
|
-
@verb_references << subclass
|
32
|
-
end
|
33
|
-
|
34
|
-
#
|
35
|
-
# Register an object type.
|
36
|
-
#
|
37
|
-
def register_obj( subclass )
|
38
|
-
@obj_references << subclass
|
39
|
-
end
|
40
|
-
|
41
|
-
#
|
42
|
-
# Initialize verbs and objects in the dictionary.
|
43
|
-
#
|
44
|
-
def init
|
45
|
-
$log.debug 'initializing dictionaries'
|
46
|
-
init_verbs
|
47
|
-
init_objs
|
48
|
-
end
|
49
|
-
|
50
|
-
#
|
51
|
-
# Is the given word an object type?
|
52
|
-
#
|
53
|
-
def obj?( word )
|
54
|
-
return false unless word
|
55
|
-
|
56
|
-
return @objs.key?( word.downcase )
|
57
|
-
end
|
58
|
-
|
59
|
-
#
|
60
|
-
# Find the object type by name.
|
61
|
-
#
|
62
|
-
def find_obj( word )
|
63
|
-
return nil unless word
|
64
|
-
return nil unless obj?( word )
|
65
|
-
|
66
|
-
return @objs[ word.downcase ]
|
67
|
-
end
|
68
|
-
|
69
|
-
#
|
70
|
-
# Is the given word a verb?
|
71
|
-
#
|
72
|
-
def verb?( word )
|
73
|
-
return false unless word
|
74
|
-
|
75
|
-
return @verbs.key?( word.downcase )
|
76
|
-
end
|
77
|
-
|
78
|
-
#
|
79
|
-
# Find the verb by name.
|
80
|
-
#
|
81
|
-
def find_verb( verb )
|
82
|
-
return nil unless verb
|
83
|
-
return nil unless verb?( verb )
|
84
|
-
|
85
|
-
return @verbs[ verb.downcase ]
|
86
|
-
end
|
87
|
-
|
88
|
-
#
|
89
|
-
# Get the list of verbs, sorted.
|
90
|
-
#
|
91
|
-
def get_obj_types
|
92
|
-
return @obj_references.sort { |a, b| a.typename <=> b.typename }
|
93
|
-
end
|
94
|
-
|
95
|
-
#
|
96
|
-
# Get the list of verbs, sorted.
|
97
|
-
#
|
98
|
-
def get_verbs
|
99
|
-
return @verb_references.sort { |a, b| a.keyword <=> b.keyword }
|
100
|
-
end
|
101
|
-
|
102
|
-
#
|
103
|
-
# Lookup the keyword by name or shortcut.
|
104
|
-
# Return the keyword (name) or nil if it is not found.
|
105
|
-
#
|
106
|
-
def lookup_keyword( key )
|
107
|
-
v = find_verb key
|
108
|
-
return v.keyword if v
|
109
|
-
|
110
|
-
o = find_obj key
|
111
|
-
return o.typename if o
|
112
|
-
|
113
|
-
return nil
|
114
|
-
end
|
115
|
-
|
116
|
-
#
|
117
|
-
# Show a list of all keywords.
|
118
|
-
# This includes verbs and objects, names and shortcuts.
|
119
|
-
#
|
120
|
-
def show_keywords
|
121
|
-
str = ''
|
122
|
-
@keywords.sort.each_with_index do |k, i|
|
123
|
-
str << k.ljust( 20, ' ' )
|
124
|
-
if ( ( i + 1 ) % 6 ).zero?
|
125
|
-
puts str
|
126
|
-
str = ''
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
# ---------------------------------------------------------------------
|
132
|
-
# Private
|
133
|
-
# ---------------------------------------------------------------------
|
134
|
-
|
135
|
-
private
|
136
|
-
|
137
|
-
#
|
138
|
-
# Add a keyword to the keyword list.
|
139
|
-
# Report an error if the keyword is already in the list.
|
140
|
-
#
|
141
|
-
def add_key( keyword )
|
142
|
-
if @keywords.include?( keyword )
|
143
|
-
$log.error "duplicate keyword '#{keyword}'"
|
144
|
-
return
|
145
|
-
end
|
146
|
-
|
147
|
-
@keywords << keyword
|
148
|
-
end
|
149
|
-
|
150
|
-
#
|
151
|
-
# Init the list of objects.
|
152
|
-
#
|
153
|
-
def init_objs
|
154
|
-
$log.debug "initializing #{@obj_references.count} objects"
|
155
|
-
@obj_references.each do |o|
|
156
|
-
$log.debug o
|
157
|
-
@objs[ o.typename ] = o
|
158
|
-
@objs[ o.short_typename ] = o
|
159
|
-
add_key o.typename
|
160
|
-
add_key o.short_typename if o.typename != o.short_typename
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
#
|
165
|
-
# Init the list of verbs.
|
166
|
-
#
|
167
|
-
def init_verbs
|
168
|
-
$log.debug "initializing #{@verb_references.count} verbs"
|
169
|
-
@verb_references.each do |v|
|
170
|
-
$log.debug v
|
171
|
-
@verbs[ v.keyword ] = v
|
172
|
-
@verbs[ v.keyword_shortcut ] = v
|
173
|
-
# v.send( :new ).run
|
174
|
-
add_key v.keyword
|
175
|
-
add_key v.keyword_shortcut if v.keyword != v.keyword_shortcut
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
end
|
180
|
-
end
|
181
|
-
end
|
data/lib/gloo/core/error.rb
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
-
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
3
|
-
#
|
4
|
-
# If the last command to run generated an error it will be here.
|
5
|
-
#
|
6
|
-
|
7
|
-
module Gloo
|
8
|
-
module Core
|
9
|
-
class Error
|
10
|
-
|
11
|
-
attr_accessor :value, :error_count
|
12
|
-
|
13
|
-
#
|
14
|
-
# Set up the error object.
|
15
|
-
#
|
16
|
-
def initialize
|
17
|
-
clear
|
18
|
-
end
|
19
|
-
|
20
|
-
#
|
21
|
-
# Clear out the error message.
|
22
|
-
#
|
23
|
-
def clear
|
24
|
-
@error_count = 0
|
25
|
-
@value = nil
|
26
|
-
end
|
27
|
-
|
28
|
-
#
|
29
|
-
# Set the value of error.
|
30
|
-
#
|
31
|
-
def set_to( new_value )
|
32
|
-
@error_count += 1
|
33
|
-
@value = new_value
|
34
|
-
end
|
35
|
-
|
36
|
-
#
|
37
|
-
# Start counting errors.
|
38
|
-
# We're looking to see if we get any new ones during
|
39
|
-
# a script or an immediate command.
|
40
|
-
#
|
41
|
-
def start_tracking
|
42
|
-
@error_count = 0
|
43
|
-
end
|
44
|
-
|
45
|
-
#
|
46
|
-
# Clear out error if we didn't add any new ones.
|
47
|
-
#
|
48
|
-
def clear_if_no_errors
|
49
|
-
self.clear if @error_count.zero?
|
50
|
-
end
|
51
|
-
|
52
|
-
#
|
53
|
-
# Get the string representation of the error.
|
54
|
-
#
|
55
|
-
def to_s
|
56
|
-
return @value.to_s
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
-
# Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
|
3
|
-
#
|
4
|
-
# The Event Manager.
|
5
|
-
# Run scripts in response to pre-defined events.
|
6
|
-
#
|
7
|
-
|
8
|
-
module Gloo
|
9
|
-
module Core
|
10
|
-
class EventManager
|
11
|
-
|
12
|
-
#
|
13
|
-
# Set up the event manager.
|
14
|
-
#
|
15
|
-
def initialize
|
16
|
-
$log.debug 'event manager intialized...'
|
17
|
-
end
|
18
|
-
|
19
|
-
#
|
20
|
-
# Run on_load scripts in the recently loaded object
|
21
|
-
# If no obj is given the script will be run in root.
|
22
|
-
#
|
23
|
-
def on_load( obj = nil, in_heap = false )
|
24
|
-
return unless obj || in_heap
|
25
|
-
|
26
|
-
$log.debug 'on_load event'
|
27
|
-
arr = Gloo::Core::ObjFinder.by_name 'on_load', obj
|
28
|
-
arr.each { |o| Gloo::Exec::Dispatch.message 'run', o }
|
29
|
-
end
|
30
|
-
|
31
|
-
#
|
32
|
-
# Run on_unload scripts in the object that will be unloaded.
|
33
|
-
#
|
34
|
-
def on_unload( obj )
|
35
|
-
return unless obj
|
36
|
-
|
37
|
-
$log.debug 'on_unload event'
|
38
|
-
arr = Gloo::Core::ObjFinder.by_name 'on_unload', obj
|
39
|
-
arr.each { |o| Gloo::Exec::Dispatch.message 'run', o }
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
data/lib/gloo/core/factory.rb
DELETED
@@ -1,210 +0,0 @@
|
|
1
|
-
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
-
# Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
|
3
|
-
#
|
4
|
-
# An object factory.
|
5
|
-
#
|
6
|
-
|
7
|
-
module Gloo
|
8
|
-
module Core
|
9
|
-
class Factory < Baseo
|
10
|
-
|
11
|
-
# ---------------------------------------------------------------------
|
12
|
-
# Initializer
|
13
|
-
# ---------------------------------------------------------------------
|
14
|
-
|
15
|
-
#
|
16
|
-
# Set up the object factory.
|
17
|
-
#
|
18
|
-
def initialize
|
19
|
-
$log.debug 'object factory intialized...'
|
20
|
-
end
|
21
|
-
|
22
|
-
# ---------------------------------------------------------------------
|
23
|
-
# Factory Helpers
|
24
|
-
# ---------------------------------------------------------------------
|
25
|
-
|
26
|
-
#
|
27
|
-
# Helper shortcut to create an alias child object.
|
28
|
-
#
|
29
|
-
def create_alias( name, value, parent )
|
30
|
-
params = { :name => name,
|
31
|
-
:type => 'alias',
|
32
|
-
:value => value,
|
33
|
-
:parent => parent }
|
34
|
-
create params
|
35
|
-
end
|
36
|
-
|
37
|
-
#
|
38
|
-
# Helper shortcut to create a string child object.
|
39
|
-
#
|
40
|
-
def create_untyped( name, value, parent )
|
41
|
-
params = { :name => name,
|
42
|
-
:type => 'untyped',
|
43
|
-
:value => value,
|
44
|
-
:parent => parent }
|
45
|
-
create params
|
46
|
-
end
|
47
|
-
|
48
|
-
#
|
49
|
-
# Helper shortcut to create a string child object.
|
50
|
-
#
|
51
|
-
def create_string( name, value, parent )
|
52
|
-
params = { :name => name,
|
53
|
-
:type => 'string',
|
54
|
-
:value => value,
|
55
|
-
:parent => parent }
|
56
|
-
create params
|
57
|
-
end
|
58
|
-
|
59
|
-
#
|
60
|
-
# Helper shortcut to create a text child object.
|
61
|
-
#
|
62
|
-
def create_text( name, value, parent )
|
63
|
-
params = { :name => name,
|
64
|
-
:type => 'text',
|
65
|
-
:value => value,
|
66
|
-
:parent => parent }
|
67
|
-
create params
|
68
|
-
end
|
69
|
-
|
70
|
-
#
|
71
|
-
# Helper shortcut to create an integer child object.
|
72
|
-
#
|
73
|
-
def create_int( name, value, parent )
|
74
|
-
params = { :name => name,
|
75
|
-
:type => 'integer',
|
76
|
-
:value => value,
|
77
|
-
:parent => parent }
|
78
|
-
create params
|
79
|
-
end
|
80
|
-
|
81
|
-
#
|
82
|
-
# Helper shortcut to create a boolean child object.
|
83
|
-
#
|
84
|
-
def create_bool( name, value, parent )
|
85
|
-
params = { :name => name,
|
86
|
-
:type => 'boolean',
|
87
|
-
:value => value,
|
88
|
-
:parent => parent }
|
89
|
-
create params
|
90
|
-
end
|
91
|
-
|
92
|
-
#
|
93
|
-
# Helper shortcut to create a container child object.
|
94
|
-
#
|
95
|
-
def create_can( name, parent )
|
96
|
-
params = { :name => name,
|
97
|
-
:type => 'container',
|
98
|
-
:value => nil,
|
99
|
-
:parent => parent }
|
100
|
-
create params
|
101
|
-
end
|
102
|
-
|
103
|
-
#
|
104
|
-
# Helper shortcut to create a script child object.
|
105
|
-
#
|
106
|
-
def create_script( name, value, parent )
|
107
|
-
params = { :name => name,
|
108
|
-
:type => 'script',
|
109
|
-
:value => value,
|
110
|
-
:parent => parent }
|
111
|
-
create params
|
112
|
-
end
|
113
|
-
|
114
|
-
#
|
115
|
-
# Helper shortcut to create a file child object.
|
116
|
-
#
|
117
|
-
def create_file( name, value, parent )
|
118
|
-
params = { :name => name,
|
119
|
-
:type => 'file',
|
120
|
-
:value => value,
|
121
|
-
:parent => parent }
|
122
|
-
create params
|
123
|
-
end
|
124
|
-
|
125
|
-
# ---------------------------------------------------------------------
|
126
|
-
# Object Factory
|
127
|
-
# ---------------------------------------------------------------------
|
128
|
-
|
129
|
-
# Create object with given name, type and value.
|
130
|
-
# One of either name or type is required.
|
131
|
-
# All values are optional when considered on their own.
|
132
|
-
# Parameter hash keys:
|
133
|
-
# :name - the name of the object
|
134
|
-
# :type - the name of the type
|
135
|
-
# :value - the initial object value
|
136
|
-
# :parent - the parent object
|
137
|
-
# :squash_duplicates - if the object exists, use it rather
|
138
|
-
# than creating a new one? Default = true
|
139
|
-
def create( params )
|
140
|
-
objtype = find_type params[ :type ]
|
141
|
-
return nil unless objtype
|
142
|
-
|
143
|
-
pn = Gloo::Core::Pn.new params[ :name ]
|
144
|
-
parent = params[ :parent ]
|
145
|
-
if parent.nil?
|
146
|
-
parent = pn.get_parent
|
147
|
-
obj_name = pn.name
|
148
|
-
else
|
149
|
-
obj_name = params[ :name ]
|
150
|
-
end
|
151
|
-
|
152
|
-
if pn.exists? && params[ :squash_duplicates ]
|
153
|
-
$log.debug "Updating existing object: #{obj_name}"
|
154
|
-
return self.update_existing pn, params[ :value ]
|
155
|
-
end
|
156
|
-
|
157
|
-
$log.debug "Creating new object: #{obj_name}"
|
158
|
-
return create_new obj_name, params[ :value ], objtype, parent
|
159
|
-
end
|
160
|
-
|
161
|
-
#
|
162
|
-
# Create a new object.
|
163
|
-
#
|
164
|
-
def create_new( name, value, type, parent )
|
165
|
-
unless parent
|
166
|
-
$log.error "Could not create object. Bad path: #{name}"
|
167
|
-
return nil
|
168
|
-
end
|
169
|
-
|
170
|
-
o = type.new
|
171
|
-
o.name = name
|
172
|
-
o.set_value value
|
173
|
-
parent.add_child( o )
|
174
|
-
return o
|
175
|
-
end
|
176
|
-
|
177
|
-
#
|
178
|
-
# Find and Update an existing object.
|
179
|
-
#
|
180
|
-
def update_existing( pn, value )
|
181
|
-
o = pn.resolve
|
182
|
-
o.set_value value
|
183
|
-
return o
|
184
|
-
end
|
185
|
-
|
186
|
-
#
|
187
|
-
# Find the object type by name.
|
188
|
-
# Return nil if the object type cannot be found or
|
189
|
-
# cannot be created.
|
190
|
-
#
|
191
|
-
def find_type( type_name )
|
192
|
-
type_name = 'untyped' if type_name.nil? || type_name.strip.empty?
|
193
|
-
t = $engine.dictionary.find_obj( type_name )
|
194
|
-
|
195
|
-
if t.nil?
|
196
|
-
$log.warn "Could not find type, '#{type_name}'"
|
197
|
-
return nil
|
198
|
-
end
|
199
|
-
|
200
|
-
unless t.can_create?
|
201
|
-
$log.error "'#{type_name}' cannot be created."
|
202
|
-
return nil
|
203
|
-
end
|
204
|
-
|
205
|
-
return t
|
206
|
-
end
|
207
|
-
|
208
|
-
end
|
209
|
-
end
|
210
|
-
end
|