is_paranoid_ext 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/is_paranoid_ext.gemspec +1 -1
- data/lib/is_paranoid_ext.rb +10 -14
- metadata +2 -2
data/is_paranoid_ext.gemspec
CHANGED
data/lib/is_paranoid_ext.rb
CHANGED
@@ -16,33 +16,29 @@ module IsParanoidExt
|
|
16
16
|
merge_paranoid_options!(association_id, options)
|
17
17
|
has_one association_id, options, &extension
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
private
|
21
21
|
|
22
22
|
def merge_paranoid_options!(association_id, options)
|
23
|
-
|
24
|
-
@paranoid_conditions, @paranoid_values = nil, nil
|
23
|
+
@paranoid_conditions = []
|
25
24
|
apply_paranoid_conditions_for(options[:class_name] || association_id)
|
26
|
-
apply_paranoid_conditions_for
|
27
|
-
|
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
|
28
30
|
end
|
29
31
|
|
30
32
|
def apply_paranoid_conditions_for(association_id)
|
31
33
|
reflection = reflections[association_id.to_sym]
|
32
34
|
association_klass = ( reflection.try(:klass) || association_id.to_s.classify.constantize )
|
33
35
|
if association_klass && association_klass.respond_to?(:restore)
|
34
|
-
|
35
|
-
|
36
|
-
@
|
37
|
-
@paranoid_values << association_klass.field_not_destroyed
|
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)
|
38
39
|
end
|
39
40
|
end
|
40
41
|
|
41
|
-
def merged_paranoid_conditions
|
42
|
-
@merged_paranoid_conditions ||= if @paranoid_conditions.any? && @paranoid_values.any?
|
43
|
-
[@paranoid_conditions.map{|c|"(#{c})"}.join(' AND ')] + @paranoid_values
|
44
|
-
else nil end
|
45
|
-
end
|
46
42
|
end
|
47
43
|
|
48
44
|
ActiveRecord::Base.send(:extend, IsParanoidExt)
|