paranoid_create 0.0.10 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +5 -1
- data/lib/paranoid/base.rb +2 -2
- data/lib/paranoid/join_association.rb +10 -11
- data/lib/paranoid/paranoid_methods.rb +1 -1
- data/lib/paranoid/version.rb +1 -1
- data/paranoid.gemspec +4 -3
- data/spec/paranoid_spec.rb +4 -0
- metadata +37 -23
data/.gitignore
CHANGED
data/lib/paranoid/base.rb
CHANGED
@@ -9,7 +9,7 @@ module Paranoid
|
|
9
9
|
# end
|
10
10
|
#
|
11
11
|
# Item < ActiveRecord::Base
|
12
|
-
# paranoid :field => [:available,
|
12
|
+
# paranoid :field => [:available, false, true]
|
13
13
|
# end
|
14
14
|
#
|
15
15
|
# === Options
|
@@ -36,7 +36,7 @@ module Paranoid
|
|
36
36
|
@paranoid = true
|
37
37
|
|
38
38
|
opts[:field] ||= [:deleted_at, Proc.new{Time.now.utc}, nil]
|
39
|
-
|
39
|
+
class_attribute :destroyed_field, :field_destroyed, :field_not_destroyed
|
40
40
|
if opts[:field].is_a?(Array)
|
41
41
|
self.destroyed_field, self.field_destroyed, self.field_not_destroyed = opts[:field]
|
42
42
|
else
|
@@ -3,22 +3,21 @@ module Paranoid
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
included do
|
6
|
-
alias_method_chain :
|
6
|
+
alias_method_chain :initialize, :paranoid
|
7
7
|
end
|
8
8
|
|
9
|
-
#
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
pb = ActiveRecord::PredicateBuilder.new(arel_engine)
|
17
|
-
result.concat(pb.build_from_hash(reflection.klass.paranoid_condition, aliased_table))
|
9
|
+
# Add conditions for eager loading
|
10
|
+
def initialize_with_paranoid(reflection, join_dependency, parent = nil)
|
11
|
+
result = initialize_without_paranoid(reflection, join_dependency, parent)
|
12
|
+
chain.reverse.each_with_index do |reflection, i|
|
13
|
+
if reflection.klass.paranoid?
|
14
|
+
conditions[i] << reflection.klass.paranoid_condition
|
15
|
+
end
|
18
16
|
end
|
19
17
|
result
|
20
18
|
end
|
19
|
+
|
21
20
|
end
|
22
21
|
end
|
23
22
|
|
24
|
-
ActiveRecord::Associations::
|
23
|
+
ActiveRecord::Associations::JoinDependency::JoinAssociation.class_eval { include Paranoid::JoinAssociation }
|
@@ -44,7 +44,7 @@ module Paranoid
|
|
44
44
|
|
45
45
|
self.class.reflect_on_all_associations.each do |association|
|
46
46
|
if association.options[:dependent] == :destroy && association.klass.paranoid?
|
47
|
-
restore_related(association.klass, association.
|
47
|
+
restore_related(association.klass, association.foreign_key, association.options[:primary_key] || 'id', association.options) if association.macro.to_s =~ /^has/
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
data/lib/paranoid/version.rb
CHANGED
data/paranoid.gemspec
CHANGED
@@ -20,7 +20,8 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
21
|
s.require_paths = ['lib']
|
22
22
|
|
23
|
-
s.add_development_dependency('rspec', ['>= 2.
|
24
|
-
s.add_development_dependency('sqlite3
|
25
|
-
s.add_development_dependency('activerecord', ['>= 3.0
|
23
|
+
s.add_development_dependency('rspec', ['>= 2.6.0'])
|
24
|
+
s.add_development_dependency('sqlite3', ['>= 1.3.4'])
|
25
|
+
s.add_development_dependency('activerecord', ['>= 3.1.0'])
|
26
|
+
s.add_development_dependency('rake', ['0.9.2'])
|
26
27
|
end
|
data/spec/paranoid_spec.rb
CHANGED
@@ -219,6 +219,10 @@ describe Paranoid do
|
|
219
219
|
@r2d2.dents.with_destroyed.to_a.should == @dents
|
220
220
|
end
|
221
221
|
|
222
|
+
it 'should show all dents with destroyed in a "where chain"' do
|
223
|
+
@r2d2.dents.where("description LIKE '%hit%'").with_destroyed.to_a.should == [@dents[0], @dents[2]]
|
224
|
+
end
|
225
|
+
|
222
226
|
it 'should show only soft deleted with destroyed_only' do
|
223
227
|
@r2d2.dents.with_destroyed_only.to_a.should == [@dents[2]]
|
224
228
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paranoid_create
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 0.0.10
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Philipp Ullmann
|
@@ -15,57 +15,72 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
19
|
-
default_executable:
|
18
|
+
date: 2011-09-05 00:00:00 Z
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
22
|
-
name: rspec
|
23
21
|
prerelease: false
|
22
|
+
type: :development
|
24
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
24
|
none: false
|
26
25
|
requirements:
|
27
26
|
- - ">="
|
28
27
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
28
|
+
hash: 23
|
30
29
|
segments:
|
31
30
|
- 2
|
32
|
-
-
|
31
|
+
- 6
|
33
32
|
- 0
|
34
|
-
version: 2.
|
35
|
-
|
33
|
+
version: 2.6.0
|
34
|
+
name: rspec
|
36
35
|
version_requirements: *id001
|
37
36
|
- !ruby/object:Gem::Dependency
|
38
|
-
name: sqlite3-ruby
|
39
37
|
prerelease: false
|
38
|
+
type: :development
|
40
39
|
requirement: &id002 !ruby/object:Gem::Requirement
|
41
40
|
none: false
|
42
41
|
requirements:
|
43
42
|
- - ">="
|
44
43
|
- !ruby/object:Gem::Version
|
45
|
-
hash:
|
44
|
+
hash: 19
|
46
45
|
segments:
|
47
46
|
- 1
|
48
47
|
- 3
|
49
|
-
-
|
50
|
-
version: 1.3.
|
51
|
-
|
48
|
+
- 4
|
49
|
+
version: 1.3.4
|
50
|
+
name: sqlite3
|
52
51
|
version_requirements: *id002
|
53
52
|
- !ruby/object:Gem::Dependency
|
54
|
-
name: activerecord
|
55
53
|
prerelease: false
|
54
|
+
type: :development
|
56
55
|
requirement: &id003 !ruby/object:Gem::Requirement
|
57
56
|
none: false
|
58
57
|
requirements:
|
59
58
|
- - ">="
|
60
59
|
- !ruby/object:Gem::Version
|
61
|
-
hash:
|
60
|
+
hash: 3
|
62
61
|
segments:
|
63
62
|
- 3
|
63
|
+
- 1
|
64
64
|
- 0
|
65
|
-
|
66
|
-
|
67
|
-
type: :development
|
65
|
+
version: 3.1.0
|
66
|
+
name: activerecord
|
68
67
|
version_requirements: *id003
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
prerelease: false
|
70
|
+
type: :development
|
71
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - "="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
hash: 63
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
- 9
|
80
|
+
- 2
|
81
|
+
version: 0.9.2
|
82
|
+
name: rake
|
83
|
+
version_requirements: *id004
|
69
84
|
description:
|
70
85
|
email: philipp.ullmann@create.at
|
71
86
|
executables: []
|
@@ -95,7 +110,6 @@ files:
|
|
95
110
|
- spec/schema.rb
|
96
111
|
- spec/spec.opts
|
97
112
|
- spec/spec_helper.rb
|
98
|
-
has_rdoc: true
|
99
113
|
homepage: http://github.com/create-philipp-ullmann/paranoid/
|
100
114
|
licenses: []
|
101
115
|
|
@@ -125,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
139
|
requirements: []
|
126
140
|
|
127
141
|
rubyforge_project: paranoid_create
|
128
|
-
rubygems_version: 1.
|
142
|
+
rubygems_version: 1.8.8
|
129
143
|
signing_key:
|
130
144
|
specification_version: 3
|
131
145
|
summary: Enable soft delete of ActiveRecord records. Based off defunct ActsAsParanoid and IsParanoid
|