rsolr 1.0.9 → 1.0.10.pre1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f864085d45dbff290a9820ec8f12bb8388ac445a
4
+ data.tar.gz: 7a117de8e81fb1c59368d4c33bc342ea379f2239
5
+ SHA512:
6
+ metadata.gz: 00410c0dd950cf7ff57a56dc55ae2d771a7de08f4b139558cd39029f763071709970400c6e99d3a5985135b54e205c576c10d8ac765010cb77e5acf71caeb87d
7
+ data.tar.gz: 3d274051c0b81c3267bdf9330ff7888c9ad65b7d6d8edb034e840d06f41c5bc49e55f7c8b72a0531518be03350e66b775b26bed9ffb65799b837753cfddcab49
@@ -0,0 +1,15 @@
1
+ rvm:
2
+ - 2.1.0
3
+ - 2.0.0
4
+ - 1.9.3
5
+ - jruby-19mode
6
+
7
+ notifications:
8
+ irc: "irc.freenode.org#blacklight"
9
+ email:
10
+ - blacklight-commits@googlegroups.com
11
+
12
+ env:
13
+ global:
14
+ - JRUBY_OPTS="-J-Xms512m -J-Xmx1024m"
15
+ - NOKOGIRI_USE_SYSTEM_LIBRARIES=true
@@ -6,7 +6,7 @@ module RSolr
6
6
 
7
7
  %W(Response Char Client Error Connection Uri Xml).each{|n|autoload n.to_sym, "rsolr/#{n.downcase}"}
8
8
 
9
- def self.version; "1.0.9" end
9
+ def self.version; "1.0.10.pre1" end
10
10
 
11
11
  VERSION = self.version
12
12
 
@@ -1,4 +1,4 @@
1
- require 'builder'
1
+ begin; require 'nokogiri'; rescue LoadError; end
2
2
 
3
3
  module RSolr::Xml
4
4
 
@@ -71,13 +71,40 @@ module RSolr::Xml
71
71
  end
72
72
 
73
73
  class Generator
74
+ class << self
75
+ attr_accessor :use_nokogiri
76
+
77
+ def builder_proc
78
+ if use_nokogiri
79
+ require 'nokogiri' unless defined?(::Nokogiri::XML::Builder)
80
+ :nokogiri_build
81
+ else
82
+ require 'builder' unless defined?(::Builder::XmlMarkup)
83
+ :builder_build
84
+ end
85
+ end
86
+ end
87
+ self.use_nokogiri = (defined?(::Nokogiri::XML::Builder) and not defined?(JRuby)) ? true : false
88
+
89
+ def nokogiri_build &block
90
+ b = ::Nokogiri::XML::Builder.new do |xml|
91
+ block_given? ? yield(xml) : xml
92
+ end
93
+ '<?xml version="1.0" encoding="UTF-8"?>'+b.to_xml(:indent => 0, :encoding => 'UTF-8', :save_with => ::Nokogiri::XML::Node::SaveOptions::AS_XML | ::Nokogiri::XML::Node::SaveOptions::NO_DECLARATION).strip
94
+ end
95
+ protected :nokogiri_build
74
96
 
75
- def build &block
97
+ def builder_build &block
76
98
  b = ::Builder::XmlMarkup.new(:indent => 0, :margin => 0, :encoding => 'UTF-8')
77
99
  b.instruct!
78
100
  block_given? ? yield(b) : b
79
101
  end
80
-
102
+ protected :builder_build
103
+
104
+ def build &block
105
+ self.send(self.class.builder_proc,&block)
106
+ end
107
+
81
108
  # generates "add" xml for updating solr
82
109
  # "data" can be a hash or an array of hashes.
83
110
  # - each hash should be a simple key=>value pair representing a solr doc.
@@ -111,11 +138,12 @@ module RSolr::Xml
111
138
  data.each do |doc|
112
139
  doc = RSolr::Xml::Document.new(doc) if doc.respond_to?(:each_pair)
113
140
  yield doc if block_given?
114
- add_node.doc(doc.attrs) do |doc_node|
141
+ doc_node_builder = lambda do |doc_node|
115
142
  doc.fields.each do |field_obj|
116
143
  doc_node.field field_obj.value, field_obj.attrs
