sequel_polymorphic 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +8 -1
- data/README.md +7 -2
- data/lib/sequel/plugins/polymorphic.rb +20 -2
- data/lib/sequel/plugins/polymorphic/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 27fb2188530df2e0fc2489a1494dfb76040507ac05184115fc904ed6a49bf066
|
4
|
+
data.tar.gz: 6854931f7f528a00b37038f9aa782b0ad59ea89444de21d46261cd4adf25d508
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9596ba84fde30fc984b770b0742fdc733d1b94608fd19a45851a33bb2babe79f1e5f7ef384cfe549bacc2d9f9c47467620fa94c88b697d4b7c3cd01d206ccf6e
|
7
|
+
data.tar.gz: 9dad034162d9396fe5015aa8c7dcc38ddf1a5e1cf81f798fd6372d7c49bbef70f0dbf5a708c9822feb33ec3d8e91efea96a9de9e3f4b5c46bf44415f64b2c916
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
# 0.5.0 (2018-10-23)
|
2
|
+
|
3
|
+
* **Feature**: *add `#where` functionality.*
|
4
|
+
|
5
|
+
See [#25](https://github.com/jackdempsey/sequel_polymorphic/pull/25).
|
6
|
+
Thanks to [@jnylen](https://github.com/jnylen).
|
7
|
+
|
1
8
|
# 0.4.0 (2017-10-25)
|
2
9
|
|
3
10
|
* **Enhancements**: *migrate to new Sequel's plugins tree schema.*
|
@@ -16,7 +23,7 @@
|
|
16
23
|
|
17
24
|
* **Fix**: *`one_to_one` association tries to add an adder, remover and clearer methods*.
|
18
25
|
|
19
|
-
It's not correct and
|
26
|
+
It's not correct and generates an error in Sequel 5.
|
20
27
|
|
21
28
|
See [#26](https://github.com/jackdempsey/sequel_polymorphic/pull/26).
|
22
29
|
Thanks to [@jnylen](https://github.com/jnylen).
|
data/README.md
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
# Sequel Polymorphic
|
2
2
|
|
3
|
-
A
|
3
|
+
A plugin for [Sequel](http://sequel.jeremyevans.net) that lets you easily create polymorphic associations.
|
4
4
|
|
5
|
-
|
5
|
+
Required:
|
6
|
+
|
7
|
+
* Sequel >= 4.0.0 and Ruby >= 1.8.7,
|
8
|
+
* or Sequel >= 5.0.0 and Ruby >= 1.9.2.
|
9
|
+
|
10
|
+
(Note: Ruby 1.8.7 option is not tested.)
|
6
11
|
|
7
12
|
## Usage examples
|
8
13
|
|
@@ -10,6 +10,26 @@ module Sequel
|
|
10
10
|
|
11
11
|
end
|
12
12
|
|
13
|
+
module DatasetMethods
|
14
|
+
def where(*cond, &block)
|
15
|
+
if cond.first.is_a? Hash
|
16
|
+
cond.first.clone.each do |key, value|
|
17
|
+
# Does it respnd to #pk ? Then it's a model
|
18
|
+
next unless value.respond_to?("pk")
|
19
|
+
next unless self.model.association_reflections.key?(key.to_sym)
|
20
|
+
next unless self.model.association_reflections[key.to_sym].key?(:polymorphic)
|
21
|
+
next unless self.model.association_reflections[key.to_sym][:polymorphic]
|
22
|
+
|
23
|
+
cond.first.delete(key)
|
24
|
+
cond.first["#{key}_id".to_sym] = value.pk
|
25
|
+
cond.first["#{key}_type".to_sym] = value.class.to_s
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
super
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
13
33
|
module ClassMethods
|
14
34
|
|
15
35
|
# Creates a many-to-one relationship.
|
@@ -157,5 +177,3 @@ module Sequel
|
|
157
177
|
end # Polymorphic
|
158
178
|
end # Plugins
|
159
179
|
end # Sequel
|
160
|
-
|
161
|
-
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequel_polymorphic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jack Dempsey
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2018-10-23 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: sequel
|
@@ -139,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
139
|
version: '0'
|
140
140
|
requirements: []
|
141
141
|
rubyforge_project:
|
142
|
-
rubygems_version: 2.
|
142
|
+
rubygems_version: 2.7.7
|
143
143
|
signing_key:
|
144
144
|
specification_version: 4
|
145
145
|
summary: A gem that provides Sequel::Models with polymorphic association capabilities
|