is_paranoid_ext 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{is_paranoid_ext}
3
- s.version = "0.0.4"
3
+ s.version = "0.0.5"
4
4
 
5
5
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
6
6
  s.authors = ["Alex Neill"]
@@ -1,44 +1,32 @@
1
1
  require 'activerecord'
2
2
 
3
3
  module IsParanoidExt
4
-
5
- def has_many_paranoid(association_id, options = {}, &extension)
6
- merge_paranoid_options!(association_id, options)
7
- has_many association_id, options, &extension
4
+
5
+ def preload_has_one_association(records, reflection, preload_options = {})
6
+ super(records, reflection, paranoid_preload_options(reflection, preload_options))
8
7
  end
9
-
10
- def has_and_belongs_to_many_paranoid(association_id, options = {}, &extension)
11
- merge_paranoid_options!(association_id, options)
12
- has_and_belongs_to_many association_id, options, &extension
8
+
9
+ def preload_has_many_association(records, reflection, preload_options = {})
10
+ super(records, reflection, paranoid_preload_options(reflection, preload_options))
13
11
  end
14
12
 
15
- def has_one_paranoid(association_id, options = {}, &extension)
16
- merge_paranoid_options!(association_id, options)
17
- has_one association_id, options, &extension
13
+ def preload_has_and_belongs_to_many_association(records, reflection, preload_options = {})
14
+ super(records, reflection, paranoid_preload_options(reflection, preload_options))
18
15
  end
19
16
 
20
17
  private
21
-
22
- def merge_paranoid_options!(association_id, options)
23
- @paranoid_conditions = []
24
- apply_paranoid_conditions_for(options[:class_name] || association_id)
25
- apply_paranoid_conditions_for options[:through] if options[:through]
26
- unless @paranoid_conditions.empty?
27
- options.merge!( :conditions => merge_conditions( @paranoid_conditions + [sanitize_sql(options.delete(:conditions) || [])] ) )
28
- @paranoid_conditions = []
29
- end
30
- end
31
-
32
- def apply_paranoid_conditions_for(association_id)
33
- reflection = reflections[association_id.to_sym]
34
- association_klass = ( reflection.try(:klass) || association_id.to_s.classify.constantize )
35
- if association_klass && association_klass.respond_to?(:restore)
36
- sql_array = ["#{association_klass.quoted_table_name}.#{association_klass.destroyed_field} IS ?"]
37
- sql_array << association_klass.field_not_destroyed
38
- @paranoid_conditions << sanitize_sql_array(sql_array)
18
+
19
+ def paranoid_preload_options(reflection, preload_options)
20
+ paranoid_preload_opts = preload_options.dup
21
+ if reflection.klass.respond_to?(:restore)
22
+ sql_array = ["#{reflection.klass.quoted_table_name}.#{reflection.klass.destroyed_field} IS ?"]
23
+ sql_array << reflection.klass.field_not_destroyed
24
+ preload_conditions = paranoid_preload_opts.delete(:conditions) || []
25
+ paranoid_preload_opts.merge(:conditions => merge_conditions(sql_array, preload_conditions))
39
26
  end
27
+ paranoid_preload_opts
40
28
  end
41
-
29
+
42
30
  end
43
31
 
44
32
  ActiveRecord::Base.send(:extend, IsParanoidExt)
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 4
9
- version: 0.0.4
8
+ - 5
9
+ version: 0.0.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Alex Neill