algoliasearch-rails 1.16.0 → 1.16.1
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.
- checksums.yaml +4 -4
- data/ChangeLog +6 -0
- data/VERSION +1 -1
- data/lib/algoliasearch-rails.rb +55 -17
- data/spec/spec_helper.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30cea1db33b8935ea694324377f78f83fc4844d3
|
4
|
+
data.tar.gz: 284bf018c8b37a098364786b8315c7b4f586c678
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2a2d96c302380fed00f63918c15b1793d176f7d8be8ee061ac096ff0092d5c66204b4b5952f60baccbaefc954d6701bac2002ce9e1b27d755ec367a29016841
|
7
|
+
data.tar.gz: ae07742435830e1375ed1656689b6f7e2edc945104fa35498d66720bfba35ba0fe46eb05c1d0e5c67589b4ad990a037397ebcf91ce9ae816f3dcfddfcbe67c83
|
data/ChangeLog
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.16.
|
1
|
+
1.16.1
|
data/lib/algoliasearch-rails.rb
CHANGED
@@ -97,27 +97,65 @@ module AlgoliaSearch
|
|
97
97
|
end
|
98
98
|
alias :add_attributes :add_attribute
|
99
99
|
|
100
|
-
def
|
101
|
-
|
102
|
-
|
100
|
+
def is_mongoid?(object)
|
101
|
+
defined?(::Mongoid::Document) && object.class.include?(::Mongoid::Document)
|
102
|
+
end
|
103
|
+
|
104
|
+
def is_sequel?(object)
|
105
|
+
defined?(::Sequel) && object.class < ::Sequel::Model
|
106
|
+
end
|
107
|
+
|
108
|
+
def is_active_record?(object)
|
109
|
+
!is_mongoid?(object) && !is_sequel?(object)
|
110
|
+
end
|
111
|
+
|
112
|
+
def get_default_attributes(object)
|
113
|
+
if is_mongoid?(object)
|
103
114
|
# work-around mongoid 2.4's unscoped method, not accepting a block
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
res
|
108
|
-
elsif defined?(::Sequel) && clazz < ::Sequel::Model
|
109
|
-
res = @attributes.nil? || @attributes.length == 0 ? object.to_hash :
|
110
|
-
Hash[@attributes.map { |name, value| [name.to_s, value.call(object) ] }]
|
111
|
-
@additional_attributes.each { |name, value| res[name.to_s] = value.call(object) } if @additional_attributes
|
112
|
-
res
|
115
|
+
object.attributes
|
116
|
+
elsif is_sequel?(object)
|
117
|
+
object.to_hash
|
113
118
|
else
|
114
119
|
object.class.unscoped do
|
115
|
-
|
116
|
-
Hash[@attributes.map { |name, value| [name.to_s, value.call(object) ] }]
|
117
|
-
@additional_attributes.each { |name, value| res[name.to_s] = value.call(object) } if @additional_attributes
|
118
|
-
res
|
120
|
+
object.attributes
|
119
121
|
end
|
120
122
|
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def get_attribute_names(object)
|
126
|
+
res = if @attributes.nil? || @attributes.length == 0
|
127
|
+
get_default_attributes(object).keys
|
128
|
+
else
|
129
|
+
@attributes.keys
|
130
|
+
end
|
131
|
+
|
132
|
+
res += @additional_attributes.keys if @additional_attributes
|
133
|
+
|
134
|
+
res
|
135
|
+
end
|
136
|
+
|
137
|
+
def attributes_to_hash(attributes, object)
|
138
|
+
if attributes
|
139
|
+
Hash[attributes.map { |name, value| [name.to_s, value.call(object) ] }]
|
140
|
+
else
|
141
|
+
{}
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def get_attributes(object)
|
146
|
+
attributes = if @attributes.nil? || @attributes.length == 0
|
147
|
+
get_default_attributes(object)
|
148
|
+
else
|
149
|
+
if is_active_record?(object)
|
150
|
+
object.class.unscoped do
|
151
|
+
attributes_to_hash(@attributes, object)
|
152
|
+
end
|
153
|
+
else
|
154
|
+
attributes_to_hash(@attributes, object)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
attributes.merge!(attributes_to_hash(@additional_attributes, object))
|
121
159
|
|
122
160
|
if @options[:sanitize]
|
123
161
|
sanitizer = begin
|
@@ -629,7 +667,7 @@ module AlgoliaSearch
|
|
629
667
|
algolia_configurations.each do |options, settings|
|
630
668
|
next if options[:slave]
|
631
669
|
return true if algolia_object_id_changed?(object, options)
|
632
|
-
settings.
|
670
|
+
settings.get_attribute_names(object).each do |k|
|
633
671
|
changed_method = "#{k}_changed?"
|
634
672
|
return true if !object.respond_to?(changed_method) || object.send(changed_method)
|
635
673
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: algoliasearch-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.16.
|
4
|
+
version: 1.16.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Algolia
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|