algoliasearch-rails 1.21.0 → 1.22.0

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
  SHA256:
3
- metadata.gz: 1eb55772f506326a5847dbc0ebee0674f23c8a382b3eea7c3fddc01b9039150d
4
- data.tar.gz: f41c8aa08a1d28ddf8f88643bb5e6231e4f447e49ff21714d0b803e6c0567394
3
+ metadata.gz: 04d14efb20e58715bff263a1eb160ccd0d192c7c44091b03aa2dc9f9ee9a3bac
4
+ data.tar.gz: 0eaa9daddcdde5d578fa8a9657a3233bcf7b30d24af61f9892056c70bf9dfe3e
5
5
  SHA512:
6
- metadata.gz: 8c763ac336f5cb507a73dbaf5b1d2be086bef6260054c3887bf2d7fa568fb513e8611151a2adfedf1f9b52d738e3cf2cb626eb9e44439a9dea2715fea501ced0
7
- data.tar.gz: 7df4726bca1c2d10aa9037d83da3a7d15684d39d429db8f5bda5b25b722edbe4c3d41538d58f96e1874a5acd5e33a3ccc6ba0437ca3b9373cdde35da63b8dd23
6
+ metadata.gz: 10af848ac5cea8769630f6bbeab00756f85ba5dd27e17eedaa9f5a026c20c5d027ae60523ec42fa7e7c4a9d737995ee4b828a17a447ebf23fe9dc807760cf740
7
+ data.tar.gz: 4427826729ef4ab92903e6161373b6eaee44b3601a236ce2278d1bda8d3f2351c06cffdd503d246ac965f5f75033dd058ef8622e5535d26ee7e75630c5ccccb8
data/ChangeLog CHANGED
@@ -1,34 +1,56 @@
1
- CHANGELOG
1
+ # CHANGELOG
2
2
 
3
- ## [1.21.0](https://github.com/algolia/algoliasearch-rails/releases/tag/1.21.0) (2019-02-12)
3
+ ## [1.22.0](https://github.com/algolia/algoliasearch-rails/releases/tag/1.22.0) (2019-03-21)
4
+
5
+ 🚨 The documentation for our Rails integration was refreshed 🎉
6
+ https://www.algolia.com/doc/framework-integration/rails/getting-started/setup/
4
7
 
5
8
  **Added**
6
9
 
7
- * Add `AlgoliaSearch::IndexSettings::DEFAULT_BATCH_SIZE` constant - PR [#319](https://github.com/algolia/algoliasearch-rails/pull/319)
10
+ * Introduce `algolia_dirty?` on models to decide if a model should be reindex.
8
11
 
9
- * Support ActiveModel Serializer 🎉 - PR [#266](https://github.com/algolia/algoliasearch-rails/pull/266)
12
+ This feature already exists via _changed? methods but might requires to implements many
13
+ methods if you have multiple dynamic attributes. Dynamic attributes are attributes not mapping
14
+ to a DB column. This feature allows you to group avoid all the _changed? method calls and
15
+ group all the logic inside one unique method.
16
+
17
+ **Fixed**
10
18
 
11
- ```ruby
12
- class SerializedObject < ActiveRecord::Base
13
- include AlgoliaSearch
19
+ * Fix _changed? method call for Rails 5.2+ with dynamic attribute - PR [#338](https://github.com/algolia/algoliasearch-rails/pull/338)
14
20
 
15
- algoliasearch do
21
+ Related issue: https://github.com/algolia/algoliasearch-rails/issues/140
22
+ Documentation: https://www.algolia.com/doc/framework-integration/rails/indexing/indexing/#automatic-updates
16
23
 
17
- use_serializer SerializedObjectSerializer
18
24
 
19
- tags do
20
- ['tag1', 'tag2']
21
- end
25
+ ## [1.21.0](https://github.com/algolia/algoliasearch-rails/releases/tag/1.21.0) (2019-02-12)
26
+
27
+ **Added**
22
28
 
29
+ * Add `AlgoliaSearch::IndexSettings::DEFAULT_BATCH_SIZE` constant - PR [#319](https://github.com/algolia/algoliasearch-rails/pull/319)
30
+
31
+ * Support ActiveModel Serializer 🎉 - PR [#266](https://github.com/algolia/algoliasearch-rails/pull/266)
32
+
33
+ ```ruby
34
+ class SerializedObject < ActiveRecord::Base
35
+ include AlgoliaSearch
36
+
37
+ algoliasearch do
38
+
39
+ use_serializer SerializedObjectSerializer
40
+
41
+ tags do
42
+ ['tag1', 'tag2']
23
43
  end
44
+
24
45
  end
25
- ```
46
+ end
47
+ ```
26
48
 
27
49
  **Fixed**
28
50
 
29
- * Add support for all new recent engine settings - PR [#327](https://github.com/algolia/algoliasearch-rails/pull/327)
51
+ * Add support for all new recent engine settings - PR [#327](https://github.com/algolia/algoliasearch-rails/pull/327)
30
52
 
31
- Algolia regularly introduce new settings, all of them are supported by this gem.
53
+ Algolia regularly introduce new settings, all of them are supported by this gem.
32
54
 
33
55
  2018-12-07 1.20.6
34
56
 
@@ -203,7 +203,7 @@ DEPENDENCIES
203
203
  redgreen
204
204
  rspec (>= 2.5.0, < 3.0)
205
205
  sequel (>= 4.0)
206
- sqlite3
206
+ sqlite3 (< 1.4.0)
207
207
  travis
208
208
  will_paginate (>= 2.3.15)
209
209
 
@@ -739,19 +739,21 @@ module AlgoliaSearch
739
739
  end
740
740
 
741
741
  def algolia_must_reindex?(object)
742
+ # use +algolia_dirty?+ method if implemented
743
+ return object.send(:algolia_dirty?) if (object.respond_to?(:algolia_dirty?))
744
+ # Loop over each index to see if a attribute used in records has changed
742
745
  algolia_configurations.each do |options, settings|
743
746
  next if options[:slave] || options[:replica]
744
747
  return true if algolia_object_id_changed?(object, options)
745
748
  settings.get_attribute_names(object).each do |k|
746
- changed_method = attribute_changed_method(k)
747
- return true if !object.respond_to?(changed_method) || object.send(changed_method)
749
+ return true if algolia_attribute_changed?(object, k)
750
+ # return true if !object.respond_to?(changed_method) || object.send(changed_method)
748
751
  end
749
752
  [options[:if], options[:unless]].each do |condition|
750
753
  case condition
751
754
  when nil
752
755
  when String, Symbol
753
- changed_method = attribute_changed_method(condition)
754
- return true if !object.respond_to?(changed_method) || object.send(changed_method)
756
+ return true if algolia_attribute_changed?(object, condition)
755
757
  else
756
758
  # if the :if, :unless condition is a anything else,
757
759
  # we have no idea whether we should reindex or not
@@ -760,6 +762,7 @@ module AlgoliaSearch
760
762
  end
761
763
  end
762
764
  end
765
+ # By default, we don't reindex
763
766
  return false
764
767
  end
765
768
 
@@ -825,8 +828,8 @@ module AlgoliaSearch
825
828
  end
826
829
 
827
830
  def algolia_object_id_changed?(o, options = nil)
828
- m = attribute_changed_method(algolia_object_id_method(options))
829
- o.respond_to?(m) ? o.send(m) : false
831
+ changed = algolia_attribute_changed?(o, algolia_object_id_method(options))
832
+ changed.nil? ? false : changed
830
833
  end
831
834
 
832
835
  def algoliasearch_settings_changed?(prev, current)
@@ -920,13 +923,48 @@ module AlgoliaSearch
920
923
  end
921
924
  end
922
925
 
923
- def attribute_changed_method(attr)
924
- if defined?(::ActiveRecord) && ActiveRecord::VERSION::MAJOR >= 5 && ActiveRecord::VERSION::MINOR >= 1 ||
925
- (defined?(::ActiveRecord) && ActiveRecord::VERSION::MAJOR > 5)
926
- "will_save_change_to_#{attr}?"
927
- else
928
- "#{attr}_changed?"
926
+ def algolia_attribute_changed?(object, attr_name)
927
+ # if one of two method is implemented, we return its result
928
+ # true/false means whether it has changed or not
929
+ # +#{attr_name}_changed?+ always defined for automatic attributes but deprecated after Rails 5.2
930
+ # +will_save_change_to_#{attr_name}?+ should be use instead for Rails 5.2+, also defined for automatic attributes.
931
+ # If none of the method are defined, it's a dynamic attribute
932
+
933
+ method_name = "#{attr_name}_changed?"
934
+ if object.respond_to?(method_name)
935
+ # If +#{attr_name}_changed?+ respond we want to see if the method is user defined or if it's automatically
936
+ # defined by Rails.
937
+ # If it's user-defined, we call it.
938
+ # If it's automatic we check ActiveRecord version to see if this method is deprecated
939
+ # and try to call +will_save_change_to_#{attr_name}?+ instead.
940
+ # See: https://github.com/algolia/algoliasearch-rails/pull/338
941
+ # This feature is not compatible with Ruby 1.8
942
+ # In this case, we always call #{attr_name}_changed?
943
+ if Object.const_defined?(:RUBY_VERSION) && RUBY_VERSION.to_f < 1.9
944
+ return object.send(method_name)
945
+ end
946
+ unless automatic_changed_method?(object, method_name) && automatic_changed_method_deprecated?
947
+ return object.send(method_name)
948
+ end
929
949
  end
950
+
951
+ if object.respond_to?("will_save_change_to_#{attr_name}?")
952
+ return object.send("will_save_change_to_#{attr_name}?")
953
+ end
954
+
955
+ # Nil means we don't know if the attribute has changed
956
+ nil
957
+ end
958
+
959
+ def automatic_changed_method?(object, method_name)
960
+ raise ArgumentError.new("Method #{method_name} doesn't exist on #{object.class.name}") unless object.respond_to?(method_name)
961
+ file = object.method(method_name).source_location[0]
962
+ file.end_with?("active_model/attribute_methods.rb")
963
+ end
964
+
965
+ def automatic_changed_method_deprecated?
966
+ (defined?(::ActiveRecord) && ActiveRecord::VERSION::MAJOR >= 5 && ActiveRecord::VERSION::MINOR >= 1) ||
967
+ (defined?(::ActiveRecord) && ActiveRecord::VERSION::MAJOR > 5)
930
968
  end
931
969
  end
932
970
 
@@ -1,3 +1,3 @@
1
1
  module AlgoliaSearch
2
- VERSION = '1.21.0'
2
+ VERSION = '1.22.0'
3
3
  end
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.21.0
4
+ version: 1.22.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Algolia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-13 00:00:00.000000000 Z
11
+ date: 2019-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json