hutch-xamplr 1.0.2 → 1.0.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.
Files changed (51) hide show
  1. data/CHANGES.txt +13 -0
  2. data/VERSION.yml +1 -1
  3. data/examples/random-people/people.rb +2 -2
  4. data/examples/random-people/query.rb +16 -11
  5. data/examples/random-people-shared-addresses/Makefile +16 -0
  6. data/examples/random-people-shared-addresses/batch-load-users.rb +86 -0
  7. data/examples/random-people-shared-addresses/find-mentions.rb +50 -0
  8. data/examples/random-people-shared-addresses/find-people-by-address.rb +110 -0
  9. data/examples/random-people-shared-addresses/optimise.rb +19 -0
  10. data/examples/random-people-shared-addresses/people.rb +50 -0
  11. data/examples/random-people-shared-addresses/query.rb +78 -0
  12. data/examples/random-people-shared-addresses/query2.rb +76 -0
  13. data/examples/random-people-shared-addresses/random-names.csv +10000 -0
  14. data/examples/random-people-shared-addresses/what-to-query-on.rb +82 -0
  15. data/examples/random-people-shared-addresses/xampl-gen.rb +36 -0
  16. data/examples/random-people-shared-addresses/xml/people.xml +14 -0
  17. data/lib/xamplr/TODO +1 -3
  18. data/lib/xamplr/{persister → obsolete}/fsdb.rb +0 -0
  19. data/lib/xamplr/persistence.rb +7 -3
  20. data/lib/xamplr/persister/tokyo-cabinet.rb +70 -7
  21. data/lib/xamplr/templates/element_data.template +29 -21
  22. data/lib/xamplr/templates/element_empty.template +29 -22
  23. data/lib/xamplr/templates/element_mixed.template +31 -24
  24. data/lib/xamplr/templates/element_simple.template +29 -22
  25. data/lib/xamplr/{Makefile → test-support/Makefile} +0 -0
  26. data/lib/xamplr/{bench-cache.rb → test-support/bench-cache.rb} +1 -1
  27. data/lib/xamplr/{bench-script.rb → test-support/bench-script.rb} +0 -0
  28. data/lib/xamplr/{bench.rb → test-support/bench.rb} +0 -0
  29. data/lib/xamplr/{bench2.rb → test-support/bench2.rb} +9 -9
  30. data/lib/xamplr/{test-cache.rb → test-support/test-cache.rb} +0 -0
  31. data/lib/xamplr/{test-data → test-support/test-data}/binding.xml +0 -0
  32. data/lib/xamplr/{test-data → test-support/test-data}/example.xml +0 -0
  33. data/lib/xamplr/{test-data → test-support/test-data}/internationalization-utf8.txt +0 -0
  34. data/lib/xamplr/{test-data → test-support/test-data}/labels.xml +0 -0
  35. data/lib/xamplr/{test-data → test-support/test-data}/labels001.xml +0 -0
  36. data/lib/xamplr/{test-deep-change.rb → test-support/test-deep-change.rb} +0 -0
  37. data/lib/xamplr/{test-elements.rb → test-support/test-elements.rb} +0 -0
  38. data/lib/xamplr/{test-indexed-array.rb → test-support/test-indexed-array.rb} +0 -0
  39. data/lib/xamplr/{test-misc.rb → test-support/test-misc.rb} +0 -0
  40. data/lib/xamplr/{test-names.rb → test-support/test-names.rb} +0 -0
  41. data/lib/xamplr/{test-rollback.rb → test-support/test-rollback.rb} +0 -0
  42. data/lib/xamplr/{test.rb → test-support/test.rb} +74 -74
  43. data/lib/xamplr/to-ruby.rb +19 -15
  44. data/lib/xamplr/to-xml.rb +5 -4
  45. data/lib/xamplr/visitor.rb +6 -2
  46. data/lib/xamplr/xampl-object.rb +4 -9
  47. metadata +43 -25
  48. data/lib/xamplr/BUGS +0 -3
  49. data/lib/xamplr/CHANGES +0 -16
  50. data/lib/xamplr/REQUIREMENTS +0 -2
  51. data/lib/xamplr/sqlite/sqlite-play.rb +0 -14
@@ -1,13 +1,15 @@
1
+
1
2
  module Xampl
