Module: Xampl::XamplObject
- Included in:
- XamplPersistedObject
- Defined in:
- lib/xamplr/visitors.rb,
lib/xamplr/xampl-object.rb,
lib/xamplr/notifications.rb,
lib/xamplr/persist-to-xml.rb
Defined Under Namespace
Modules: XamplRubyDefinition
Constant Summary
collapse
- @@preferred_ns_prefix =
{ "http://xampl.com/" => "xampl",
"http://xampl.com/generator" => "xampl-gen",
"http://www.w3.org/XML/1998/namespace" => "xml" }
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
-
#===(other) ⇒ Object
-
#accessed ⇒ Object
-
#add_parent(xampl) ⇒ Object
-
#changed ⇒ Object
-
#changes_accepted ⇒ Object
-
#compare_xampl(other) ⇒ Object
-
#copy_xampl(root, translate_pids = {}) ⇒ Object
-
#dirty? ⇒ Boolean
def changed? @is_changed end.
-
#ignore_when_no_index ⇒ Object
-
#indexed_by ⇒ Object
-
#init_attributes(attr_name, attr_namespace, attr_value) ⇒ Object
-
#init_hook ⇒ Object
-
#init_xampl_object ⇒ Object
-
#inspect ⇒ Object
-
#invalid ⇒ Object
(also: #invalid?)
-
#invalidate ⇒ Object
-
#mark_changed_deep ⇒ Object
-
#new_from_xml_file(file_name, id = nil, tokenise = true) ⇒ Object
-
#new_from_xml_string(xml_string, id = nil, tokenise = true) ⇒ Object
-
#note_add_child(child, realising) ⇒ Object
about to be added to a parent.
-
#note_add_to_parent(parent, realising) ⇒ Object
about to be added to a parent.
-
#note_adding_text_content(xml_text, realising) ⇒ Object
add text (while loading from XML) xml_text – the text realising – true when loading from a persister.
-
#note_attributes_initialised(realising) ⇒ Object
attributes are setup up (while loading from XML).
-
#note_closed(realising) ⇒ Object
this element has been completed.
-
#note_created(realising) ⇒ Object
-
#note_initialise_attributes_with(names, namespaces, values, realising) ⇒ Object
these are the arrays of attribute information about to be used to initialise the attributes.
-
#note_invalidate ⇒ Object
-
#note_realised ⇒ Object
this element has been realised.
-
#note_replacing(original) ⇒ Object
-
#persist(out = "", mentions = nil, rules = nil) ⇒ Object
-
#persist_required ⇒ Object
-
#pp_xml(out = "", skip = []) ⇒ Object
-
#remove_ws_content ⇒ Object
-
#schedule_a_deletion_if_needed(at = Time.now.to_i) ⇒ Object
-
#should_schedule_delete? ⇒ Boolean
-
#substituting_to_xml(opts = {}) ⇒ Object
-
#to_ruby(mentions = nil) ⇒ Object
-
#to_s ⇒ Object
-
#to_xml(out = "", skip = []) ⇒ Object
Instance Attribute Details
#is_changed ⇒ Object
Returns the value of attribute is_changed.
4
5
6
|
# File 'lib/xamplr/xampl-object.rb', line 4
def is_changed
@is_changed
end
|
#parents ⇒ Object
Returns the value of attribute parents.
4
5
6
|
# File 'lib/xamplr/xampl-object.rb', line 4
def parents
@parents
end
|
Class Method Details
.from_ruby(ruby_string, target = nil) ⇒ Object
199
200
201
202
203
|
# File 'lib/xamplr/xampl-object.rb', line 199
def XamplObject.from_ruby(ruby_string, target=nil)
eval(ruby_string, nil, "ruby_definition", 0)
target.load_needed = false if target
xampl = XamplRubyDefinition.build(target)
end
|
.from_string(string, target = nil) ⇒ Object
191
192
193
|
# File 'lib/xamplr/xampl-object.rb', line 191
def XamplObject.from_string(string, target=nil)
return FromXML.new.parse_string(string, true, false, target)
end
|
.from_xml_file(file_name, tokenise = true) ⇒ Object
264
265
266
|
# File 'lib/xamplr/xampl-object.rb', line 264
def XamplObject.from_xml_file(file_name, tokenise=true)
return FromXML.new.parse(file_name, tokenise)
end
|
.from_xml_string(xml_string, tokenise = true) ⇒ Object
260
261
262
|
# File 'lib/xamplr/xampl-object.rb', line 260
def XamplObject.from_xml_string(xml_string, tokenise=true)
return FromXML.new.parse_string(xml_string, tokenise)
end
|
.lookup_preferred_ns_prefix(ns) ⇒ Object
22
23
24
|
# File 'lib/xamplr/xampl-object.rb', line 22
def XamplObject.lookup_preferred_ns_prefix(ns)
@@preferred_ns_prefix[ns]
end
|
.ns_preferred_prefix(ns, prefix) ⇒ Object
18
19
20
|
# File 'lib/xamplr/xampl-object.rb', line 18
def XamplObject.ns_preferred_prefix(ns, prefix)
@@preferred_ns_prefix[ns] = prefix unless @@preferred_ns_prefix.has_key?(ns)
end
|
.realise_from_xml_string(xml_string, target = nil, tokenise = true) ⇒ Object
239
240
241
242
|
# File 'lib/xamplr/xampl-object.rb', line 239
def XamplObject.realise_from_xml_string(xml_string, target=nil, tokenise=true)
xampl = FromXML.new.realise_string(xml_string, tokenise, target)
return xampl
end
|
.recover_from_string(string) ⇒ Object
195
196
197
|
# File 'lib/xamplr/xampl-object.rb', line 195
def XamplObject.recover_from_string(string)
return FromXML.new(true).parse_string(string, true, false, nil)
end
|
Instance Method Details
#===(other) ⇒ Object
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
# File 'lib/xamplr/xampl-object.rb', line 120
def ===(other)
accessed
other.accessed if other
return false unless self.class == other.class
return false unless self.children.size == other.children.size
self.children.zip(other.children).each do |c1, c2|
return false unless c1.class == c2.class
if c1.kind_of? String then
return false unless c1 == c2
else
return false unless c1 === c2
end
end
if (defined? self._content) and (defined? other._content) then
return false unless self._content == other._content
else
return false if (defined? self._content) or (defined? other._content)
end
return true
end
|
#accessed ⇒ Object
69
70
71
|
# File 'lib/xamplr/xampl-object.rb', line 69
def accessed
raise XamplIsInvalid.new(self) if invalid
end
|
#add_parent(xampl) ⇒ Object
73
74
75
76
77
78
79
|
# File 'lib/xamplr/xampl-object.rb', line 73
def add_parent(xampl)
@parents = [] if (not defined? @parents) or (nil == @parents)
@parents << xampl
if Xampl.persister and self.persist_required and (nil == self.persister) then
Xampl.introduce_to_persister(self)
end
end
|
#changed ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/xamplr/xampl-object.rb', line 49
def changed
raise UnmanagedChange.new(self) unless Xampl.persister
unless @is_changed then
@is_changed = true
if nil != @parents
@parents.each do |parent|
parent.changed
end
end
end
end
|
#changes_accepted ⇒ Object
#compare_xampl(other) ⇒ Object
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/xamplr/xampl-object.rb', line 99
def compare_xampl(other)
accessed
other.accessed if other
return false unless self.class == other.class
return false unless self.children.size == other.children.size
self.children.zip(other.children).each do |c1, c2|
return false unless c1.class == c2.class
if c1.kind_of? String then
return false unless c1 == c2
else
return false unless c1.compare_xampl(c2)
end
end
if (defined? self._content) and (defined? other._content) then
return false unless self._content == other._content
else
return false if (defined? self._content) or (defined? other._content)
end
return true
end
|
#copy_xampl(root, translate_pids = {}) ⇒ Object
591
592
593
|
# File 'lib/xamplr/visitors.rb', line 591
def copy_xampl(root, translate_pids={})
CopyXML.copy(root, translate_pids)
end
|
#dirty? ⇒ Boolean
def changed?
@is_changed
end
65
66
67
|
# File 'lib/xamplr/xampl-object.rb', line 65
def dirty?
@is_changed
end
|
#ignore_when_no_index ⇒ Object
30
31
32
|
# File 'lib/xamplr/xampl-object.rb', line 30
def ignore_when_no_index
return false
end
|
#indexed_by ⇒ Object
141
142
143
|
# File 'lib/xamplr/xampl-object.rb', line 141
def indexed_by
nil
end
|
#init_attributes(attr_name, attr_namespace, attr_value) ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/xamplr/xampl-object.rb', line 81
def init_attributes(attr_name, attr_namespace, attr_value)
return unless attr_name
attr_name.each_index do |i|
self.attributes.each do |attr_spec|
if (2 == attr_spec.size) then
if (attr_spec[1] == attr_name[i]) then
self.instance_variable_set(attr_spec[0], attr_value[i])
end
else
if ((attr_spec[1] == attr_name[i]) and (attr_spec[2] == attr_namespace[i])) then
self.instance_variable_set(attr_spec[0], attr_value[i])
end
end
end
end
end
|
#init_hook ⇒ Object
15
16
|
# File 'lib/xamplr/xampl-object.rb', line 15
def init_hook
end
|
#init_xampl_object ⇒ Object
10
11
12
13
|
# File 'lib/xamplr/xampl-object.rb', line 10
def init_xampl_object
@parents = nil if not defined? @parents
@is_changed = false if not defined? @is_changed
end
|
#inspect ⇒ Object
160
161
162
|
# File 'lib/xamplr/xampl-object.rb', line 160
def inspect
self.to_s
end
|
#invalid ⇒ Object
Also known as:
invalid?
40
41
42
|
# File 'lib/xamplr/xampl-object.rb', line 40
def invalid
return kind_of?(InvalidXampl)
end
|
#invalidate ⇒ Object
34
35
36
37
38
|
# File 'lib/xamplr/xampl-object.rb', line 34
def invalidate
self.note_invalidate
self.persister.uncache(self) if self.persister
self.extend InvalidXampl
end
|
#mark_changed_deep ⇒ Object
#new_from_xml_file(file_name, id = nil, tokenise = true) ⇒ Object
252
253
254
255
256
257
258
|
# File 'lib/xamplr/xampl-object.rb', line 252
def new_from_xml_file(file_name, id=nil, tokenise=true)
thing = FromXML.new.parse(file_name, tokenise)
if thing.indexed_by then
thing.set_the_index(id) if id
self << thing if thing.get_the_index
end
end
|
#new_from_xml_string(xml_string, id = nil, tokenise = true) ⇒ Object
244
245
246
247
248
249
250
|
# File 'lib/xamplr/xampl-object.rb', line 244
def new_from_xml_string(xml_string, id=nil, tokenise=true)
thing = FromXML.new.parse_string(xml_string, tokenise)
if thing.indexed_by then
thing.set_the_index(id) if id
self << thing if thing.get_the_index
end
end
|
#note_add_child(child, realising) ⇒ Object
about to be added to a parent
37
38
39
|
# File 'lib/xamplr/notifications.rb', line 37
def note_add_child(child, realising)
return child
end
|
#note_add_to_parent(parent, realising) ⇒ Object
about to be added to a parent
31
32
33
|
# File 'lib/xamplr/notifications.rb', line 31
def note_add_to_parent(parent, realising)
return self
end
|
#note_adding_text_content(xml_text, realising) ⇒ Object
add text (while loading from XML)
xml_text -- the text
realising -- true when loading from a persister
9
10
11
|
# File 'lib/xamplr/notifications.rb', line 9
def note_adding_text_content(xml_text, realising)
return xml_text
end
|
#note_attributes_initialised(realising) ⇒ Object
attributes are setup up (while loading from XML)
21
22
|
# File 'lib/xamplr/notifications.rb', line 21
def note_attributes_initialised(realising)
end
|
#note_closed(realising) ⇒ Object
this element has been completed
43
44
45
|
# File 'lib/xamplr/notifications.rb', line 43
def note_closed(realising)
return self
end
|
#note_created(realising) ⇒ Object
26
27
|
# File 'lib/xamplr/notifications.rb', line 26
def note_created(realising)
end
|
#note_initialise_attributes_with(names, namespaces, values, realising) ⇒ Object
these are the arrays of attribute information about to be used to initialise the attributes
16
17
|
# File 'lib/xamplr/notifications.rb', line 16
def note_initialise_attributes_with(names, namespaces, values, realising)
end
|
#note_invalidate ⇒ Object
59
60
|
# File 'lib/xamplr/notifications.rb', line 59
def note_invalidate
end
|
#note_realised ⇒ Object
this element has been realised
48
49
50
|
# File 'lib/xamplr/notifications.rb', line 48
def note_realised
return self
end
|
#note_replacing(original) ⇒ Object
54
55
|
# File 'lib/xamplr/notifications.rb', line 54
def note_replacing(original)
end
|
#persist(out = "", mentions = nil, rules = nil) ⇒ Object
205
206
207
208
209
210
211
212
213
|
# File 'lib/xamplr/xampl-object.rb', line 205
def persist(out="", mentions=nil, rules=nil)
persist_xml_new = PersistXML.new(out, mentions)
r = persist_xml_new.start(self).done
return r
end
|
#persist_required ⇒ Object
26
27
28
|
# File 'lib/xamplr/xampl-object.rb', line 26
def persist_required
return false
end
|
#pp_xml(out = "", skip = []) ⇒ Object
587
588
589
|
# File 'lib/xamplr/visitors.rb', line 587
def pp_xml(out="", skip=[])
PrettyXML.new(out, skip).start(self).done
end
|
#remove_ws_content ⇒ Object
#schedule_a_deletion_if_needed(at = Time.now.to_i) ⇒ Object
231
232
233
|
# File 'lib/xamplr/xampl-object.rb', line 231
def schedule_a_deletion_if_needed(at=Time.now.to_i)
@scheduled_for_deletion_at = should_schedule_delete? ? at.to_s : nil end
|
#should_schedule_delete? ⇒ Boolean
226
227
228
229
|
# File 'lib/xamplr/xampl-object.rb', line 226
def should_schedule_delete?
false
end
|
#substituting_to_xml(opts = {}) ⇒ Object
274
275
276
277
|
# File 'lib/xamplr/persist-to-xml.rb', line 274
def substituting_to_xml(opts={})
substitutions = opts[:substitutions] || {}
PersistXML.new("", [], substitutions).start(self).done
end
|
#to_ruby(mentions = nil) ⇒ Object
164
165
166
167
|
# File 'lib/xamplr/xampl-object.rb', line 164
def to_ruby(mentions=nil)
accessed
return RubyPrinter.new(mentions).to_ruby(self)
end
|
#to_s ⇒ Object
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
# File 'lib/xamplr/xampl-object.rb', line 145
def to_s
if self.persisted? then
persister_name = self.persister ? "#{ self.persister.name }/" : ''
if @load_needed then
"<<#{ self.class.name } #{ self.object_id } [#{ self.persister ? self.persister.name : 'no-persister' }/#{ self.get_the_index }] NOT LOADED>>"
else
"<<#{ self.class.name } #{ self.object_id } [#{ self.persister ? self.persister.name : 'no-persister' }/#{ self.get_the_index }]#{ @is_changed ? ' DIRTY' : ''}>>"
end
elsif self.indexed_by then
"<<#{ self.class.name } #{ self.object_id } [#{ self.get_the_index }]>>"
else
"<<#{ self.class.name } #{ self.object_id }>>"
end
end
|
#to_xml(out = "", skip = []) ⇒ Object
270
271
272
|
# File 'lib/xamplr/persist-to-xml.rb', line 270
def to_xml(out="", skip=[])
PersistXML.new(out).start(self).done
end
|