unscoped_associations 0.3.0 → 0.3.1
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/README.md +3 -3
- data/VERSION +1 -1
- data/lib/unscoped_associations.rb +9 -22
- data/unscoped_associations.gemspec +2 -2
- metadata +3 -3
data/README.md
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
Unscoped Associations
|
2
2
|
=====================
|
3
|
-
It may be that you've ever needed to skip default_scope pulling objects via associations (for some strange reasons).
|
3
|
+
It may be that you've ever needed to skip `default_scope` pulling objects via associations (for some strange reasons).
|
4
4
|
Do it easily with this lib. Supported associations:
|
5
5
|
* `:belongs_to`
|
6
6
|
* `:has_one`
|
7
7
|
* `:has_many`
|
8
8
|
|
9
9
|
## Installation
|
10
|
-
Add this line to
|
10
|
+
Add this line to your Gemfile:
|
11
11
|
|
12
12
|
```ruby
|
13
13
|
gem 'unscoped_associations'
|
@@ -50,7 +50,7 @@ end
|
|
50
50
|
```
|
51
51
|
|
52
52
|
## Status
|
53
|
-
Tested on Rails 3.
|
53
|
+
Tested on Rails 3.x series. In Rails 4 you are able to customize data retrieving via a scope block, so you can skip `default_scope` using a block.
|
54
54
|
|
55
55
|
|
56
56
|
## Contributing
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.1
|
@@ -12,48 +12,35 @@ module UnscopedAssociations
|
|
12
12
|
module ClassMethods
|
13
13
|
|
14
14
|
def belongs_to_with_unscoped(name, options = {})
|
15
|
-
if
|
16
|
-
|
15
|
+
if options.delete(:unscoped)
|
16
|
+
add_unscoped_association(name)
|
17
17
|
end
|
18
18
|
belongs_to_without_unscoped(name, options)
|
19
19
|
end
|
20
20
|
|
21
21
|
def has_many_with_unscoped(name, options = {})
|
22
|
-
if
|
23
|
-
|
22
|
+
if options.delete(:unscoped)
|
23
|
+
add_unscoped_association(name)
|
24
24
|
end
|
25
25
|
has_many_without_unscoped(name, options)
|
26
26
|
end
|
27
27
|
|
28
28
|
def has_one_with_unscoped(name, options = {})
|
29
|
-
if
|
30
|
-
|
29
|
+
if options.delete(:unscoped)
|
30
|
+
add_unscoped_association(name)
|
31
31
|
end
|
32
32
|
has_one_without_unscoped(name, options)
|
33
33
|
end
|
34
34
|
|
35
35
|
private
|
36
36
|
|
37
|
-
def
|
38
|
-
define_unscoped_association(association_name, options)
|
39
|
-
end
|
40
|
-
|
41
|
-
def add_unscoped_has_many(association_name, options)
|
42
|
-
define_unscoped_association(association_name, options)
|
43
|
-
end
|
44
|
-
|
45
|
-
def add_unscoped_has_one(association_name, options)
|
46
|
-
define_unscoped_association(association_name, options)
|
47
|
-
end
|
48
|
-
|
49
|
-
def define_unscoped_association(association_name, options)
|
37
|
+
def add_unscoped_association(association_name)
|
50
38
|
define_method(association_name) do
|
51
|
-
self.class.reflect_on_association(association_name).klass.unscoped
|
39
|
+
self.class.reflect_on_association(association_name).klass.unscoped do
|
52
40
|
super(association_name)
|
53
|
-
|
41
|
+
end
|
54
42
|
end
|
55
43
|
end
|
56
|
-
|
57
44
|
end
|
58
45
|
end
|
59
46
|
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "unscoped_associations"
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["markets"]
|
12
|
-
s.date = "2013-
|
12
|
+
s.date = "2013-09-07"
|
13
13
|
s.description = "Skip default_scope in your associations"
|
14
14
|
s.email = "srmarc.ai@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unscoped_associations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-09-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -103,7 +103,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
103
103
|
version: '0'
|
104
104
|
segments:
|
105
105
|
- 0
|
106
|
-
hash:
|
106
|
+
hash: 596675425
|
107
107
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
108
|
none: false
|
109
109
|
requirements:
|