2
3
 
3
4
  class RubyPrinter
4
5
 
5
6
  $USE_A_PROC = false
6
7
 
7
- def initialize
8
+ def initialize(mentions=nil)
8
9
  @obj_count = 0
9
10
  @map = {}
10
11
  @lookup_map={}
12
+ @mentions = mentions
11
13
  end
12
14
 
13
15
  def show_attributes(thing, name, depth)
@@ -23,7 +25,7 @@ module Xampl
23
25
  out << indent << "#{name}.#{accessor} = #{value.inspect}\n"
24
26
  end
25
27
  else
26
- thing.attributes.each{ | attribute |
28
+ thing.attributes.each do |attribute|
27
29
  value = thing.instance_variable_get(attribute[0])
28
30
 
29
31
  if value then
@@ -35,7 +37,7 @@ module Xampl
35
37
  out << indent << "#{name}.instance_variable_set(:#{attribute[0]}, #{value.inspect})\n"
36
38
  end
37
39
  end
38
- }
40
+ end
39
41
  end
40
42
  return out
41
43
  end
@@ -44,15 +46,16 @@ module Xampl
44
46
  out = ""
45
47
  indent = " " + (" " * depth)
46
48
 
47
- #TODO -- is this getting the changed flag right?
48
- return out << indent << "#{name}.load_needed = true\n" if thing.persist_required and (1 < depth)
49
+ if thing.persist_required and (1 < depth) then
50
+ return out << indent << "#{name}.load_needed = true\n"
51
+ end
49
52
 
50
53
  if (!thing.kind_of? XamplWithMixedContent) and
51
54
  (!thing.kind_of? XamplWithoutContent) and
52
55
  thing._content then
53
56
  out << indent << "#{name} << #{thing._content.inspect}\n"
54
57
  end
55
- thing.children.each{ | child |
58
+ thing.children.each do |child|
56
59
  if child.kind_of? XamplObject then
57
60
  cname = "v_#{child.safe_name}_#{@obj_count += 1}"
58
61
 
@@ -70,7 +73,7 @@ module Xampl
70
73
  else
71
74
  out << indent << "#{name} << #{child.inspect}\n"
72
75
  end
73
- }
76
+ end
74
77
  return out
75
78
  end
76
79
 
@@ -87,13 +90,13 @@ module Xampl
87
90
  out << " " << "xampl.#{accessor} = #{value.inspect}\n"
88
91
  end
89
92
  else
90
- thing.attributes.each{ | attribute |
93
+ thing.attributes.each do |attribute|
91
94
  value = thing.instance_variable_get(attribute[0])
92
95
 
93
96
  if value then
94
97
  out << " " << "xampl.instance_variable_set(:#{attribute[0]}, #{value.inspect})\n"
95
98
  end
96
- }
99
+ end
97
100
  end
98
101
  return out
99
102
  end
@@ -101,7 +104,7 @@ module Xampl
101
104
  def show_children_flat(thing, name, depth)
102
105
  out = ""
103
106
 
104
- thing.children.each{ | child |
107
+ thing.children.each do |child|
105
108
  if child.kind_of? XamplObject and (nil == @map[child]) then
106
109
  cname = "v_#{child.safe_name}_#{@obj_count += 1}"
107
110
 
@@ -113,6 +116,7 @@ module Xampl
113
116
  if 0 < cout.size then
114
117
  if child.persist_required then
115
118
  out << " " << "#{cname} = #{child.class.to_s}['#{child.get_the_index}']\n"
119
+ @mentions << child if @mentions
116
120
  else
117
121
  out << " " << "#{cname} = #{child.class.to_s}.new { | xampl |\n"
118
122
  out << cout
@@ -123,7 +127,7 @@ module Xampl
123
127
  end
124
128
  out << show_children_flat(child, cname, 1 + depth) unless child.persist_required
125
129
  end
126
- }
130
+ end
127
131
  return out
128
132
  end
129
133
 
@@ -149,18 +153,18 @@ module Xampl
149
153
  thing._content then
150
154
  out << " " << "#{name} << #{thing._content.inspect}\n"
151
155
  end
