algoliasearch-rails 1.16.0 → 1.16.1

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: 896c5f230813d18ff8e9690822d0a4306333db91
4
- data.tar.gz: aebeff6835f6dd017dede213dcce29671cf3ef6b
3
+ metadata.gz: 30cea1db33b8935ea694324377f78f83fc4844d3
4
+ data.tar.gz: 284bf018c8b37a098364786b8315c7b4f586c678
5
5
  SHA512:
6
- metadata.gz: 5e53db4e89af8d4ed8432f6cb918d62050348d7ebc6ee54f42839714a695f0199a7c6c65d17e1a9341c88b76751b305eca24919dbd7f91f0e765388215ecbe11
7
- data.tar.gz: 7a11bf529e54d4b2024b0e0947baa7d1c985246945eafc910513301b7a79525609dd102f465119a9e68ca09ddc5e047966ba43e743467b905dfb9a4aba3efaa8
6
+ metadata.gz: c2a2d96c302380fed00f63918c15b1793d176f7d8be8ee061ac096ff0092d5c66204b4b5952f60baccbaefc954d6701bac2002ce9e1b27d755ec367a29016841
7
+ data.tar.gz: ae07742435830e1375ed1656689b6f7e2edc945104fa35498d66720bfba35ba0fe46eb05c1d0e5c67589b4ad990a037397ebcf91ce9ae816f3dcfddfcbe67c83
data/ChangeLog CHANGED
@@ -1,5 +1,11 @@
1
1
  CHANGELOG
2
2
 
3
+ 2016-11-04 1.16.1
4
+
5
+ * Added IndexSettings#get_attribute_names
6
+ * Refactored IndexSettings#get_attributes
7
+ * algolia_must_reindex? doesn't compute attribute values anymore
8
+
3
9
  2016-10-02 1.16.0
4
10
 
5
11
  * Upgrade `algoliasearch` to 1.12.0
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.16.0
1
+ 1.16.1
@@ -97,27 +97,65 @@ module AlgoliaSearch
97
97
  end
98
98
  alias :add_attributes :add_attribute
99
99
 
100
- def get_attributes(object)
101
- clazz = object.class
102
- attributes = if defined?(::Mongoid::Document) && clazz.include?(::Mongoid::Document)
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
- res = @attributes.nil? || @attributes.length == 0 ? object.attributes :
105
- Hash[@attributes.map { |name, value| [name.to_s, value.call(object) ] }]
106
- @additional_attributes.each { |name, value| res[name.to_s] = value.call(object) } if @additional_attributes
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
- res = @attributes.nil? || @attributes.length == 0 ? object.attributes :
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.get_attributes(object).each do |k, v|
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
@@ -18,6 +18,7 @@ RSpec.configure do |c|
18
18
  c.mock_with :rspec
19
19
  c.filter_run :focus => true
20
20
  c.run_all_when_everything_filtered = true
21
+ c.formatter = 'documentation'
21
22
  end
22
23
 
23
24
  # avoid concurrent access to the same index
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.0
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-10-31 00:00:00.000000000 Z
11
+ date: 2016-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json