117
144
  end
118
145
  end
146
+ self.class.use_nokogiri ? add_node.doc_(doc.attrs,&doc_node_builder) : add_node.doc(doc.attrs,&doc_node_builder)
119
147
  end
120
148
  end
121
149
  end
@@ -144,7 +172,9 @@ module RSolr::Xml
144
172
  ids = [ids] unless ids.is_a?(Array)
145
173
  build do |xml|
146
174
  xml.delete do |delete_node|
147
- ids.each { |id| delete_node.id(id) }
175
+ ids.each do |id|
176
+ self.class.use_nokogiri ? delete_node.id_(id) : delete_node.id(id)
177
+ end
148
178
  end
149
179
  end
150
180
  end
@@ -162,4 +192,4 @@ module RSolr::Xml
162
192
 
163
193
  end
164
194
 
165
- end
195
+ end
@@ -28,6 +28,7 @@ Gem::Specification.new do |s|
28
28
  s.require_paths = ["lib"]
29
29
 
30
30
  s.add_dependency 'builder', '>= 2.1.2'
31
+ s.add_development_dependency 'nokogiri', '>= 1.4.0'
31
32
  s.add_development_dependency 'rake', '~> 0.9.2'
32
33
  s.add_development_dependency 'rdoc', '~> 3.9.4'
33
34
  s.add_development_dependency 'rspec', '~> 2.6.0'
@@ -1,121 +1,157 @@
1
1
  require 'spec_helper'
2
+ require 'builder'
3
+ require 'nokogiri'
2
4
  describe "RSolr::Xml" do
3
5
 
4
6
  let(:generator){ RSolr::Xml::Generator.new }
5
-
6
- # call all of the simple methods...
7
- # make sure the xml string is valid
8
- # ensure the class is actually Solr::XML
9
- [:optimize, :rollback, :commit].each do |meth|
10
- it "#{meth} should generator xml" do
11
- result = generator.send(meth)
12
- result.should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?><#{meth}/>"
13
- end
7
+ let(:builder_engines) do
8
+ {
9
+ :builder => { :val => false, :class => Builder::XmlMarkup, :engine => Builder::XmlMarkup.new(:indent => 0, :margin => 0, :encoding => 'UTF-8') },
10
+ :nokogiri => { :val => true, :class => Nokogiri::XML::Builder, :engine => Nokogiri::XML::Builder.new }
11
+ }
14
12
  end
13
+
14
+ [:builder,:nokogiri].each do |engine_name|
15
+ describe engine_name do
16
+ before :all do
17
+ @engine = builder_engines[engine_name]
18
+ @old_ng_setting = RSolr::Xml::Generator.use_nokogiri
19
+ RSolr::Xml::Generator.use_nokogiri = @engine[:val]
20
+ end
21
+
22
+ after :all do
23
+ RSolr::Xml::Generator.use_nokogiri = @old_ng_setting
24
+ end
15
25
 
16
- context :add do
17
-
18
- it 'should yield a Message::Document object when #add is called with a block' do
19
- documents = [{:id=>1, :name=>'sam', :cat=>['cat 1', 'cat 2']}]
20
- add_attrs = {:boost=>200.00}
21
- result = generator.add(documents, add_attrs) do |doc|
22
- doc.field_by_name(:name).attrs[:boost] = 10
23
- doc.fields.size.should == 4
24
- doc.fields_by_name(:cat).size.should == 2
26
+ before :each do
27
+ builder_engines.each_pair do |name,spec|
28
+ spec[:class].should_not_receive(:new) unless name == engine_name
29
+ end
25
30
  end
26
- result.should match(%r(name="cat">cat 1</field>))
27
- result.should match(%r(name="cat">cat 2</field>))
28
- result.should match(%r(<add boost="200.0">))
29
- result.should match(%r(boost="10"))
30
- result.should match(%r(<field name="id">1</field>))
31
- end
31
+
32
+ context :xml_engine do
33
+ it "should use #{engine_name}" do
34
+ @engine[:class].should_receive(:new).and_return(@engine[:engine])
35
+ generator.send(:commit)
36
+ end
37
+ end
38
+
39
+ # call all of the simple methods...
40
+ # make sure the xml string is valid
41
+ # ensure the class is actually Solr::XML
42
+ [:optimize, :rollback, :commit].each do |meth|
43
+ it "#{meth} should generator xml" do
44
+ result = generator.send(meth)
45
+ result.should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?><#{meth}/>"
46
+ end
47
+ end
48
+
49
+ context :add do
32
50
 