152
- thing.children.each{ | child |
156
+ thing.children.each do |child|
153
157
  if child.kind_of? XamplObject then
154
158
  out << " " << "#{name} << #{@lookup_map[child]}\n"
155
159
  else
156
160
  out << " " << "#{name} << #{child.inspect}\n"
157
161
  end
158
- }
159
- thing.children.each{ | child |
162
+ end
163
+ thing.children.each do |child|
160
164
  if child.kind_of? XamplObject then
161
165
  out << show_children_stitch(child, 1 + depth)
162
166
  end
163
- }
167
+ end
164
168
  return out
165
169
  end
166
170
 
data/lib/xamplr/to-xml.rb CHANGED
@@ -1,3 +1,4 @@
1
+
1
2
  module Xampl
2
3
 
3
4
  class XMLPrinter
@@ -69,12 +70,12 @@ module Xampl
69
70
  def attribute(xampl)
70
71
  @attr_list = []
71
72
  if (nil != xampl.attributes) then
72
- xampl.attributes.each{ | attr_spec |
73
+ xampl.attributes.each do |attr_spec|
73
74
  prefix = (2 < attr_spec.length) ? register_ns(attr_spec[2]) : ""
74
75
  value = xampl.instance_variable_get(attr_spec[0])
75
76
  @attr_list << " " << prefix << attr_spec[1] << "='" << attr_esc(value) << "'" \
76
77
  unless nil == value
77
- }
78
+ end
78
79
  end
79
80
  end
80
81
 
@@ -144,9 +145,9 @@ module Xampl
144
145
 
145
146
  def define_ns
146
147
  result = ""
147
- ns_to_prefix.each{ | ns, prefix |
148
+ ns_to_prefix.each do |ns, prefix|
148
149
  result = sprintf("%s xmlns:%s='%s'", result, prefix[0..-2], ns)
149
- }
150
+ end
150
151
  return result
151
152
  end
152
153
 
@@ -1,3 +1,4 @@
1
+
1
2
  module Xampl
2
3
 
3
4
  class Visitor
@@ -439,14 +440,16 @@ module Xampl
439
440
  end
440
441
 
441
442
  class PersistXML < Visitor
442
- attr_accessor :ns_to_prefix, :start_body, :body, :out
443
+ attr_accessor :ns_to_prefix, :start_body, :body, :out, :mentions
443
444
 
444
- def initialize(out="")
445
+ def initialize(out="", mentions=nil)
445
446
  super()
446
447
 
447
448
  @out = out
448
449
  @was_attr = false
449
450
 
451
+ @mentions = mentions
452
+
450
453
  @ns_to_prefix = {}
451
454
  @start_body = nil
452
455
  @body = ""
@@ -552,6 +555,7 @@ module Xampl
552
555
  @was_attr = true if 0 < attr_defn.size
553
556
  else
554
557
  if xampl.persist_required then
558
+ @mentions << xampl if @mentions
555
559
  @no_children = true
556
560
  persist_attribute(xampl)
557
561
  else
@@ -133,9 +133,9 @@ module Xampl
133
133
  return true
134
134
  end
135
135
 
136
- def to_ruby
136
+ def to_ruby(mentions=nil)
137
137
  accessed
138
- return RubyPrinter.new.to_ruby(self)
138
+ return RubyPrinter.new(mentions).to_ruby(self)
139
139
  end
140
140
 
141
141
  module XamplRubyDefinition
@@ -211,10 +211,8 @@ module Xampl
211
211
  return result
212
212
  end
213
213
 
214
- def persist(out="", rules=nil)
215
- #rules = XMLPrinter.new(out, true) if nil == rules
216
- #return to_xml(out, rules)
217
- return PersistXML.new("").start(self).done
214
+ def persist(out="", mentions=nil, rules=nil)
215
+ return PersistXML.new(out, mentions).start(self).done
218
216
  end
219
217
 
220
218
  def XamplObject.realise_from_xml_string(xml_string, target=nil, tokenise=true)
@@ -449,9 +447,6 @@ module Xampl
449
447
  end
450
448
 
451
449
  def to_xml(xml_printer=nil)
452
- # xml_printer should be an XMLPrinter (and it knows about
453
- # namespace prefixes)
454
-
455
450
  @text
456
451
  end
457
452
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hutch-xamplr
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Hutchison
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-16 00:00:00 -07:00
12
+ date: 2009-04-21 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -32,10 +32,23 @@ extra_rdoc_files:
32
32
  - LICENSE
