activemodel-associations 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/Rakefile +2 -2
- data/activemodel-associations.gemspec +3 -0
- data/gemfiles/activerecord-41.gemfile +3 -3
- data/gemfiles/activerecord-412.gemfile +7 -0
- data/gemfiles/activerecord-42.gemfile +8 -0
- data/lib/active_model/associations/active_record_reflection.rb +12 -3
- data/lib/active_model/associations/override_methods.rb +4 -0
- data/lib/active_model/associations/version.rb +1 -1
- data/lib/active_record/associations/has_many_for_active_model_association.rb +9 -0
- data/spec/lib/active_model/association_spec.rb +2 -2
- data/spec/spec_helper.rb +3 -0
- metadata +46 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 017e2f0b46163726880d4703ec352add2b9b9b05
|
4
|
+
data.tar.gz: b5afa0902988cd9cae5656126178bc720d2fc12d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57be72dc156c9913ed2de207b866385eb32391263b5d81f7695a431c9c54fe701bab046d2f608111be3d6fa75facf14d1744eca905231d719c1717338773c85c
|
7
|
+
data.tar.gz: bbbed9c4019bf1a309c4670ff54802dae9e04db77795882b171f59a4b2db1d5af10e2859eb947f44bbd03ca5ccb3185a158aca09da7c53dcd52f648184f4a0b4
|
data/.travis.yml
CHANGED
data/Rakefile
CHANGED
@@ -6,7 +6,7 @@ RSpec::Core::RakeTask.new(:spec)
|
|
6
6
|
task :default => :spec
|
7
7
|
|
8
8
|
namespace :spec do
|
9
|
-
%w(activerecord-40 activerecord-41).each do |gemfile|
|
9
|
+
%w(activerecord-40 activerecord-41 activerecord-412 activerecord-42).each do |gemfile|
|
10
10
|
desc "Run Tests by #{gemfile}.gemfile"
|
11
11
|
task gemfile do
|
12
12
|
sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle install --path .bundle"
|
@@ -16,7 +16,7 @@ namespace :spec do
|
|
16
16
|
|
17
17
|
desc "Run All Tests"
|
18
18
|
task :all do
|
19
|
-
%w(activerecord-40 activerecord-41).each do |gemfile|
|
19
|
+
%w(activerecord-40 activerecord-41 activerecord-412 activerecord-42).each do |gemfile|
|
20
20
|
Rake::Task["spec:#{gemfile}"].invoke
|
21
21
|
end
|
22
22
|
end
|
@@ -29,4 +29,7 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.add_development_dependency "sqlite3"
|
30
30
|
spec.add_development_dependency "database_cleaner"
|
31
31
|
spec.add_development_dependency "coveralls"
|
32
|
+
spec.add_development_dependency "byebug"
|
33
|
+
spec.add_development_dependency "pry"
|
34
|
+
spec.add_development_dependency "pry-byebug"
|
32
35
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
source "https://rubygems.org"
|
2
2
|
|
3
|
-
gem "activerecord", "~> 4.1.0"
|
4
|
-
gem "activemodel", "~> 4.1.0"
|
5
|
-
gem "activesupport", "~> 4.1.0"
|
3
|
+
gem "activerecord", "~> 4.1.0", "<= 4.1.1"
|
4
|
+
gem "activemodel", "~> 4.1.0", "<= 4.1.1"
|
5
|
+
gem "activesupport", "~> 4.1.0", "<= 4.1.1"
|
6
6
|
|
7
7
|
gemspec :path => "../"
|
@@ -3,8 +3,13 @@ module ActiveModel::Associations
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
included do
|
6
|
-
|
7
|
-
|
6
|
+
if ActiveRecord.version.to_s >= "4.1.2"
|
7
|
+
class_attribute :_reflections
|
8
|
+
self._reflections = ActiveSupport::HashWithIndifferentAccess.new
|
9
|
+
else
|
10
|
+
class_attribute :reflections
|
11
|
+
self.reflections = {}
|
12
|
+
end
|
8
13
|
end
|
9
14
|
|
10
15
|
module ClassMethods
|
@@ -22,7 +27,11 @@ module ActiveModel::Associations
|
|
22
27
|
end
|
23
28
|
|
24
29
|
def reflect_on_association(association)
|
25
|
-
|
30
|
+
if ActiveRecord.version.to_s >= "4.1.2"
|
31
|
+
_reflections[association.to_s]
|
32
|
+
else
|
33
|
+
reflections[association]
|
34
|
+
end
|
26
35
|
end
|
27
36
|
end
|
28
37
|
end
|
@@ -50,5 +50,14 @@ module ActiveRecord::Associations
|
|
50
50
|
|
51
51
|
target
|
52
52
|
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def get_records
|
57
|
+
return scope.to_a if reflection.scope_chain.any?(&:any?)
|
58
|
+
|
59
|
+
target_ids = reflection.options[:target_ids]
|
60
|
+
klass.where(id: owner[target_ids]).to_a
|
61
|
+
end
|
53
62
|
end
|
54
63
|
end
|
@@ -53,7 +53,7 @@ describe ActiveModel::Associations do
|
|
53
53
|
end
|
54
54
|
|
55
55
|
it "can validate" do
|
56
|
-
expect(comment.valid?).to
|
56
|
+
expect(comment.valid?).to be_truthy
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
@@ -180,7 +180,7 @@ describe ActiveModel::Associations do
|
|
180
180
|
end
|
181
181
|
|
182
182
|
it "can validate" do
|
183
|
-
expect(group.valid?).to
|
183
|
+
expect(group.valid?).to be_truthy
|
184
184
|
end
|
185
185
|
end
|
186
186
|
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activemodel-associations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- joker1007
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -150,6 +150,48 @@ dependencies:
|
|
150
150
|
- - ">="
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: byebug
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: pry
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: pry-byebug
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - ">="
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
153
195
|
description: ActiveRecord Association Helper for PORO (Plain Old Ruby Object)
|
154
196
|
email:
|
155
197
|
- kakyoin.hierophant@gmail.com
|
@@ -167,6 +209,8 @@ files:
|
|
167
209
|
- activemodel-associations.gemspec
|
168
210
|
- gemfiles/activerecord-40.gemfile
|
169
211
|
- gemfiles/activerecord-41.gemfile
|
212
|
+
- gemfiles/activerecord-412.gemfile
|
213
|
+
- gemfiles/activerecord-42.gemfile
|
170
214
|
- lib/active_model/associations.rb
|
171
215
|
- lib/active_model/associations/active_record_reflection.rb
|
172
216
|
- lib/active_model/associations/association_scope_extension.rb
|