33
- # add a single hash ("doc")
34
- it 'should create an add from a hash' do
35
- data = {
36
- :id=>1,
37
- :name=>'matt'
38
- }
39
- result = generator.add(data)
40
- result.should match(/<field name="name">matt<\/field>/)
41
- result.should match(/<field name="id">1<\/field>/)
42
- end
51
+ it 'should yield a Message::Document object when #add is called with a block' do
52
+ documents = [{:id=>1, :name=>'sam', :cat=>['cat 1', 'cat 2']}]
53
+ add_attrs = {:boost=>200.00}
54
+ result = generator.add(documents, add_attrs) do |doc|
55
+ doc.field_by_name(:name).attrs[:boost] = 10
56
+ doc.fields.size.should == 4
57
+ doc.fields_by_name(:cat).size.should == 2
58
+ end
59
+ result.should match(%r(name="cat">cat 1</field>))
60
+ result.should match(%r(name="cat">cat 2</field>))
61
+ result.should match(%r(<add boost="200.0">))
62
+ result.should match(%r(boost="10"))
63
+ result.should match(%r(<field name="id">1</field>))
64
+ end
65
+
66
+ # add a single hash ("doc")
67
+ it 'should create an add from a hash' do
68
+ data = {
69
+ :id=>1,
70
+ :name=>'matt'
71
+ }
72
+ result = generator.add(data)
73
+ result.should match(/<field name="name">matt<\/field>/)
74
+ result.should match(/<field name="id">1<\/field>/)
75
+ end
43
76
 
44
- # add an array of hashes
45
- it 'should create many adds from an array of hashes' do
46
- data = [
47
- {
48
- :id=>1,
49
- :name=>'matt'
50
- },
51
- {
52
- :id=>2,
53
- :name=>'sam'
54
- }
55
- ]
56
- message = generator.add(data)
57
- expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><add><doc><field name=\"id\">1</field><field name=\"name\">matt</field></doc><doc><field name=\"id\">2</field><field name=\"name\">sam</field></doc></add>"
58
- message.should match(/<field name="name">matt<\/field>/)
59
- message.should match(/<field name="name">sam<\/field>/)
60
- end
77
+ # add an array of hashes
78
+ it 'should create many adds from an array of hashes' do
79
+ data = [
80
+ {
81
+ :id=>1,
82
+ :name=>'matt'
83
+ },
84
+ {
85
+ :id=>2,
86
+ :name=>'sam'
87
+ }
88
+ ]
89
+ message = generator.add(data)
90
+ expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><add><doc><field name=\"id\">1</field><field name=\"name\">matt</field></doc><doc><field name=\"id\">2</field><field name=\"name\">sam</field></doc></add>"
91
+ message.should match(/<field name="name">matt<\/field>/)
92
+ message.should match(/<field name="name">sam<\/field>/)
93
+ end
61
94
 
62
- # multiValue field support test, thanks to Fouad Mardini!
63
- it 'should create multiple fields from array values' do
64
- data = {
65
- :id => 1,
66
- :name => ['matt1', 'matt2']
67
- }
68
- result = generator.add(data)
69
- result.should match(/<field name="name">matt1<\/field>/)
70
- result.should match(/<field name="name">matt2<\/field>/)
71
- end
95
+ # multiValue field support test, thanks to Fouad Mardini!
96
+ it 'should create multiple fields from array values' do
97
+ data = {
98
+ :id => 1,
99
+ :name => ['matt1', 'matt2']
100
+ }
101
+ result = generator.add(data)
102
+ result.should match(/<field name="name">matt1<\/field>/)
103
+ result.should match(/<field name="name">matt2<\/field>/)
104
+ end
72
105
 