33
33
  - README.rdoc
34
34
  files:
35
+ - CHANGES.txt
35
36
  - LICENSE
36
37
  - README.rdoc
37
38
  - Rakefile
38
39
  - VERSION.yml
40
+ - examples/random-people-shared-addresses/Makefile
41
+ - examples/random-people-shared-addresses/batch-load-users.rb
42
+ - examples/random-people-shared-addresses/find-mentions.rb
43
+ - examples/random-people-shared-addresses/find-people-by-address.rb
44
+ - examples/random-people-shared-addresses/optimise.rb
45
+ - examples/random-people-shared-addresses/people.rb
46
+ - examples/random-people-shared-addresses/query.rb
47
+ - examples/random-people-shared-addresses/query2.rb
48
+ - examples/random-people-shared-addresses/random-names.csv
49
+ - examples/random-people-shared-addresses/what-to-query-on.rb
50
+ - examples/random-people-shared-addresses/xampl-gen.rb
51
+ - examples/random-people-shared-addresses/xml/people.xml
39
52
  - examples/random-people/Makefile
40
53
  - examples/random-people/batch-load-users.rb
41
54
  - examples/random-people/optimise.rb
@@ -58,15 +71,7 @@ files:
58
71
  - lib/xampl.rb
59
72
  - lib/xamplr-generator.rb
60
73
  - lib/xamplr.rb
61
- - lib/xamplr/BUGS
62
- - lib/xamplr/CHANGES
63
- - lib/xamplr/Makefile
64
- - lib/xamplr/REQUIREMENTS
65
74
  - lib/xamplr/TODO
66
- - lib/xamplr/bench-cache.rb
67
- - lib/xamplr/bench-script.rb
68
- - lib/xamplr/bench.rb
69
- - lib/xamplr/bench2.rb
70
75
  - lib/xamplr/from-xml.rb
71
76
  - lib/xamplr/gen-elements.xml
72
77
  - lib/xamplr/gen.elements.xml
@@ -79,13 +84,13 @@ files:
79
84
  - lib/xamplr/mixins.rb
80
85
  - lib/xamplr/my.gen.elements.xml
81
86
  - lib/xamplr/notifications.rb
87
+ - lib/xamplr/obsolete/fsdb.rb
82
88
  - lib/xamplr/persistence.rb
83
89
  - lib/xamplr/persistence.rb.more_thread_safe
84
90
  - lib/xamplr/persistence.rb.partially_thread_safe
85
91
  - lib/xamplr/persister/caches.rb
86
92
  - lib/xamplr/persister/caching.rb
87
93
  - lib/xamplr/persister/filesystem.rb
88
- - lib/xamplr/persister/fsdb.rb
89
94
  - lib/xamplr/persister/in-memory.rb
90
95
  - lib/xamplr/persister/simple.rb
91
96
  - lib/xamplr/persister/subversion.rb
@@ -107,7 +112,6 @@ files:
107
112
  - lib/xamplr/simpleTemplate/test001.r5
108
113
  - lib/xamplr/simpleTemplate/test002.r5
109
114
  - lib/xamplr/simpleTemplate/test003.r5
110
- - lib/xamplr/sqlite/sqlite-play.rb
111
115
  - lib/xamplr/templates/child.template
112
116
  - lib/xamplr/templates/child_indexed.template
113
117
  - lib/xamplr/templates/child_indexed.template.000
@@ -118,19 +122,24 @@ files:
118
122
  - lib/xamplr/templates/element_mixed.template
119
123
  - lib/xamplr/templates/element_simple.template
120
124
  - lib/xamplr/templates/package.template
