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,21 @@
|
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
|
2
|
+
# Copyright:: Copyright (c) 202 Eric Crane. All rights reserved.
|
|
3
|
+
#
|
|
4
|
+
# Conversion tool: String to Date Time.
|
|
5
|
+
#
|
|
6
|
+
require 'chronic'
|
|
7
|
+
|
|
8
|
+
module Gloo
|
|
9
|
+
module Convert
|
|
10
|
+
class StringToDateTime
|
|
11
|
+
|
|
12
|
+
#
|
|
13
|
+
# Convert the given string value to a date and time.
|
|
14
|
+
#
|
|
15
|
+
def convert( value )
|
|
16
|
+
return Chronic.parse( value )
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
|
2
|
+
# Copyright:: Copyright (c) 202 Eric Crane. All rights reserved.
|
|
3
|
+
#
|
|
4
|
+
# Conversion tool: String to Decimal.
|
|
5
|
+
#
|
|
6
|
+
|
|
7
|
+
module Gloo
|
|
8
|
+
module Convert
|
|
9
|
+
class StringToDecimal
|
|
10
|
+
|
|
11
|
+
#
|
|
12
|
+
# Convert the given string value to an integer.
|
|
13
|
+
#
|
|
14
|
+
def convert( value )
|
|
15
|
+
return value.to_f
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
|
2
|
+
# Copyright:: Copyright (c) 202 Eric Crane. All rights reserved.
|
|
3
|
+
#
|
|
4
|
+
# Conversion tool: String to Integer.
|
|
5
|
+
#
|
|
6
|
+
|
|
7
|
+
module Gloo
|
|
8
|
+
module Convert
|
|
9
|
+
class StringToInteger
|
|
10
|
+
|
|
11
|
+
#
|
|
12
|
+
# Convert the given string value to an integer.
|
|
13
|
+
#
|
|
14
|
+
def convert( value )
|
|
15
|
+
return value.to_i
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
data/lib/gloo/core/baseo.rb
CHANGED
|
@@ -8,17 +8,17 @@
|
|
|
8
8
|
module Gloo
|
|
9
9
|
module Core
|
|
10
10
|
class Baseo
|
|
11
|
-
|
|
11
|
+
|
|
12
12
|
attr_accessor :name
|
|
13
|
-
|
|
13
|
+
|
|
14
14
|
# Set up the object.
|
|
15
|
-
def initialize
|
|
16
|
-
@name =
|
|
15
|
+
def initialize
|
|
16
|
+
@name = ''
|
|
17
17
|
end
|
|
18
|
-
|
|
19
|
-
#
|
|
18
|
+
|
|
19
|
+
#
|
|
20
20
|
# The object type, suitable for display.
|
|
21
|
-
#
|
|
21
|
+
#
|
|
22
22
|
def type_display
|
|
23
23
|
raise 'this method should be overriden'
|
|
24
24
|
end
|
data/lib/gloo/core/dictionary.rb
CHANGED
|
@@ -8,32 +8,32 @@ require 'singleton'
|
|
|
8
8
|
module Gloo
|
|
9
9
|
module Core
|
|
10
10
|
class Dictionary
|
|
11
|
-
|
|
11
|
+
|
|
12
12
|
include Singleton
|
|
13
|
-
|
|
13
|
+
|
|
14
14
|
attr_reader :verbs, :objs
|
|
15
|
-
|
|
15
|
+
|
|
16
16
|
# Set up the object dictionary.
|
|
17
|
-
def initialize
|
|
17
|
+
def initialize
|
|
18
18
|
@verbs = {}
|
|
19
19
|
@objs = {}
|
|
20
20
|
@verb_references = []
|
|
21
21
|
@obj_references = []
|
|
22
22
|
end
|
|
23
|
-
|
|
23
|
+
|
|
24
24
|
# Register a verb.
|
|
25
|
-
def register_verb subclass
|
|
25
|
+
def register_verb( subclass )
|
|
26
26
|
@verb_references << subclass
|
|
27
27
|
end
|
|
28
|
-
|
|
28
|
+
|
|
29
29
|
# Register an object type.
|
|
30
|
-
def register_obj subclass
|
|
30
|
+
def register_obj( subclass )
|
|
31
31
|
@obj_references << subclass
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
# Initialize verbs and objects in the dictionary.
|
|
35
35
|
def init
|
|
36
|
-
$log.debug
|
|
36
|
+
$log.debug 'initializing dictionaries'
|
|
37
37
|
init_verbs
|
|
38
38
|
init_objs
|
|
39
39
|
end
|
|
@@ -42,60 +42,63 @@ module Gloo
|
|
|
42
42
|
def init_objs
|
|
43
43
|
$log.debug "initializing #{@obj_references.count} objects"
|
|
44
44
|
@obj_references.each do |o|
|
|
45
|
-
$log.debug
|
|
45
|
+
$log.debug o
|
|
46
46
|
@objs[ o.typename ] = o
|
|
47
47
|
@objs[ o.short_typename ] = o
|
|
48
48
|
end
|
|
49
49
|
end
|
|
50
|
-
|
|
50
|
+
|
|
51
51
|
# Is the given word an object type?
|
|
52
|
-
def
|
|
52
|
+
def obj?( word )
|
|
53
53
|
return false unless word
|
|
54
|
+
|
|
54
55
|
return @objs.key?( word.downcase )
|
|
55
56
|
end
|
|
56
|
-
|
|
57
|
+
|
|
57
58
|
# Find the object type by name.
|
|
58
|
-
def find_obj word
|
|
59
|
+
def find_obj( word )
|
|
59
60
|
return nil unless word
|
|
60
|
-
return nil unless
|
|
61
|
+
return nil unless obj?( word )
|
|
62
|
+
|
|
61
63
|
return @objs[ word.downcase ]
|
|
62
64
|
end
|
|
63
65
|
|
|
64
|
-
|
|
65
66
|
# Init the list of verbs.
|
|
66
67
|
def init_verbs
|
|
67
68
|
$log.debug "initializing #{@verb_references.count} verbs"
|
|
68
69
|
@verb_references.each do |v|
|
|
69
|
-
$log.debug
|
|
70
|
+
$log.debug v
|
|
70
71
|
@verbs[ v.keyword ] = v
|
|
71
72
|
@verbs[ v.keyword_shortcut ] = v
|
|
72
73
|
# v.send( :new ).run
|
|
73
74
|
end
|
|
74
75
|
end
|
|
75
|
-
|
|
76
|
+
|
|
76
77
|
# Is the given word a verb?
|
|
77
|
-
def
|
|
78
|
+
def verb?( word )
|
|
78
79
|
return false unless word
|
|
80
|
+
|
|
79
81
|
return @verbs.key?( word.downcase )
|
|
80
82
|
end
|
|
81
|
-
|
|
83
|
+
|
|
82
84
|
# Find the verb by name.
|
|
83
|
-
def find_verb verb
|
|
85
|
+
def find_verb( verb )
|
|
84
86
|
return nil unless verb
|
|
85
|
-
return nil unless
|
|
87
|
+
return nil unless verb?( verb )
|
|
88
|
+
|
|
86
89
|
return @verbs[ verb.downcase ]
|
|
87
90
|
end
|
|
88
|
-
|
|
91
|
+
|
|
89
92
|
# Get the list of verbs, sorted.
|
|
90
93
|
def get_obj_types
|
|
91
|
-
return @obj_references.sort{ |a,b| a.typename <=> b.typename }
|
|
94
|
+
return @obj_references.sort { |a, b| a.typename <=> b.typename }
|
|
92
95
|
end
|
|
93
|
-
|
|
96
|
+
|
|
94
97
|
# Get the list of verbs, sorted.
|
|
95
98
|
def get_verbs
|
|
96
|
-
return @verb_references.sort{ |a,b| a.keyword <=> b.keyword }
|
|
99
|
+
return @verb_references.sort { |a, b| a.keyword <=> b.keyword }
|
|
97
100
|
end
|
|
98
|
-
|
|
101
|
+
|
|
99
102
|
end
|
|
100
103
|
end
|
|
101
104
|
end
|
|
@@ -0,0 +1,50 @@
|
|
|
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
|
|
12
|
+
|
|
13
|
+
# Set up the error object.
|
|
14
|
+
def initialize
|
|
15
|
+
@value = nil
|
|
16
|
+
@error_count = 0
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Set the value of error.
|
|
20
|
+
def set_to( new_value )
|
|
21
|
+
@error_count += 1
|
|
22
|
+
@value = new_value
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Clear out the error message.
|
|
26
|
+
def clear
|
|
27
|
+
@error_count = 0
|
|
28
|
+
@value = nil
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Start counting errors.
|
|
32
|
+
# We're looking to see if we get any new ones during
|
|
33
|
+
# a script or an immediate command.
|
|
34
|
+
def start_tracking
|
|
35
|
+
@error_count = 0
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Clear out error if we didn't add any new ones.
|
|
39
|
+
def clear_if_no_errors
|
|
40
|
+
self.clear if @error_count.zero?
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Get the string representation of the error.
|
|
44
|
+
def to_s
|
|
45
|
+
return @value.to_s
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -8,39 +8,33 @@
|
|
|
8
8
|
module Gloo
|
|
9
9
|
module Core
|
|
10
10
|
class EventManager
|
|
11
|
-
|
|
11
|
+
|
|
12
12
|
# Set up the event manager.
|
|
13
|
-
def initialize
|
|
14
|
-
$log.debug
|
|
13
|
+
def initialize
|
|
14
|
+
$log.debug 'event manager intialized...'
|
|
15
15
|
end
|
|
16
|
-
|
|
17
|
-
#
|
|
16
|
+
|
|
17
|
+
#
|
|
18
18
|
# Run on_load scripts in the recently loaded object
|
|
19
19
|
# If no obj is given the script will be run in root.
|
|
20
|
-
#
|
|
21
|
-
def on_load obj=nil, in_heap=false
|
|
20
|
+
#
|
|
21
|
+
def on_load( obj = nil, in_heap = false )
|
|
22
22
|
return unless obj || in_heap
|
|
23
|
-
|
|
24
|
-
arr.
|
|
25
|
-
|
|
26
|
-
o.send_message "run"
|
|
27
|
-
end
|
|
28
|
-
end
|
|
23
|
+
|
|
24
|
+
arr = Gloo::Core::ObjFinder.by_name 'on_load', obj
|
|
25
|
+
arr.each { |o| Gloo::Exec::Dispatch.message 'run', o }
|
|
29
26
|
end
|
|
30
27
|
|
|
31
|
-
#
|
|
28
|
+
#
|
|
32
29
|
# Run on_unload scripts in the object that will be unloaded.
|
|
33
|
-
#
|
|
34
|
-
def on_unload obj
|
|
30
|
+
#
|
|
31
|
+
def on_unload( obj )
|
|
35
32
|
return unless obj
|
|
36
|
-
|
|
37
|
-
arr.
|
|
38
|
-
|
|
39
|
-
o.send_message "run"
|
|
40
|
-
end
|
|
41
|
-
end
|
|
33
|
+
|
|
34
|
+
arr = Gloo::Core::ObjFinder.by_name 'on_unload', obj
|
|
35
|
+
arr.each { |o| Gloo::Exec::Dispatch.message 'run', o }
|
|
42
36
|
end
|
|
43
|
-
|
|
37
|
+
|
|
44
38
|
end
|
|
45
39
|
end
|
|
46
40
|
end
|
data/lib/gloo/core/factory.rb
CHANGED
|
@@ -7,61 +7,171 @@
|
|
|
7
7
|
module Gloo
|
|
8
8
|
module Core
|
|
9
9
|
class Factory < Baseo
|
|
10
|
-
|
|
10
|
+
|
|
11
|
+
# ---------------------------------------------------------------------
|
|
12
|
+
# Initializer
|
|
13
|
+
# ---------------------------------------------------------------------
|
|
14
|
+
|
|
15
|
+
#
|
|
11
16
|
# Set up the object factory.
|
|
12
|
-
|
|
13
|
-
|
|
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 a string child object.
|
|
28
|
+
#
|
|
29
|
+
def create_untyped( name, value, parent )
|
|
30
|
+
params = { :name => name,
|
|
31
|
+
:type => 'untyped',
|
|
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_string( name, value, parent )
|
|
41
|
+
params = { :name => name,
|
|
42
|
+
:type => 'string',
|
|
43
|
+
:value => value,
|
|
44
|
+
:parent => parent }
|
|
45
|
+
create params
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
#
|
|
49
|
+
# Helper shortcut to create an integer child object.
|
|
50
|
+
#
|
|
51
|
+
def create_int( name, value, parent )
|
|
52
|
+
params = { :name => name,
|
|
53
|
+
:type => 'integer',
|
|
54
|
+
:value => value,
|
|
55
|
+
:parent => parent }
|
|
56
|
+
create params
|
|
14
57
|
end
|
|
15
|
-
|
|
58
|
+
|
|
59
|
+
#
|
|
60
|
+
# Helper shortcut to create a boolean child object.
|
|
61
|
+
#
|
|
62
|
+
def create_bool( name, value, parent )
|
|
63
|
+
params = { :name => name,
|
|
64
|
+
:type => 'boolean',
|
|
65
|
+
:value => value,
|
|
66
|
+
:parent => parent }
|
|
67
|
+
create params
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
#
|
|
71
|
+
# Helper shortcut to create a container child object.
|
|
72
|
+
#
|
|
73
|
+
def create_can( name, parent )
|
|
74
|
+
params = { :name => name,
|
|
75
|
+
:type => 'container',
|
|
76
|
+
:value => nil,
|
|
77
|
+
:parent => parent }
|
|
78
|
+
create params
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
#
|
|
82
|
+
# Helper shortcut to create a script child object.
|
|
83
|
+
#
|
|
84
|
+
def create_script( name, value, parent )
|
|
85
|
+
params = { :name => name,
|
|
86
|
+
:type => 'script',
|
|
87
|
+
:value => value,
|
|
88
|
+
:parent => parent }
|
|
89
|
+
create params
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# ---------------------------------------------------------------------
|
|
93
|
+
# Object Factory
|
|
94
|
+
# ---------------------------------------------------------------------
|
|
95
|
+
|
|
16
96
|
# Create object with given name, type and value.
|
|
17
97
|
# One of either name or type is required.
|
|
18
98
|
# All values are optional when considered on their own.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
99
|
+
# Parameter hash keys:
|
|
100
|
+
# :name - the name of the object
|
|
101
|
+
# :type - the name of the type
|
|
102
|
+
# :value - the initial object value
|
|
103
|
+
# :parent - the parent object
|
|
104
|
+
# :squash_duplicates - if the object exists, use it rather
|
|
105
|
+
# than creating a new one? Default = true
|
|
106
|
+
def create( params )
|
|
107
|
+
objtype = find_type params[ :type ]
|
|
108
|
+
return nil unless objtype
|
|
109
|
+
|
|
110
|
+
pn = Gloo::Core::Pn.new params[ :name ]
|
|
111
|
+
parent = params[ :parent ]
|
|
22
112
|
if parent.nil?
|
|
23
113
|
parent = pn.get_parent
|
|
24
114
|
obj_name = pn.name
|
|
25
115
|
else
|
|
26
|
-
obj_name = name
|
|
116
|
+
obj_name = params[ :name ]
|
|
27
117
|
end
|
|
28
118
|
|
|
29
|
-
if
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
parent.add_child( o )
|
|
45
|
-
return o
|
|
46
|
-
else
|
|
47
|
-
$log.error "Could not create object. Bad path: #{name}"
|
|
48
|
-
return nil
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
else
|
|
52
|
-
$log.warn "Could not find type, '#{type}'"
|
|
119
|
+
if pn.exists? && params[ :squash_duplicates ]
|
|
120
|
+
$log.debug "Updating existing object: #{name}"
|
|
121
|
+
return self.update_existing pn, params[ :value ]
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
$log.debug "Creating new object: #{name}"
|
|
125
|
+
return create_new obj_name, params[ :value ], objtype, parent
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
#
|
|
129
|
+
# Create a new object.
|
|
130
|
+
#
|
|
131
|
+
def create_new( name, value, type, parent )
|
|
132
|
+
unless parent
|
|
133
|
+
$log.error "Could not create object. Bad path: #{name}"
|
|
53
134
|
return nil
|
|
54
|
-
end
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
o = type.new
|
|
138
|
+
o.name = name
|
|
139
|
+
o.set_value value
|
|
140
|
+
parent.add_child( o )
|
|
141
|
+
return o
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
#
|
|
145
|
+
# Find and Update an existing object.
|
|
146
|
+
#
|
|
147
|
+
def update_existing( pn, value )
|
|
148
|
+
o = pn.resolve
|
|
149
|
+
o.set_value value
|
|
150
|
+
return o
|
|
55
151
|
end
|
|
56
|
-
|
|
152
|
+
|
|
153
|
+
#
|
|
57
154
|
# Find the object type by name.
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
155
|
+
# Return nil if the object type cannot be found or
|
|
156
|
+
# cannot be created.
|
|
157
|
+
#
|
|
158
|
+
def find_type( type_name )
|
|
159
|
+
type_name = 'untyped' if type_name.nil? || type_name.strip.empty?
|
|
160
|
+
t = $engine.dictionary.find_obj( type_name )
|
|
161
|
+
|
|
162
|
+
if t.nil?
|
|
163
|
+
$log.warn "Could not find type, '#{type_name}'"
|
|
164
|
+
return nil
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
unless t.can_create?
|
|
168
|
+
$log.error "'#{type_name}' cannot be created."
|
|
169
|
+
return nil
|
|
61
170
|
end
|
|
62
|
-
|
|
171
|
+
|
|
172
|
+
return t
|
|
63
173
|
end
|
|
64
|
-
|
|
174
|
+
|
|
65
175
|
end
|
|
66
176
|
end
|
|
67
177
|
end
|