73
- it 'should create an add from a single Message::Document' do
74
- document = RSolr::Xml::Document.new
75
- document.add_field('id', 1)
76
- document.add_field('name', 'matt', :boost => 2.0)
77
- result = generator.add(document)
78
- result.should match(Regexp.escape('<?xml version="1.0" encoding="UTF-8"?>'))
79
- result.should match(/<field name="id">1<\/field>/)
80
- result.should match Regexp.escape('boost="2.0"')
81
- result.should match Regexp.escape('name="name"')
82
- result.should match Regexp.escape('matt</field>')
83
- end
106
+ it 'should create an add from a single Message::Document' do
107
+ document = RSolr::Xml::Document.new
108
+ document.add_field('id', 1)
109
+ document.add_field('name', 'matt', :boost => 2.0)
110
+ result = generator.add(document)
111
+ result.should match(Regexp.escape('<?xml version="1.0" encoding="UTF-8"?>'))
112
+ result.should match(/<field name="id">1<\/field>/)
113
+ result.should match Regexp.escape('boost="2.0"')
114
+ result.should match Regexp.escape('name="name"')
115
+ result.should match Regexp.escape('matt</field>')
116
+ end
84
117
 
85
- it 'should create adds from multiple Message::Documents' do
86
- documents = (1..2).map do |i|
87
- doc = RSolr::Xml::Document.new
88
- doc.add_field('id', i)
89
- doc.add_field('name', "matt#{i}")
90
- doc
91
- end
92
- result = generator.add(documents)
93
- result.should match(/<field name="name">matt1<\/field>/)
94
- result.should match(/<field name="name">matt2<\/field>/)
95
- end
118
+ it 'should create adds from multiple Message::Documents' do
119
+ documents = (1..2).map do |i|
120
+ doc = RSolr::Xml::Document.new
121
+ doc.add_field('id', i)
122
+ doc.add_field('name', "matt#{i}")
123
+ doc
124
+ end
125
+ result = generator.add(documents)
126
+ result.should match(/<field name="name">matt1<\/field>/)
127
+ result.should match(/<field name="name">matt2<\/field>/)
128
+ end
96
129
 
97
- end
130
+ end
98
131
 
99
- context :delete_by_id do
132
+ context :delete_by_id do
100
133
 
101
- it 'should create a doc id delete' do
102
- generator.delete_by_id(10).should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?><delete><id>10</id></delete>"
103
- end
134
+ it 'should create a doc id delete' do
135
+ generator.delete_by_id(10).should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?><delete><id>10</id></delete>"
136
+ end
104
137
 
105
- it 'should create many doc id deletes' do
106
- generator.delete_by_id([1, 2, 3]).should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?><delete><id>1</id><id>2</id><id>3</id></delete>"
107
- end
138
+ it 'should create many doc id deletes' do
139
+ generator.delete_by_id([1, 2, 3]).should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?><delete><id>1</id><id>2</id><id>3</id></delete>"
140
+ end
108
141
 
109
- end
142
+ end
110
143
 
111
- context :delete_by_query do
112
- it 'should create a query delete' do
113
- generator.delete_by_query('status:"LOST"').should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?><delete><query>status:\"LOST\"</query></delete>"
114
- end
144
+ context :delete_by_query do
145
+ it 'should create a query delete' do
146
+ generator.delete_by_query('status:"LOST"').should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?><delete><query>status:\"LOST\"</query></delete>"
147
+ end
115
148
 
116
- it 'should create many query deletes' do
117
- generator.delete_by_query(['status:"LOST"', 'quantity:0']).should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?><delete><query>status:\"LOST\"</query><query>quantity:0</query></delete>"
149
+ it 'should create many query deletes' do
150
+ generator.delete_by_query(['status:"LOST"', 'quantity:0']).should == "<?xml version=\"1.0\" encoding=\"UTF-8\"?><delete><query>status:\"LOST\"</query><query>quantity:0</query></delete>"
151
+ end
152
+ end
153
+
118
154
  end
119
155
  end
120
-
156
+
121
157
  end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rsolr
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.9
5
- prerelease:
4
+ version: 1.0.10.pre1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Antoine Latter
@@ -25,56 +24,82 @@ authors:
25
24
  - Fouad Mardini
26
25
  - Jeremy Hinegardner
27
26
  - Nathan Witmer
28
- - ! '"shima"'
27
+ - '"shima"'
29
28
  autorequire:
30
29
  bindir: bin
31
30
  cert_chain: []
