rsolr 2.0.0.pre2 → 2.0.0.pre3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c12bcd80599dbe9baf6b616dd23422a935587718
4
- data.tar.gz: ea19f8226b2a7737099c38094899a46a649e3de0
3
+ metadata.gz: 452ea2927fbbb82cad4aba0948007a0e6cf1bd13
4
+ data.tar.gz: 7cbed4e5da8b29a69c3f8004f29a91de9d299fcb
5
5
  SHA512:
6
- metadata.gz: dc3e492100005e174362232e5cf4b1e6d0d0e8a4288fd8810256980747288f9ff74fa61411d565610c9c234d2d638fe1c190a1c4bb35d57310b54005a1943440
7
- data.tar.gz: 0ec2bcdf0bbcfdc8bc82d711f9c5df3158f56c948f8ae698ce07a7959aeb82534f2a202c90461003a3d99f1ce411d58b9d80e7e24ca433a1a463d6fd0b89363b
6
+ metadata.gz: 5abc10f76135922d1f5ce642efa245b20bf29ac01432d6dfbf8f053944b60d70fe76db2dac7eec41d35b72a8fff66cff6b98a11b449d2796243df111eb06c4bd
7
+ data.tar.gz: 5b096b2d49a2721c86cef3d879bca8d806234c8a5f1784b9686e5ae0c39873a048cb6affb0f6f73918eaf2a771cc8e04041320ec9df75e76bd41a11cc03a60af
data/.travis.yml CHANGED
@@ -1,9 +1,10 @@
1
1
  language: ruby
2
2
  sudo: false
3
3
  rvm:
4
- - 2.3.1
5
- - 2.2.5
6
- - jruby-9.1.5.0
4
+ - 2.4.0
5
+ - 2.3.3
6
+ - 2.2.6
7
+ - jruby-9.1.7.0
7
8
 
8
9
  env:
9
10
  global:
@@ -38,8 +38,6 @@ module RSolr
38
38
  #
39
39
  def add_field(name, values, options = {})
40
40
  RSolr::Array.wrap(values).each do |v|
41
- next if v.nil?
42
-
43
41
  field_attrs = { name: name }
44
42
  field_attrs[:type] = DocumentField if name.to_s == CHILD_DOCUMENT_KEY
45
43
 
@@ -55,91 +53,4 @@ module RSolr
55
53
  end
56
54
  end
57
55
  end
58
-
59
- class Field
60
-
61
- def self.instance(attrs, value)
62
- attrs = attrs.dup
63
- field_type = attrs.delete(:type) { value.class.name }
64
-
65
- klass = if field_type.is_a? String
66
- class_for_field(field_type)
67
- elsif field_type.is_a? Class
68
- field_type
69
- else
70
- self
71
- end
72
-
73
- klass.new(attrs, value)
74
- end
75
-
76
- def self.class_for_field(field_type)
77
- potential_class_name = field_type + 'Field'.freeze
78
- search_scope = Module.nesting[1]
79
- search_scope.const_defined?(potential_class_name, false) ? search_scope.const_get(potential_class_name) : self
80
- end
81
- private_class_method :class_for_field
82
-
83
- # "attrs" is a hash for setting the "doc" xml attributes
84
- # "value" is the text value for the node
85
- attr_accessor :attrs, :source_value
86
-
87
- # "attrs" must be a hash
88
- # "value" should be something that responds to #_to_s
89
- def initialize(attrs, source_value)
90
- @attrs = attrs
91
- @source_value = source_value
92
- end
93
-
94
- # the value of the "name" attribute
95
- def name
96
- attrs[:name]
97
- end
98
-
99
- def value
100
- source_value
101
- end
102
-
103
- def as_json
104
- if attrs[:update]
105
- { attrs[:update] => value }
106
- elsif attrs.any? { |k, _| k != :name }
107
- hash = attrs.dup
108
- hash.delete(:name)
109
- hash.merge(value: value)
110
- else
111
- value
112
- end
113
- end
114
- end
115
-
116
- class DateField < Field
117
- def value
118
- Time.utc(source_value.year, source_value.mon, source_value.mday).iso8601
119
- end
120
- end
121
-
122
- class TimeField < Field
123
- def value
124
- source_value.getutc.strftime('%FT%TZ')
125
- end
126
- end
127
-
128
- class DateTimeField < Field
129
- def value
130
- source_value.to_time.getutc.iso8601
131
- end
132
- end
133
-
134
- class DocumentField < Field
135
- def value
136
- return RSolr::Document.new(source_value) if source_value.respond_to? :each_pair
137
-
138
- super
139
- end
140
-
141
- def as_json
142
- value.as_json
143
- end
144
- end
145
56
  end
@@ -0,0 +1,87 @@
1
+ module RSolr
2
+ class Field
3
+ def self.instance(attrs, value)
4
+ attrs = attrs.dup
5
+ field_type = attrs.delete(:type) { value.class.name }
6
+
7
+ klass = if field_type.is_a? String
8
+ class_for_field(field_type)
9
+ elsif field_type.is_a? Class
10
+ field_type
11
+ else
12
+ self
13
+ end
14
+
15
+ klass.new(attrs, value)
16
+ end
17
+
18
+ def self.class_for_field(field_type)
19
+ potential_class_name = field_type + 'Field'.freeze
20
+ search_scope = Module.nesting[1]
21
+ search_scope.const_defined?(potential_class_name, false) ? search_scope.const_get(potential_class_name) : self
22
+ end
23
+ private_class_method :class_for_field
24
+
25
+ # "attrs" is a hash for setting the "doc" xml attributes
26
+ # "value" is the text value for the node
27
+ attr_accessor :attrs, :source_value
28
+
29
+ # "attrs" must be a hash
30
+ # "value" should be something that responds to #_to_s
31
+ def initialize(attrs, source_value)
32
+ @attrs = attrs
33
+ @source_value = source_value
34
+ end
35
+
36
+ # the value of the "name" attribute
37
+ def name
38
+ attrs[:name]
39
+ end
40
+
41
+ def value
42
+ source_value
43
+ end
44
+
45
+ def as_json
46
+ if attrs[:update]
47
+ { attrs[:update] => value }
48
+ elsif attrs.any? { |k, _| k != :name }
49
+ hash = attrs.dup
50
+ hash.delete(:name)
51
+ hash.merge(value: value)
52
+ else
53
+ value
54
+ end
55
+ end
56
+ end
57
+
58
+ class DateField < Field
59
+ def value
60
+ Time.utc(source_value.year, source_value.mon, source_value.mday).iso8601
61
+ end
62
+ end
63
+
64
+ class TimeField < Field
65
+ def value
66
+ source_value.getutc.strftime('%FT%TZ')
67
+ end
68
+ end
69
+
70
+ class DateTimeField < Field
71
+ def value
72
+ source_value.to_time.getutc.iso8601
73
+ end
74
+ end
75
+
76
+ class DocumentField < Field
77
+ def value
78
+ return RSolr::Document.new(source_value) if source_value.respond_to? :each_pair
79
+
80
+ super
81
+ end
82
+
83
+ def as_json
84
+ value.as_json
85
+ end
86
+ end
87
+ end
data/lib/rsolr/json.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'json'
2
+ require 'rsolr/generator'
2
3
 
3
4
  module RSolr::JSON
4
5
  class Generator < RSolr::Generator
data/lib/rsolr/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module RSolr
2
- VERSION = "2.0.0.pre2"
2
+ VERSION = "2.0.0.pre3"
3
3
 
4
4
  def self.version
5
5
  VERSION
data/lib/rsolr/xml.rb CHANGED
@@ -1,6 +1,6 @@
1
+ require 'rsolr/generator'
2
+ require 'rsolr/document'
1
3
  module RSolr::Xml
2
- require 'rsolr/document'
3
-
4
4
  Document = RSolr::Document
5
5
  Field = RSolr::Field
6
6
 
@@ -133,12 +133,15 @@ module RSolr::Xml
133
133
  lambda do |doc_node|
134
134
  doc.fields.each do |field_obj|
135
135
  value = field_obj.value
136
+
136
137
  if field_obj.name.to_s == RSolr::Document::CHILD_DOCUMENT_KEY
137
138
  child_node_builder = to_xml(field_obj.value)
138
139
  self.class.use_nokogiri ? doc_node.doc_(&child_node_builder) : doc_node.doc(&child_node_builder)
139
140
  elsif value.is_a?(Hash) && value.length == 1 && field_obj.attrs[:update].nil?
140
141
  update_attr, real_value = value.first
141
142
  doc_node.field real_value, field_obj.attrs.merge(update: update_attr)
143
+ elsif value.nil?
144
+ doc_node.field field_obj.value, field_obj.attrs.merge(null: true)
142
145
  else
143
146
  doc_node.field field_obj.value, field_obj.attrs
144
147
  end
data/lib/rsolr.rb CHANGED
@@ -25,7 +25,7 @@ module RSolr
25
25
  module Array
26
26
  def self.wrap(object)
27
27
  if object.nil?
28
- []
28
+ [nil]
29
29
  elsif object.respond_to?(:to_ary)
30
30
  object.to_ary || [object]
31
31
  elsif object.is_a? Hash
@@ -37,4 +37,4 @@ module RSolr
37
37
  end
38
38
  end
39
39
  end
40
- end
40
+ end
data/spec/api/xml_spec.rb CHANGED
@@ -89,6 +89,15 @@ RSpec.describe RSolr::Xml do
89
89
  expect(result).to match(/<field name="name" update="set">matt<\/field>/)
90
90
  expect(result).to match(/<field name="id">1<\/field>/)
91
91
  end
92
+ it 'should remove a field from a hash formatted for atomic updates' do
93
+ data = {
94
+ :id => 1,
95
+ :name => nil
96
+ }
97
+ result = generator.add(data)
98
+ expect(result).to match(%r{<field name="name" null="true"})
99
+ expect(result).to match(/<field name="id">1<\/field>/)
100
+ end
92
101
 
93
102
  # add an array of hashes
94
103
  it 'should create many adds from an array of hashes' do
@@ -103,7 +112,6 @@ RSpec.describe RSolr::Xml do
103
112
  }
104
113
  ]
105
114
  message = generator.add(data)
106
- 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>"
107
115
  expect(message).to match %r{<field name="name">matt</field>}
108
116
  expect(message).to match %r{<field name="name">sam</field>}
109
117
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rsolr
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.pre2
4
+ version: 2.0.0.pre3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antoine Latter
@@ -29,7 +29,7 @@ authors:
29
29
  autorequire:
30
30
  bindir: bin
31
31
  cert_chain: []
32
- date: 2017-02-05 00:00:00.000000000 Z
32
+ date: 2017-02-24 00:00:00.000000000 Z
33
33
  dependencies:
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: builder
@@ -164,6 +164,7 @@ files:
164
164
  - lib/rsolr/client.rb
165
165
  - lib/rsolr/document.rb
166
166
  - lib/rsolr/error.rb
167
+ - lib/rsolr/field.rb
167
168
  - lib/rsolr/generator.rb
168
169
  - lib/rsolr/json.rb
169
170
  - lib/rsolr/response.rb
@@ -210,7 +211,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
210
211
  requirements:
211
212
  - Apache Solr
212
213
  rubyforge_project: rsolr
213
- rubygems_version: 2.5.2
214
+ rubygems_version: 2.6.8
214
215
  signing_key:
215
216
  specification_version: 4
216
217
  summary: A Ruby client for Apache Solr