121
- - lib/xamplr/test-cache.rb
122
- - lib/xamplr/test-data/binding.xml
123
- - lib/xamplr/test-data/example.xml
124
- - lib/xamplr/test-data/internationalization-utf8.txt
125
- - lib/xamplr/test-data/labels.xml
126
- - lib/xamplr/test-data/labels001.xml
127
- - lib/xamplr/test-deep-change.rb
128
- - lib/xamplr/test-elements.rb
129
- - lib/xamplr/test-indexed-array.rb
130
- - lib/xamplr/test-misc.rb
131
- - lib/xamplr/test-names.rb
132
- - lib/xamplr/test-rollback.rb
133
- - lib/xamplr/test.rb
125
+ - lib/xamplr/test-support/Makefile
126
+ - lib/xamplr/test-support/bench-cache.rb
127
+ - lib/xamplr/test-support/bench-script.rb
128
+ - lib/xamplr/test-support/bench.rb
129
+ - lib/xamplr/test-support/bench2.rb
130
+ - lib/xamplr/test-support/test-cache.rb
131
+ - lib/xamplr/test-support/test-data/binding.xml
132
+ - lib/xamplr/test-support/test-data/example.xml
133
+ - lib/xamplr/test-support/test-data/internationalization-utf8.txt
134
+ - lib/xamplr/test-support/test-data/labels.xml
135
+ - lib/xamplr/test-support/test-data/labels001.xml
136
+ - lib/xamplr/test-support/test-deep-change.rb
137
+ - lib/xamplr/test-support/test-elements.rb
138
+ - lib/xamplr/test-support/test-indexed-array.rb
139
+ - lib/xamplr/test-support/test-misc.rb
140
+ - lib/xamplr/test-support/test-names.rb
141
+ - lib/xamplr/test-support/test-rollback.rb
142
+ - lib/xamplr/test-support/test.rb
134
143
  - lib/xamplr/to-ruby.rb
135
144
  - lib/xamplr/to-xml.rb
136
145
  - lib/xamplr/version.rb
@@ -183,6 +192,15 @@ test_files:
183
192
  - examples/random-people/rawtc.rb
184
193
  - examples/random-people/what-to-query-on.rb
185
194
  - examples/random-people/xampl-gen.rb
195
+ - examples/random-people-shared-addresses/batch-load-users.rb
196
+ - examples/random-people-shared-addresses/find-mentions.rb
197
+ - examples/random-people-shared-addresses/find-people-by-address.rb
198
+ - examples/random-people-shared-addresses/optimise.rb
199
+ - examples/random-people-shared-addresses/people.rb
200
+ - examples/random-people-shared-addresses/query.rb
201
+ - examples/random-people-shared-addresses/query2.rb
202
+ - examples/random-people-shared-addresses/what-to-query-on.rb
203
+ - examples/random-people-shared-addresses/xampl-gen.rb
186
204
  - examples/tokyo-cabinet-experimental/expt-query.rb
187
205
  - examples/tokyo-cabinet-experimental/expt-query2.rb
188
206
  - examples/tokyo-cabinet-experimental/expt-query3.rb
data/lib/xamplr/BUGS DELETED
@@ -1,3 +0,0 @@
1
-
2
- -- an element with the same name as a ruby keyword will likely fail miserably
3
-
data/lib/xamplr/CHANGES DELETED
@@ -1,16 +0,0 @@
1
-
2
-
3
- -- the accessed method will now fail outside of the persistence manager (as
4
- it should have been doing all along)
5
- -- the accessed method will try to access the persistence manager if it can
6
- to try and lazy load a xampl object
7
-
8
- -- replaced s.to_s with s.dup.to_s in content_esc and attribute_esc in
9
- to_xml and pp_xml, because s.to_s returns itself when it is a string
10
- and this caused the escaping to change the original string.
11
-
12
- -- fixed the ensure* method for non-indexed children (no longer aliased with
13
- new* so no longer does this create a new child each time it is called)
14
-
15
- -- ATTENTAION: if you are accessing attributes directly in an opened xampl class
16
- then DO NOT FAIL to call accessed
@@ -1,2 +0,0 @@
1
-
2
-
@@ -1,14 +0,0 @@
1
- #require 'sqlite3'
2
-
3
- require "rubygems"
4
- require_gem "sqlite3-ruby"
5
-
6
-
7
- db = SQLite3::Database.new( "test.db" )
8
- db.execute( "create table test ( foo int, bar text, baz int );" )
9
- db.execute( "insert into test ( foo, bar, baz ) values ( 1, 'test', 3 );" )
10
- puts "EXECUTE ----------------------------------------"
11
- db.execute( "select * from test" ) { |row| puts row.join( ',' ) }
12
- puts "EXECUTE2 ---------------------------------------"
13
- db.execute2( "select * from test" ) { |row| puts row.join( ',' ) }
14
-