32
- date: 2013-03-29 00:00:00.000000000Z
31
+ date: 2014-01-16 00:00:00.000000000 Z
33
32
  dependencies:
34
33
  - !ruby/object:Gem::Dependency
35
34
  name: builder
36
- requirement: &70317957140320 !ruby/object:Gem::Requirement
37
- none: false
35
+ requirement: !ruby/object:Gem::Requirement
38
36
  requirements:
39
- - - ! '>='
37
+ - - '>='
40
38
  - !ruby/object:Gem::Version
41
39
  version: 2.1.2
42
40
  type: :runtime
43
41
  prerelease: false
44
- version_requirements: *70317957140320
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - '>='
45
+ - !ruby/object:Gem::Version
46
+ version: 2.1.2
47
+ - !ruby/object:Gem::Dependency
48
+ name: nokogiri
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 1.4.0
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - '>='
59
+ - !ruby/object:Gem::Version
60
+ version: 1.4.0
45
61
  - !ruby/object:Gem::Dependency
46
62
  name: rake
47
- requirement: &70317957139580 !ruby/object:Gem::Requirement
48
- none: false
63
+ requirement: !ruby/object:Gem::Requirement
49
64
  requirements:
50
65
  - - ~>
51
66
  - !ruby/object:Gem::Version
52
67
  version: 0.9.2
53
68
  type: :development
54
69
  prerelease: false
55
- version_requirements: *70317957139580
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ~>
73
+ - !ruby/object:Gem::Version
74
+ version: 0.9.2
56
75
  - !ruby/object:Gem::Dependency
57
76
  name: rdoc
58
- requirement: &70317957138980 !ruby/object:Gem::Requirement
59
- none: false
77
+ requirement: !ruby/object:Gem::Requirement
60
78
  requirements:
61
79
  - - ~>
62
80
  - !ruby/object:Gem::Version
63
81
  version: 3.9.4
64
82
  type: :development
65
83
  prerelease: false
66
- version_requirements: *70317957138980
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ~>
87
+ - !ruby/object:Gem::Version
88
+ version: 3.9.4
67
89
  - !ruby/object:Gem::Dependency
68
90
  name: rspec
69
- requirement: &70317957138400 !ruby/object:Gem::Requirement
70
- none: false
91
+ requirement: !ruby/object:Gem::Requirement
71
92
  requirements:
72
93
  - - ~>
73
94
  - !ruby/object:Gem::Version
74
95
  version: 2.6.0
75
96
  type: :development
76
97
  prerelease: false
77
- version_requirements: *70317957138400
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ~>
101
+ - !ruby/object:Gem::Version
102
+ version: 2.6.0
78
103
  description: RSolr aims to provide a simple and extensible library for working with
79
104
  Solr
80
105
  email:
@@ -84,6 +109,7 @@ extensions: []
84
109
  extra_rdoc_files: []
85
110
  files:
86
111
  - .gitignore
112
+ - .travis.yml
87
113
  - CHANGES.txt
88
114
  - Gemfile
89
115
  - LICENSE
@@ -113,26 +139,26 @@ files:
113
139
  - tasks/spec.rake
114
140
  homepage: https://github.com/mwmitchell/rsolr
115
141
  licenses: []
142
+ metadata: {}
116
143
  post_install_message:
117
144
  rdoc_options: []
118
145
  require_paths:
119
146
  - lib
120
147
  required_ruby_version: !ruby/object:Gem::Requirement
121
- none: false
122
148
  requirements:
123
- - - ! '>='
149
+ - - '>='
124
150
  - !ruby/object:Gem::Version
125
151
  version: '0'
126
152
  required_rubygems_version: !ruby/object:Gem::Requirement
127
- none: false
128
153
  requirements:
129
- - - ! '>='
154
+ - - '>'
130
155
  - !ruby/object:Gem::Version
131
- version: '0'
156
+ version: 1.3.1
132
157
  requirements: []
133
158
  rubyforge_project: rsolr
134
- rubygems_version: 1.8.11
159
+ rubygems_version: 2.1.11
135
160
  signing_key:
136
- specification_version: 3
161
+ specification_version: 4
137
162
  summary: A Ruby client for Apache Solr
138
163
  test_files: []
164
+ has_rdoc: