Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix specs / remove AR 1 support

  • Loading branch information...
commit 1c686acdee1ac161c29ff7a76452a16b1e3793ea 1 parent 54eda56
@grosser authored
View
25 lib/search_do/dirty_tracking.rb
@@ -1,15 +1,20 @@
-require 'search_do/dirty_tracking/self_made'
-require 'search_do/dirty_tracking/bridge'
-
module SearchDo
module DirtyTracking
- def self.included(base)
- mod = if defined?(ActiveModel::Dirty) && base.included_modules.include?(ActiveModel::Dirty)
- DirtyTracking::Bridge
- else
- DirtyTracking::SelfMade
- end
- base.send(:include, mod)
+ def need_update_index?(attr_name = nil)
+ return false unless changed?
+ cs = changed_attributes.keys
+ if attr_name
+ cs.include?(attr_name)
+ else
+ search_indexer.observing_fields.any?{|t| cs.include?(t) }
+ end
+ end
+
+ private
+
+ def clear_changed_attributes
+ changed_attributes.clear
end
end
end
+
View
22 lib/search_do/dirty_tracking/bridge.rb
@@ -1,22 +0,0 @@
-module SearchDo
- module DirtyTracking
- module Bridge
-
- def need_update_index?(attr_name = nil)
- return false unless changed?
- cs = changed_attributes.keys
- if attr_name
- cs.include?(attr_name)
- else
- search_indexer.observing_fields.any?{|t| cs.include?(t) }
- end
- end
-
- private
- def clear_changed_attributes
- changed_attributes.clear
- end
- end
- end
-end
-
View
36 lib/search_do/dirty_tracking/self_made.rb
@@ -1,36 +0,0 @@
-
-module SearchDo
- module DirtyTracking
- module SelfMade
- def self.included(base)
- base.class_eval do
- attr_accessor :changed_attributes
-
- search_indexer.observing_fields.each do |attr_name|
- define_method("#{attr_name}=") do |value|
- write_changed_attribute attr_name, value
- end
- end
- end
- end
-
- # If called with no parameters, gets whether the current model has changed and needs to updated in the index.
- # If called with a single parameter, gets whether the parameter has changed.
- def need_update_index?(attr_name = nil)
- changed_attributes and (attr_name.nil? ?
- (not changed_attributes.length.zero?) : (changed_attributes.include?(attr_name.to_s)) )
- end
-
- private
- def clear_changed_attributes #:nodoc:
- self.changed_attributes = []
- end
-
- def write_changed_attribute(attr_name, attr_value) #:nodoc:
- (self.changed_attributes ||= []) << attr_name.to_s unless self.need_update_index?(attr_name) or self.send(attr_name) == attr_value
- write_attribute(attr_name.to_s, attr_value)
- end
- end
- end
-end
-
Please sign in to comment.
Something went wrong with that request. Please try again.