activerecord-polymorph 0.1.0 → 0.1.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.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/README.md +2 -2
- data/activerecord-polymorph.gemspec +3 -0
- data/lib/polymorph/methods.rb +2 -2
- data/lib/polymorph/relation.rb +1 -1
- data/lib/polymorph/version.rb +1 -1
- metadata +43 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d1b99dbcba39839072dfd1f95466e9a9aa8249a
|
4
|
+
data.tar.gz: ba0a4138bda24d8f5dc2577390fa4bd27b35ab62
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23c12a901d994fa3c6cb58ad447db3cda94d8fa5471270fe9d76e93e72fb2971b9fb5202a0ffa34a3756ebc7ce812284838435fb130978ab785e04b314e0df2f
|
7
|
+
data.tar.gz: bbfec582d55ab7144b18b0e3ba171d6476c66378512d13bf06ee1fcdb0de00c3af587f6515cf65d1e296ca22a8fb5d4f019c5d4ca579b4458623558140f14cee
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -89,13 +89,13 @@ polymorph :participants, through: :comments, source_types: [:users, :robots], fi
|
|
89
89
|
If we want to call these 'participants', but our database columns are already set to 'commenter_id' and 'commenter_type', we can invoke the `source_column` method:
|
90
90
|
|
91
91
|
```ruby
|
92
|
-
polymorph :
|
92
|
+
polymorph :participants, through: :comments, source_types: [:users, :robots], source_column: :commenter
|
93
93
|
```
|
94
94
|
|
95
95
|
If the ruby class cannot be inferred by the 'through' option, we can point it to the right place with `through_class`:
|
96
96
|
|
97
97
|
```ruby
|
98
|
-
polymorph :
|
98
|
+
polymorph :participants, through: :comments, source_types: [:users, :robots], through_class: Comments::Base
|
99
99
|
```
|
100
100
|
|
101
101
|
NB that this relation has somewhat limited support for further querying! Currently, we support count, pluck, and simple where clauses on common keys:
|
@@ -23,4 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.12"
|
24
24
|
spec.add_development_dependency "rake", "~> 10.0"
|
25
25
|
spec.add_development_dependency "minitest", "~> 5.0"
|
26
|
+
spec.add_development_dependency "temping", "~> 3.7"
|
27
|
+
spec.add_development_dependency "sqlite3", "~> 1.3"
|
28
|
+
spec.add_development_dependency "byebug", "~> 9.0"
|
26
29
|
end
|
data/lib/polymorph/methods.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require "polymorph/relation"
|
2
|
-
require "byebug"
|
3
2
|
|
4
3
|
module Polymorph
|
5
4
|
module Methods
|
@@ -17,7 +16,7 @@ module Polymorph
|
|
17
16
|
source_types.map { |t| "#{t}.*" },
|
18
17
|
source_types.product(fields).map { |a| "#{a[0]}.#{a[1]} AS #{a[0].to_s.singularize}_#{a[1]}" },
|
19
18
|
"#{through}.#{source_column}_type",
|
20
|
-
"'
|
19
|
+
"'is_polymorph' as polymorph_query"
|
21
20
|
].flatten.join(', '))
|
22
21
|
|
23
22
|
source_types.each do |type|
|
@@ -33,6 +32,7 @@ module Polymorph
|
|
33
32
|
|
34
33
|
through_class.define_singleton_method :instantiate, ->(attrs, column_types) {
|
35
34
|
super(attrs, column_types).tap do |record|
|
35
|
+
break unless attrs['polymorph_query'].present?
|
36
36
|
transfer_fields = fields.map { |field| [field, attrs["#{attrs[source_type].downcase}_#{field}"]] }.to_h
|
37
37
|
record.assign_attributes(transfer_fields)
|
38
38
|
end
|
data/lib/polymorph/relation.rb
CHANGED
data/lib/polymorph/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-polymorph
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Kiesel
|
@@ -66,6 +66,48 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '5.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: temping
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.7'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.7'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: sqlite3
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.3'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.3'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: byebug
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '9.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '9.0'
|
69
111
|
description:
|
70
112
|
email:
|
71
113
|
- james.kiesel@gmail.com
|