xamplr 1.2.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.
- data/CHANGES.txt +13 -0
- data/LICENSE +3 -0
- data/README.rdoc +26 -0
- data/README.rdoc.orig +118 -0
- data/Rakefile +85 -0
- data/VERSION.yml +4 -0
- data/examples/random-people-shared-addresses/Makefile +16 -0
- data/examples/random-people-shared-addresses/batch-load-users.rb +83 -0
- data/examples/random-people-shared-addresses/find-mentions.rb +47 -0
- data/examples/random-people-shared-addresses/find-people-by-address.rb +104 -0
- data/examples/random-people-shared-addresses/optimise.rb +16 -0
- data/examples/random-people-shared-addresses/people.rb +35 -0
- data/examples/random-people-shared-addresses/query.rb +75 -0
- data/examples/random-people-shared-addresses/query2.rb +73 -0
- data/examples/random-people-shared-addresses/random-names.csv +10000 -0
- data/examples/random-people-shared-addresses/settings.rb +3 -0
- data/examples/random-people-shared-addresses/what-to-query-on.rb +82 -0
- data/examples/random-people-shared-addresses/xampl-gen.rb +36 -0
- data/examples/random-people-shared-addresses/xml/people.xml +14 -0
- data/examples/random-people/Makefile +16 -0
- data/examples/random-people/batch-load-users.rb +61 -0
- data/examples/random-people/optimise.rb +16 -0
- data/examples/random-people/people.rb +22 -0
- data/examples/random-people/query.rb +73 -0
- data/examples/random-people/query2.rb +73 -0
- data/examples/random-people/random-names.csv +10000 -0
- data/examples/random-people/rawtc.rb +91 -0
- data/examples/random-people/settings.rb +3 -0
- data/examples/random-people/what-to-query-on.rb +80 -0
- data/examples/random-people/xampl-gen.rb +36 -0
- data/examples/random-people/xml/people.xml +11 -0
- data/examples/read-testing/Makefile +10 -0
- data/examples/read-testing/load.rb +65 -0
- data/examples/read-testing/read.rb +51 -0
- data/examples/read-testing/rrr.rb +87 -0
- data/examples/read-testing/settings.rb +2 -0
- data/examples/read-testing/xampl-gen.rb +36 -0
- data/examples/read-testing/xml/text.xml +8 -0
- data/examples/tokyo-cabinet-experimental/expt-query.rb +42 -0
- data/examples/tokyo-cabinet-experimental/expt-query2.rb +42 -0
- data/examples/tokyo-cabinet-experimental/expt-query3.rb +41 -0
- data/examples/tokyo-cabinet-experimental/expt-reader.rb +32 -0
- data/examples/tokyo-cabinet-experimental/expt.rb +61 -0
- data/examples/tokyo-cabinet-experimental/xampl-gen.rb +36 -0
- data/examples/tokyo-cabinet-experimental/xml/tcx.xml +6 -0
- data/lib/xampl-generator.rb +3 -0
- data/lib/xampl.rb +3 -0
- data/lib/xamplr-generator.rb +10 -0
- data/lib/xamplr.rb +37 -0
- data/lib/xamplr/README-POSSIBLE-PROBLEMS +5 -0
- data/lib/xamplr/TODO +1 -0
- data/lib/xamplr/exceptions.rb +97 -0
- data/lib/xamplr/from-xml-orig.rb +350 -0
- data/lib/xamplr/from-xml.rb +439 -0
- data/lib/xamplr/gen-elements.xml +6230 -0
- data/lib/xamplr/gen.elements.xml +108 -0
- data/lib/xamplr/generate-elements.rb +15 -0
- data/lib/xamplr/generator.rb +5 -0
- data/lib/xamplr/graphml-out.rb +470 -0
- data/lib/xamplr/handwritten/example.rb +698 -0
- data/lib/xamplr/handwritten/hand-example.rb +533 -0
- data/lib/xamplr/handwritten/test-handwritten.rb +873 -0
- data/lib/xamplr/indexed-array.rb +115 -0
- data/lib/xamplr/mixins.rb +397 -0
- data/lib/xamplr/my.gen.elements.xml +461 -0
- data/lib/xamplr/notifications.rb +57 -0
- data/lib/xamplr/obsolete/fsdb.rb +62 -0
- data/lib/xamplr/persist-to-xml.rb +249 -0
- data/lib/xamplr/persistence.rb +522 -0
- data/lib/xamplr/persistence.rb.more_thread_safe +771 -0
- data/lib/xamplr/persistence.rb.partially_thread_safe +763 -0
- data/lib/xamplr/persister.rb +310 -0
- data/lib/xamplr/persisters/caches.rb +186 -0
- data/lib/xamplr/persisters/caching.rb +172 -0
- data/lib/xamplr/persisters/filesystem.rb +60 -0
- data/lib/xamplr/persisters/in-memory.rb +180 -0
- data/lib/xamplr/persisters/simple.rb +59 -0
- data/lib/xamplr/persisters/tokyo-cabinet.rb +641 -0
- data/lib/xamplr/simpleTemplate/danger.rx +4 -0
- data/lib/xamplr/simpleTemplate/obsolete/input-c.r4 +35 -0
- data/lib/xamplr/simpleTemplate/obsolete/play.r6.txt +12 -0
- data/lib/xamplr/simpleTemplate/obsolete/play_more.r6.txt +20 -0
- data/lib/xamplr/simpleTemplate/obsolete/test001.r5 +8 -0
- data/lib/xamplr/simpleTemplate/obsolete/test002.r5 +13 -0
- data/lib/xamplr/simpleTemplate/obsolete/test003.r5 +37 -0
- data/lib/xamplr/simpleTemplate/old/r6.000.rb +122 -0
- data/lib/xamplr/simpleTemplate/old/r6.001.rb +145 -0
- data/lib/xamplr/simpleTemplate/play.r6 +12 -0
- data/lib/xamplr/simpleTemplate/play_more.r6 +20 -0
- data/lib/xamplr/simpleTemplate/play_noblanks.r6 +21 -0
- data/lib/xamplr/simpleTemplate/playq.r6 +16 -0
- data/lib/xamplr/simpleTemplate/r6.rb +87 -0
- data/lib/xamplr/simpleTemplate/simple-template.rb +75 -0
- data/lib/xamplr/templates/child.template +47 -0
- data/lib/xamplr/templates/child_indexed.template +89 -0
- data/lib/xamplr/templates/child_modules.template +5 -0
- data/lib/xamplr/templates/element_classes.template +11 -0
- data/lib/xamplr/templates/element_data.template +282 -0
- data/lib/xamplr/templates/element_empty.template +285 -0
- data/lib/xamplr/templates/element_mixed.template +277 -0
- data/lib/xamplr/templates/element_simple.template +276 -0
- data/lib/xamplr/templates/package.template +26 -0
- data/lib/xamplr/test-support/Makefile +47 -0
- data/lib/xamplr/test-support/bench-cache.rb +80 -0
- data/lib/xamplr/test-support/bench-script.rb +21 -0
- data/lib/xamplr/test-support/bench.rb +116 -0
- data/lib/xamplr/test-support/bench2.rb +132 -0
- data/lib/xamplr/test-support/test-cache.rb +147 -0
- data/lib/xamplr/test-support/test-data/binding.xml +7 -0
- data/lib/xamplr/test-support/test-data/example.xml +14 -0
- data/lib/xamplr/test-support/test-data/internationalization-utf8.txt +1 -0
- data/lib/xamplr/test-support/test-data/labels.xml +37 -0
- data/lib/xamplr/test-support/test-data/labels001.xml +38 -0
- data/lib/xamplr/test-support/test-deep-change.rb +135 -0
- data/lib/xamplr/test-support/test-elements.rb +109 -0
- data/lib/xamplr/test-support/test-indexed-array.rb +169 -0
- data/lib/xamplr/test-support/test-misc.rb +73 -0
- data/lib/xamplr/test-support/test-names.rb +67 -0
- data/lib/xamplr/test-support/test-rollback.rb +106 -0
- data/lib/xamplr/test-support/test.rb +1504 -0
- data/lib/xamplr/to-ruby.rb +220 -0
- data/lib/xamplr/to-xml.rb +158 -0
- data/lib/xamplr/version.rb +67 -0
- data/lib/xamplr/visitor.rb +140 -0
- data/lib/xamplr/visitors.rb +573 -0
- data/lib/xamplr/xampl-generator.rb +533 -0
- data/lib/xamplr/xampl-hand-generated.rb +1535 -0
- data/lib/xamplr/xampl-module.rb +36 -0
- data/lib/xamplr/xampl-object-internals.rb +6 -0
- data/lib/xamplr/xampl-object.rb +202 -0
- data/lib/xamplr/xampl-persisted-object.rb +122 -0
- data/lib/xamplr/xml-text.rb +117 -0
- data/lib/xamplr/xml/document.xml +7 -0
- data/lib/xamplr/xml/elements.xml +101 -0
- data/lib/xamplr/xml/elements000.xml +73 -0
- data/lib/xamplr/xml/example.xml +23 -0
- data/lib/xamplr/xml/options.xml +12 -0
- data/lib/xamplr/xml/uche.xml +38 -0
- data/lib/xamplr/yEd-sample.graphml +300 -0
- data/test/test_helper.rb +10 -0
- data/test/xamplr_test.rb +7 -0
- metadata +245 -0
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
|
|
2
|
+
module Xampl
|
|
3
|
+
|
|
4
|
+
class RubyPrinter
|
|
5
|
+
|
|
6
|
+
$USE_A_PROC = false
|
|
7
|
+
|
|
8
|
+
def initialize(mentions=nil)
|
|
9
|
+
@obj_count = 0
|
|
10
|
+
@map = {}
|
|
11
|
+
@lookup_map={}
|
|
12
|
+
@mentions = mentions
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def show_attributes(thing, name, depth)
|
|
16
|
+
return "" unless thing.attributes
|
|
17
|
+
|
|
18
|
+
out = ""
|
|
19
|
+
indent = " " + (" " * depth)
|
|
20
|
+
|
|
21
|
+
if thing.persist_required and (1 < depth)
|
|
22
|
+
accessor = thing.indexed_by
|
|
23
|
+
value = thing.get_the_index
|
|
24
|
+
if value then
|
|
25
|
+
out << indent << "#{name}.#{accessor} = #{value.inspect}\n"
|
|
26
|
+
end
|
|
27
|
+
else
|
|
28
|
+
thing.attributes.each do |attribute|
|
|
29
|
+
value = thing.instance_variable_get(attribute[0])
|
|
30
|
+
|
|
31
|
+
if value then
|
|
32
|
+
if value.kind_of?(XamplObject) then
|
|
33
|
+
vname = "root_#{@obj_count += 1}"
|
|
34
|
+
out << to_ruby_as_attr(value, depth, vname)
|
|
35
|
+
out << indent << "#{name}.instance_variable_set(:#{attribute[0]}, #{vname})\n"
|
|
36
|
+
else
|
|
37
|
+
out << indent << "#{name}.instance_variable_set(:#{attribute[0]}, #{value.inspect})\n"
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
return out
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def show_children_tree(thing, name, depth)
|
|
46
|
+
out = ""
|
|
47
|
+
indent = " " + (" " * depth)
|
|
48
|
+
|
|
49
|
+
if thing.persist_required and (1 < depth) then
|
|
50
|
+
return out << indent << "#{name}.load_needed = true\n"
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
if (!thing.kind_of? XamplWithMixedContent) and
|
|
54
|
+
(!thing.kind_of? XamplWithoutContent) and
|
|
55
|
+
thing._content then
|
|
56
|
+
out << indent << "#{name} << #{thing._content.inspect}\n"
|
|
57
|
+
end
|
|
58
|
+
thing.children.each do |child|
|
|
59
|
+
if child.kind_of? XamplObject then
|
|
60
|
+
cname = "v_#{child.safe_name}_#{@obj_count += 1}"
|
|
61
|
+
|
|
62
|
+
cout = ""
|
|
63
|
+
cout << show_attributes(child, cname, 1 + depth)
|
|
64
|
+
cout << show_children_tree(child, cname, 1 + depth)
|
|
65
|
+
|
|
66
|
+
if 0 < cout.size then
|
|
67
|
+
out << indent << "#{name} << #{child.class.to_s}.new { | #{cname} |\n"
|
|
68
|
+
out << cout
|
|
69
|
+
out << indent << "}\n"
|
|
70
|
+
else
|
|
71
|
+
out << indent << "#{name} << #{child.class.to_s}.new\n"
|
|
72
|
+
end
|
|
73
|
+
else
|
|
74
|
+
out << indent << "#{name} << #{child.inspect}\n"
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
return out
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def show_attributes_flat(thing, depth)
|
|
81
|
+
return "" unless thing.attributes
|
|
82
|
+
|
|
83
|
+
out = ""
|
|
84
|
+
|
|
85
|
+
if thing.persist_required and (1 < depth)
|
|
86
|
+
accessor = thing.indexed_by
|
|
87
|
+
|
|
88
|
+
value = thing.get_the_index
|
|
89
|
+
if value then
|
|
90
|
+
out << " " << "xampl.#{accessor} = #{value.inspect}\n"
|
|
91
|
+
end
|
|
92
|
+
else
|
|
93
|
+
thing.attributes.each do |attribute|
|
|
94
|
+
value = thing.instance_variable_get(attribute[0])
|
|
95
|
+
|
|
96
|
+
if value then
|
|
97
|
+
out << " " << "xampl.instance_variable_set(:#{attribute[0]}, #{value.inspect})\n"
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
return out
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def show_children_flat(thing, name, depth)
|
|
105
|
+
out = ""
|
|
106
|
+
|
|
107
|
+
thing.children.each do |child|
|
|
108
|
+
if child.kind_of? XamplObject and (nil == @map[child]) then
|
|
109
|
+
cname = "v_#{child.safe_name}_#{@obj_count += 1}"
|
|
110
|
+
|
|
111
|
+
@map[child] = cname
|
|
112
|
+
|
|
113
|
+
cout = ""
|
|
114
|
+
cout << show_attributes_flat(child, 1 + depth)
|
|
115
|
+
|
|
116
|
+
if 0 < cout.size then
|
|
117
|
+
if child.persist_required then
|
|
118
|
+
out << " " << "#{cname} = #{child.class.to_s}['#{child.get_the_index}']\n"
|
|
119
|
+
@mentions << child if @mentions
|
|
120
|
+
else
|
|
121
|
+
out << " " << "#{cname} = #{child.class.to_s}.new { | xampl |\n"
|
|
122
|
+
out << cout
|
|
123
|
+
out << " " << "}\n"
|
|
124
|
+
end
|
|
125
|
+
else
|
|
126
|
+
out << " " << "#{cname} = #{child.class.to_s}.new\n"
|
|
127
|
+
end
|
|
128
|
+
out << show_children_flat(child, cname, 1 + depth) unless child.persist_required
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
return out
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def show_children_stitch_start(thing, depth)
|
|
135
|
+
@lookup_map.merge!(@map)
|
|
136
|
+
return show_children_stitch(thing, depth)
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def show_children_stitch(thing, depth)
|
|
140
|
+
out = ""
|
|
141
|
+
|
|
142
|
+
return out if thing.persist_required and (0 < depth)
|
|
143
|
+
|
|
144
|
+
name = @map[thing]
|
|
145
|
+
if name then
|
|
146
|
+
@map.delete(thing)
|
|
147
|
+
else
|
|
148
|
+
return out
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
if (!thing.kind_of? XamplWithMixedContent) and
|
|
152
|
+
(!thing.kind_of? XamplWithoutContent) and
|
|
153
|
+
thing._content then
|
|
154
|
+
out << " " << "#{name} << #{thing._content.inspect}\n"
|
|
155
|
+
end
|
|
156
|
+
thing.children.each do |child|
|
|
157
|
+
if child.kind_of? XamplObject then
|
|
158
|
+
out << " " << "#{name} << #{@lookup_map[child]}\n"
|
|
159
|
+
else
|
|
160
|
+
out << " " << "#{name} << #{child.inspect}\n"
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
thing.children.each do |child|
|
|
164
|
+
if child.kind_of? XamplObject then
|
|
165
|
+
out << show_children_stitch(child, 1 + depth)
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
return out
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
def to_ruby(thing, depth=0, name="root")
|
|
172
|
+
thing.accessed
|
|
173
|
+
|
|
174
|
+
@obj_count = 0
|
|
175
|
+
@map = {}
|
|
176
|
+
@lookup_map={}
|
|
177
|
+
|
|
178
|
+
@map[thing] = name
|
|
179
|
+
|
|
180
|
+
if $USE_A_PROC then
|
|
181
|
+
return %Q{
|
|
182
|
+
module XamplRubyDefinition
|
|
183
|
+
@@proc = Proc.new { | target |
|
|
184
|
+
#{name} = target ? target : #{thing.class.to_s}.new
|
|
185
|
+
#{show_attributes(thing, name, depth)}
|
|
186
|
+
#{show_children_flat(thing, name, depth)}
|
|
187
|
+
#{show_children_stitch_start(thing, depth)}
|
|
188
|
+
#{name}
|
|
189
|
+
}
|
|
190
|
+
end
|
|
191
|
+
}
|
|
192
|
+
else
|
|
193
|
+
return %Q{
|
|
194
|
+
module XamplRubyDefinition
|
|
195
|
+
def XamplRubyDefinition.build_it(target)
|
|
196
|
+
#{name} = target ? target : #{thing.class.to_s}.new
|
|
197
|
+
#{show_attributes(thing, name, depth)}
|
|
198
|
+
#{show_children_flat(thing, name, depth)}
|
|
199
|
+
#{show_children_stitch_start(thing, depth)}
|
|
200
|
+
#{name}
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
}
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
def to_ruby_as_attr(thing, depth, name)
|
|
208
|
+
thing.accessed
|
|
209
|
+
|
|
210
|
+
@map[thing] = name
|
|
211
|
+
|
|
212
|
+
return %Q{
|
|
213
|
+
#{name} = #{thing.class.name}.new
|
|
214
|
+
#{show_attributes(thing, name, depth)}
|
|
215
|
+
#{show_children_flat(thing, name, depth)}
|
|
216
|
+
#{show_children_stitch_start(thing, depth)}
|
|
217
|
+
}
|
|
218
|
+
end
|
|
219
|
+
end
|
|
220
|
+
end
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
|
|
2
|
+
module Xampl
|
|
3
|
+
|
|
4
|
+
class XMLPrinter
|
|
5
|
+
attr_accessor :ns_to_prefix, :start_body, :body, :out, :mixed, :persisting
|
|
6
|
+
|
|
7
|
+
def initialize(out, persisting=false)
|
|
8
|
+
@out = out
|
|
9
|
+
@persisting = persisting
|
|
10
|
+
|
|
11
|
+
@ns_to_prefix = {}
|
|
12
|
+
@start_body = ""
|
|
13
|
+
@body = ""
|
|
14
|
+
@attr_list = nil
|
|
15
|
+
@mixed = 0
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def now_as_mixed
|
|
19
|
+
@mixed = @mixed + 1
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def now_as_before
|
|
23
|
+
@mixed = @mixed - 1 if (0 < @mixed)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def register_ns(ns)
|
|
27
|
+
if (0 == ns.length) then
|
|
28
|
+
return ""
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
prefix = ns_to_prefix[ns]
|
|
32
|
+
if (nil == prefix) then
|
|
33
|
+
preferred = XamplObject.lookup_preferred_ns_prefix(ns)
|
|
34
|
+
prefix = "" << preferred << ":" if preferred
|
|
35
|
+
prefix = "ns" << ns_to_prefix.size.to_s << ":" unless prefix
|
|
36
|
+
ns_to_prefix[ns] = prefix
|
|
37
|
+
end
|
|
38
|
+
return prefix
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def attr_esc(s)
|
|
42
|
+
if (s.kind_of? XamplObject)
|
|
43
|
+
return attr_esc(s.to_xml)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
result = s.to_s.dup
|
|
47
|
+
#result = s.to_xml
|
|
48
|
+
|
|
49
|
+
result.gsub!("&", "&")
|
|
50
|
+
result.gsub!("<", "<")
|
|
51
|
+
result.gsub!(">", ">")
|
|
52
|
+
result.gsub!("'", "'")
|
|
53
|
+
result.gsub!("\"", """)
|
|
54
|
+
|
|
55
|
+
return result
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def content_esc(s)
|
|
59
|
+
result = s.to_s.dup
|
|
60
|
+
#result = s.to_xml
|
|
61
|
+
|
|
62
|
+
return result if (s.kind_of? XamplObject)
|
|
63
|
+
|
|
64
|
+
result.gsub!("&", "&")
|
|
65
|
+
result.gsub!("<", "<")
|
|
66
|
+
|
|
67
|
+
return result
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def attribute(xampl)
|
|
71
|
+
@attr_list = []
|
|
72
|
+
if (nil != xampl.attributes) then
|
|
73
|
+
xampl.attributes.each do |attr_spec|
|
|
74
|
+
prefix = (2 < attr_spec.length) ? register_ns(attr_spec[2]) : ""
|
|
75
|
+
value = xampl.instance_variable_get(attr_spec[0])
|
|
76
|
+
@attr_list << " " << prefix << attr_spec[1] << "='" << attr_esc(value) << "'" \
|
|
77
|
+
unless nil == value
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def persist_attribute(xampl)
|
|
83
|
+
@attr_list = []
|
|
84
|
+
index = xampl.indexed_by[1..-1]
|
|
85
|
+
if (nil != index) then
|
|
86
|
+
value = xampl.get_the_index
|
|
87
|
+
@attr_list << " " << index << "='" << attr_esc(value) << "'" if value
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def show_attributes
|
|
92
|
+
if (nil == @attr_list) then
|
|
93
|
+
return ""
|
|
94
|
+
else
|
|
95
|
+
result = @attr_list.join
|
|
96
|
+
if (0 == result.length) then
|
|
97
|
+
return ""
|
|
98
|
+
else
|
|
99
|
+
return result
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def start_root_element(tag, ns, empty=false)
|
|
105
|
+
if (empty) then
|
|
106
|
+
@start_body << "<" << register_ns(ns) << tag << show_attributes
|
|
107
|
+
@body = "/>"
|
|
108
|
+
else
|
|
109
|
+
@start_body << "<" << register_ns(ns) << tag << show_attributes
|
|
110
|
+
@body = ">"
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def start_element(tag, ns, empty=false)
|
|
115
|
+
if (empty) then
|
|
116
|
+
@body << "<" << register_ns(ns) << tag << show_attributes << "/>"
|
|
117
|
+
else
|
|
118
|
+
@body << "<" << register_ns(ns) << tag << show_attributes << ">"
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def persisted_element(tag, ns)
|
|
123
|
+
@body << "<" << register_ns(ns) << tag << show_attributes << "/>"
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def _content(text)
|
|
127
|
+
if nil != text then
|
|
128
|
+
if text.kind_of? XMLText then
|
|
129
|
+
@body << text.to_xml(self)
|
|
130
|
+
else
|
|
131
|
+
@body << content_esc(text)
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
alias content _content
|
|
137
|
+
|
|
138
|
+
def end_root_element(tag, ns, empty)
|
|
139
|
+
@body << "</" << register_ns(ns) << tag << ">" if (!empty)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def end_element(tag, ns, empty)
|
|
143
|
+
@body << "</" << register_ns(ns) << tag << ">" if (!empty)
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def define_ns
|
|
147
|
+
result = ""
|
|
148
|
+
ns_to_prefix.each do |ns, prefix|
|
|
149
|
+
result = sprintf("%s xmlns:%s='%s'", result, prefix[0..-2], ns)
|
|
150
|
+
end
|
|
151
|
+
return result
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def done
|
|
155
|
+
out << start_body << define_ns << body
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
module Xampl
|
|
2
|
+
class Version
|
|
3
|
+
@@version_limit = 5
|
|
4
|
+
|
|
5
|
+
def initialize(repo_name, repo_root)
|
|
6
|
+
@invalid = true
|
|
7
|
+
throw :refuse_to_version unless repo_name
|
|
8
|
+
|
|
9
|
+
repo_name.gsub!(/^[\.\/]*/, '')
|
|
10
|
+
repo_name.gsub!(/\/.*/, '')
|
|
11
|
+
throw :refuse_to_version unless repo_name
|
|
12
|
+
|
|
13
|
+
@repo_root = repo_root
|
|
14
|
+
@repo_root << '/' unless '/'[-1] == @repo_root[-1]
|
|
15
|
+
|
|
16
|
+
@repo_path = "#{@repo_root}#{repo_name}"
|
|
17
|
+
@repo_name = repo_name
|
|
18
|
+
|
|
19
|
+
throw :refuse_to_version if @repo_path == @repo_root
|
|
20
|
+
throw :refuse_to_version unless File.directory?(@repo_path)
|
|
21
|
+
|
|
22
|
+
@invalid = false
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def make(version_stream, description=nil)
|
|
26
|
+
throw :refuse_to_version if @invalid
|
|
27
|
+
|
|
28
|
+
existing_versions = Dir.glob("#{@repo_root}/#{@repo_name}_#{version_stream}*")
|
|
29
|
+
|
|
30
|
+
if 0 == existing_versions.size then
|
|
31
|
+
make_first_version(version_stream, existing_versions, description)
|
|
32
|
+
else
|
|
33
|
+
make_new_version(version_stream, existing_versions, description)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def make_first_version(version_stream, existing_versions, description)
|
|
38
|
+
cmd = "cd '#{@repo_root}'; rsync -a --delete '#{@repo_name}/' '#{@repo_name}_#{version_stream}.0/'"
|
|
39
|
+
# puts "first version: #{cmd}"
|
|
40
|
+
system(cmd)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def make_new_version(version_stream, existing_versions, description)
|
|
44
|
+
|
|
45
|
+
existing_versions.reverse!
|
|
46
|
+
cmd = []
|
|
47
|
+
eliminate = []
|
|
48
|
+
existing_versions.each_with_index do | version, i |
|
|
49
|
+
pushed_name = "#{@repo_name}_#{version_stream}.#{i + 1}"
|
|
50
|
+
cmd << "mv '#{@repo_name}_#{version_stream}.#{i}' '#{pushed_name}'"
|
|
51
|
+
eliminate << pushed_name unless i < @@version_limit
|
|
52
|
+
end
|
|
53
|
+
cmd << "cd '#{@repo_root}'"
|
|
54
|
+
cmd = cmd.reverse
|
|
55
|
+
cmd << "rsync -a --delete --checksum --link-dest='../#{@repo_name}_#{version_stream}.1' '#{@repo_name}/' '#{@repo_name}_#{version_stream}.0/'"
|
|
56
|
+
cmd << "touch '#{@repo_name}_#{version_stream}.0'"
|
|
57
|
+
|
|
58
|
+
eliminate.each do | name |
|
|
59
|
+
cmd << "rm -rf '#{name}'"
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
cmd = cmd.join("; ")
|
|
63
|
+
# puts "new version: #{cmd}"
|
|
64
|
+
system(cmd)
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
module Xampl
|
|
2
|
+
|
|
3
|
+
class Visitor
|
|
4
|
+
attr_accessor :no_children, :no_siblings, :done
|
|
5
|
+
|
|
6
|
+
def initialize
|
|
7
|
+
reset
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def reset
|
|
11
|
+
@no_children = false
|
|
12
|
+
@no_siblings = false
|
|
13
|
+
@done = false
|
|
14
|
+
|
|
15
|
+
@short_circuit = false
|
|
16
|
+
|
|
17
|
+
@visited = {}
|
|
18
|
+
@visiting = {}
|
|
19
|
+
|
|
20
|
+
@revisiting = false
|
|
21
|
+
@cycling = false
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def cycle(xampl)
|
|
25
|
+
return false
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def revisit(xampl)
|
|
29
|
+
return false
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def short_circuit
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def method_missing(symbol, *args)
|
|
36
|
+
return nil
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def substitute_in_visit(xampl)
|
|
40
|
+
return xampl.substitute_in_visit(self)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def before_visit(xampl)
|
|
44
|
+
xampl.before_visit(self)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def after_visit(xampl)
|
|
48
|
+
xampl.after_visit(self)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def around_visit(xampl)
|
|
52
|
+
return false
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def visit_string(string)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def start(xampl_in)
|
|
59
|
+
xampl = substitute_in_visit(xampl_in)
|
|
60
|
+
|
|
61
|
+
n = @visiting[xampl]
|
|
62
|
+
if n then
|
|
63
|
+
@visiting[xampl] = n + 1
|
|
64
|
+
else
|
|
65
|
+
@visiting[xampl] = 1
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
if 1 < @visiting[xampl] then
|
|
69
|
+
return self unless cycle(xampl)
|
|
70
|
+
@cycling = true
|
|
71
|
+
@revisiting = true
|
|
72
|
+
elsif @visited.has_key? xampl then
|
|
73
|
+
return self unless revisit(xampl)
|
|
74
|
+
@revisiting = true
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
@visited[xampl] = xampl
|
|
78
|
+
|
|
79
|
+
before_visit(xampl)
|
|
80
|
+
if @no_children then
|
|
81
|
+
@no_children = false
|
|
82
|
+
return self
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
xampl.visit(self) unless around_visit(xampl) or !xampl.respond_to? "visit"
|
|
86
|
+
|
|
87
|
+
return self if @done
|
|
88
|
+
return self if @no_siblings
|
|
89
|
+
|
|
90
|
+
if @no_children then
|
|
91
|
+
after_visit(xampl)
|
|
92
|
+
@no_children = false
|
|
93
|
+
return self
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
if @short_circuit then
|
|
97
|
+
short_circuit
|
|
98
|
+
@short_circuit = false
|
|
99
|
+
else
|
|
100
|
+
xampl.children.each do | child |
|
|
101
|
+
if child.kind_of?(XamplObject) then
|
|
102
|
+
start(child)
|
|
103
|
+
else
|
|
104
|
+
visit_string(child)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
after_visit(xampl) if @done
|
|
108
|
+
return self if @done
|
|
109
|
+
|
|
110
|
+
if @no_siblings then
|
|
111
|
+
@no_siblings = false
|
|
112
|
+
after_visit(xampl)
|
|
113
|
+
return self
|
|
114
|
+
end
|
|
115
|
+
end if xampl.respond_to? "children"
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
after_visit(xampl)
|
|
119
|
+
return self
|
|
120
|
+
|
|
121
|
+
rescue => e
|
|
122
|
+
puts "visit failed !!!!! #{ e }"
|
|
123
|
+
e.backtrace.each do | trace |
|
|
124
|
+
puts " #{trace}"
|
|
125
|
+
break if /actionpack/ =~ trace
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
ensure
|
|
129
|
+
n = @visiting[xampl]
|
|
130
|
+
if 1 == n then
|
|
131
|
+
@visiting.delete(xampl)
|
|
132
|
+
else
|
|
133
|
+
@visiting[xampl] = n - 1
|
|
134
|
+
end
|
|
135
|
+
@revisiting = false
|
|
136
|
+
@cycling = false
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
|