acts_as 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -7
- data/lib/acts_as/version.rb +1 -1
- data/lib/acts_as.rb +5 -3
- data/spec/acts_as_spec.rb +4 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6e9ee1715570c9e8a97e3212b76ad5a66fb65bb
|
4
|
+
data.tar.gz: 38bc6aa48979d056cf86ec03903d741d1200eabe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ec4605e84506cf2765025d68812542c37ae548400f6176e78b3d313abe97acbe71eada88542baafdb4d6346c4d0156e4483c7d653b29b62a1060ebe0b4cfb23
|
7
|
+
data.tar.gz: 6c055ebd63e0abc5a1c00aa472333cfa88b8a3d924bcc574c9b9a08aef5353ef655d7a951188d1955644b4f099678dfc429181298cdc7a3c2113ee47e72b7134
|
data/README.md
CHANGED
@@ -82,16 +82,15 @@ Now a whole slew of methods related to ActiveRecord attributes are available for
|
|
82
82
|
# Any method you want
|
83
83
|
rebel.delegate_at_will #=> '10'
|
84
84
|
|
85
|
+
## Automagical joins through .where Hash syntax
|
85
86
|
|
86
|
-
|
87
|
+
Just get to what you want
|
87
88
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
Can we make this work for ruby-sql autojoins? Is that even a good idea?
|
89
|
+
```ruby
|
90
|
+
Rebel.where(strength: 10) #=> the same as Rebel.joins(:clan).where(clan: {strength: 10)
|
91
|
+
```
|
93
92
|
|
94
|
-
|
93
|
+
One major caveat, it only works for first-level attributes at the moment. (see pending spec)
|
95
94
|
|
96
95
|
## Contributing
|
97
96
|
|
data/lib/acts_as/version.rb
CHANGED
data/lib/acts_as.rb
CHANGED
@@ -56,9 +56,11 @@ module ActsAs
|
|
56
56
|
relation = super
|
57
57
|
#TODO support nested attribute joins like Guns.where(rebels: {strength: 10}))
|
58
58
|
# for now, only first level joins will happen automagically
|
59
|
-
|
60
|
-
|
61
|
-
|
59
|
+
if opts.is_a? Hash
|
60
|
+
detected_associations = opts.keys.map {|attr| acts_as_fields_match(attr) }
|
61
|
+
.reject {|attr| attr.nil?}
|
62
|
+
return relation.joins(detected_associations) if detected_associations.any?
|
63
|
+
end
|
62
64
|
relation
|
63
65
|
end
|
64
66
|
|
data/spec/acts_as_spec.rb
CHANGED
@@ -104,9 +104,12 @@ describe ActsAs do
|
|
104
104
|
end
|
105
105
|
|
106
106
|
describe 'automagic .where hash syntax helpers' do
|
107
|
-
it 'should auto-expand acted attributes' do
|
107
|
+
it 'should auto-expand acted hash attributes' do
|
108
108
|
Rebel.where(strength: rebel.strength).should include(rebel)
|
109
109
|
Rebel.where(strength: rebel.strength, name: 'Jimbo').should_not include(rebel)
|
110
|
+
expect {
|
111
|
+
Rebel.where('strength = ?', 12).any?
|
112
|
+
}.to raise_error(ActiveRecord::StatementInvalid)
|
110
113
|
end
|
111
114
|
|
112
115
|
it 'should auto-expand acted attribuets that are nested as well' do
|