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.
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{is_paranoid_ext}
3
- s.version = "0.0.3"
3
+ s.version = "0.0.4"
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"]
@@ -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
- through_id = options[:through]
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 through_id if through_id
27
- options.merge!(:conditions => merged_paranoid_conditions) unless @paranoid_conditions.nil?
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
- @paranoid_conditions ||= []
35
- @paranoid_conditions << "#{association_klass.quoted_table_name}.#{association_klass.destroyed_field} IS ?"
36
- @paranoid_values ||= []
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)
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 3
9
- version: 0.0.3
8
+ - 4
9
+ version: 0.0.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Alex Neill