belongs_to_polymorphic 0.1.2 → 0.2.0
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/.reek.yml +127 -0
- data/.rspec +3 -0
- data/.rubocop.yml +86 -0
- data/CHANGELOG.md +36 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/CONTRIBUTORS +1 -0
- data/Gemfile +13 -0
- data/README.md +27 -4
- data/Rakefile +12 -0
- data/config/locales/en.yml +5 -0
- data/gemfiles/belongs_to_polymorphic-0.1.2.gem +0 -0
- data/gemfiles/belongs_to_polymorphic-0.1.3.gem +0 -0
- data/gemfiles/belongs_to_polymorphic-0.2.0.gem +0 -0
- data/lib/belongs_to_polymorphic/associations.rb +33 -6
- data/lib/belongs_to_polymorphic/version.rb +1 -1
- data/lib/belongs_to_polymorphic.rb +1 -1
- metadata +19 -77
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29a354017463f28f8c39642be9e2dfbbf597768a8b2d4f3591f4b1e8a1470931
|
4
|
+
data.tar.gz: d4f65459c4a69796525cc7f9a80dbca787fda27065f8424ac3c62938181185d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28d1f1b80203ef6b8876ac112ca5e0142f98e0b12b6c31bd804b28bd0e6ed96b4b5720db71b5d69320f50cacc038838635945d0c8aee1e3482aee8f09c9debd3
|
7
|
+
data.tar.gz: 2fa3373ed9d6480668d473a752eca867b6ce3355704145ea83025c40e8e636ec3909277f873682e4e25793c228bcaea490970834fcf8e7c658ad17ed6b4a75bf
|
data/.reek.yml
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
detectors:
|
2
|
+
Attribute:
|
3
|
+
enabled: false
|
4
|
+
exclude: []
|
5
|
+
BooleanParameter:
|
6
|
+
enabled: true
|
7
|
+
exclude: []
|
8
|
+
ClassVariable:
|
9
|
+
enabled: false
|
10
|
+
exclude: []
|
11
|
+
ControlParameter:
|
12
|
+
enabled: true
|
13
|
+
exclude: []
|
14
|
+
DataClump:
|
15
|
+
enabled: true
|
16
|
+
exclude: []
|
17
|
+
max_copies: 2
|
18
|
+
min_clump_size: 2
|
19
|
+
DuplicateMethodCall:
|
20
|
+
enabled: true
|
21
|
+
exclude: []
|
22
|
+
max_calls: 1
|
23
|
+
allow_calls: []
|
24
|
+
FeatureEnvy:
|
25
|
+
enabled: true
|
26
|
+
exclude: []
|
27
|
+
InstanceVariableAssumption:
|
28
|
+
enabled: false
|
29
|
+
IrresponsibleModule:
|
30
|
+
enabled: false
|
31
|
+
exclude: []
|
32
|
+
LongParameterList:
|
33
|
+
enabled: true
|
34
|
+
exclude: []
|
35
|
+
max_params: 4
|
36
|
+
overrides:
|
37
|
+
initialize:
|
38
|
+
max_params: 5
|
39
|
+
LongYieldList:
|
40
|
+
enabled: true
|
41
|
+
exclude: []
|
42
|
+
max_params: 3
|
43
|
+
ManualDispatch:
|
44
|
+
enabled: true
|
45
|
+
exclude: []
|
46
|
+
MissingSafeMethod:
|
47
|
+
enabled: false
|
48
|
+
exclude: []
|
49
|
+
ModuleInitialize:
|
50
|
+
enabled: true
|
51
|
+
exclude: []
|
52
|
+
NestedIterators:
|
53
|
+
enabled: true
|
54
|
+
exclude: []
|
55
|
+
max_allowed_nesting: 2
|
56
|
+
ignore_iterators: []
|
57
|
+
NilCheck:
|
58
|
+
enabled: false
|
59
|
+
exclude: []
|
60
|
+
RepeatedConditional:
|
61
|
+
enabled: true
|
62
|
+
exclude: []
|
63
|
+
max_ifs: 3
|
64
|
+
SubclassedFromCoreClass:
|
65
|
+
enabled: true
|
66
|
+
exclude: []
|
67
|
+
TooManyConstants:
|
68
|
+
enabled: true
|
69
|
+
exclude: []
|
70
|
+
max_constants: 5
|
71
|
+
TooManyInstanceVariables:
|
72
|
+
enabled: true
|
73
|
+
exclude: []
|
74
|
+
max_instance_variables: 9
|
75
|
+
TooManyMethods:
|
76
|
+
enabled: true
|
77
|
+
exclude: []
|
78
|
+
max_methods: 25
|
79
|
+
TooManyStatements:
|
80
|
+
enabled: true
|
81
|
+
exclude:
|
82
|
+
- initialize
|
83
|
+
max_statements: 12
|
84
|
+
UncommunicativeMethodName:
|
85
|
+
enabled: true
|
86
|
+
exclude: []
|
87
|
+
reject:
|
88
|
+
- "/^[a-z]$/"
|
89
|
+
- "/[0-9]$/"
|
90
|
+
- "/[A-Z]/"
|
91
|
+
accept: []
|
92
|
+
UncommunicativeModuleName:
|
93
|
+
enabled: true
|
94
|
+
exclude: []
|
95
|
+
reject:
|
96
|
+
- "/^.$/"
|
97
|
+
- "/[0-9]$/"
|
98
|
+
accept:
|
99
|
+
- Inline::C
|
100
|
+
- "/V[0-9]/"
|
101
|
+
UncommunicativeParameterName:
|
102
|
+
enabled: true
|
103
|
+
exclude: []
|
104
|
+
reject:
|
105
|
+
- "/^.$/"
|
106
|
+
- "/[0-9]$/"
|
107
|
+
- "/[A-Z]/"
|
108
|
+
accept: []
|
109
|
+
UncommunicativeVariableName:
|
110
|
+
enabled: true
|
111
|
+
exclude: []
|
112
|
+
reject:
|
113
|
+
- "/^.$/"
|
114
|
+
- "/[0-9]$/"
|
115
|
+
- "/[A-Z]/"
|
116
|
+
accept:
|
117
|
+
- _
|
118
|
+
UnusedParameters:
|
119
|
+
enabled: true
|
120
|
+
exclude: []
|
121
|
+
UnusedPrivateMethod:
|
122
|
+
enabled: false
|
123
|
+
UtilityFunction:
|
124
|
+
enabled: false
|
125
|
+
|
126
|
+
exclude_paths:
|
127
|
+
- config
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.5
|
3
|
+
SuggestExtensions: false
|
4
|
+
NewCops: enable
|
5
|
+
|
6
|
+
Style/Documentation:
|
7
|
+
Enabled: false
|
8
|
+
|
9
|
+
Layout/SpaceBeforeFirstArg:
|
10
|
+
Exclude:
|
11
|
+
|
12
|
+
Lint/AmbiguousBlockAssociation:
|
13
|
+
Exclude:
|
14
|
+
- spec/**/*
|
15
|
+
|
16
|
+
Metrics/AbcSize:
|
17
|
+
# The ABC size is a calculated magnitude, so this number can be an Integer or
|
18
|
+
# a Float.
|
19
|
+
Max: 15
|
20
|
+
|
21
|
+
Metrics/BlockLength:
|
22
|
+
CountComments: false
|
23
|
+
Max: 25
|
24
|
+
Exclude:
|
25
|
+
- '*.gemspec'
|
26
|
+
- config/**/*
|
27
|
+
- spec/**/*
|
28
|
+
IgnoredMethods:
|
29
|
+
- class_methods
|
30
|
+
|
31
|
+
Metrics/BlockNesting:
|
32
|
+
Max: 4
|
33
|
+
|
34
|
+
Metrics/ClassLength:
|
35
|
+
CountComments: false
|
36
|
+
Max: 200
|
37
|
+
|
38
|
+
# Avoid complex methods.
|
39
|
+
Metrics/CyclomaticComplexity:
|
40
|
+
Max: 7
|
41
|
+
|
42
|
+
Metrics/MethodLength:
|
43
|
+
CountComments: false
|
44
|
+
Max: 24
|
45
|
+
|
46
|
+
Metrics/ModuleLength:
|
47
|
+
CountComments: false
|
48
|
+
Max: 200
|
49
|
+
|
50
|
+
Layout/LineLength:
|
51
|
+
Max: 100
|
52
|
+
# To make it possible to copy or click on URIs in the code, we allow lines
|
53
|
+
# containing a URI to be longer than Max.
|
54
|
+
AllowURI: true
|
55
|
+
URISchemes:
|
56
|
+
- http
|
57
|
+
- https
|
58
|
+
|
59
|
+
Metrics/ParameterLists:
|
60
|
+
Max: 5
|
61
|
+
CountKeywordArgs: true
|
62
|
+
|
63
|
+
Metrics/PerceivedComplexity:
|
64
|
+
Max: 12
|
65
|
+
|
66
|
+
Style/FrozenStringLiteralComment:
|
67
|
+
Enabled: true
|
68
|
+
|
69
|
+
Style/ModuleFunction:
|
70
|
+
Enabled: false
|
71
|
+
|
72
|
+
Style/RescueModifier:
|
73
|
+
Exclude:
|
74
|
+
- spec/**/*
|
75
|
+
|
76
|
+
Naming/PredicateName:
|
77
|
+
Enabled: false
|
78
|
+
|
79
|
+
Style/HashEachMethods:
|
80
|
+
Enabled: true
|
81
|
+
|
82
|
+
Style/HashTransformKeys:
|
83
|
+
Enabled: true
|
84
|
+
|
85
|
+
Style/HashTransformValues:
|
86
|
+
Enabled: true
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
## [Unreleased]
|
2
|
+
|
3
|
+
## [0.1.1] - 2022-03-14
|
4
|
+
|
5
|
+
- Initial release
|
6
|
+
|
7
|
+
## [0.1.2] - 2022-07-20
|
8
|
+
|
9
|
+
- Added necessary specs
|
10
|
+
|
11
|
+
## [0.1.3] - 2022-07-20
|
12
|
+
|
13
|
+
- Fixed issue with I18n load path
|
14
|
+
|
15
|
+
## [0.2.0] - 2022-12-27
|
16
|
+
|
17
|
+
- This version is a refactor with a breaking change into how the gem is used.
|
18
|
+
|
19
|
+
### Breaking Changes
|
20
|
+
|
21
|
+
- Drop usage of the keyword `belongs_to_polymorphic` in favor of `belongs_to`.
|
22
|
+
- Drop usage of the option `allowed_classes` in favor of reusing the `polymorphic` option.
|
23
|
+
- As an example, in previous versions, you would have:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
class User < ApplicationRecord
|
27
|
+
belongs_to_polymorphic :profile, allowed_classes: [Person, Company]
|
28
|
+
end
|
29
|
+
```
|
30
|
+
Whereas in this version, you would have:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
class User < ApplicationRecord
|
34
|
+
belongs_to :profile, polymorphic: [Person, Company]
|
35
|
+
end
|
36
|
+
```
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
- Demonstrating empathy and kindness toward other people
|
14
|
+
- Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
- Giving and gracefully accepting constructive feedback
|
16
|
+
- Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
- Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
- The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
- Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
- Public or private harassment
|
25
|
+
- Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
- Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at hello@gogrow.dev. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/CONTRIBUTORS
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Nicolas Erlichman <nicolas@gogrow.dev>
|
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in belongs_to_polymorphic.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem 'database_cleaner-active_record', '~> 1.8.0', require: false
|
9
|
+
gem 'rake', '~> 13.0.6'
|
10
|
+
gem 'rspec', '~> 3.11.0'
|
11
|
+
gem 'rubocop', '~> 1.28'
|
12
|
+
gem 'simplecov', '~> 0.17.1'
|
13
|
+
gem 'sqlite3', '~> 1.4.2', require: false
|
data/README.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
# Belongs to Polymorphic
|
2
|
+
[](https://badge.fury.io/rb/belongs_to_polymorphic)
|
3
|
+
[](https://github.com/gogrow-dev/belongs_to_polymorphic/actions/workflows/main.yml)
|
4
|
+
[](https://codeclimate.com/github/gogrow-dev/belongs_to_polymorphic/maintainability)
|
5
|
+
[](https://codeclimate.com/github/gogrow-dev/belongs_to_polymorphic/test_coverage)
|
2
6
|
|
3
|
-
An ActiveRecord extension
|
7
|
+
An ActiveRecord extension which allows us to use polymorphic associations (belongs_to) and validating which classes are allowed to be related to, while also adding some helper methods.
|
4
8
|
|
5
9
|
|
6
10
|
The base idea was taken from this blogpost: [Improve ActiveRecord Polymorphic Associations - Head of engineering at Product Hunt](https://blog.rstankov.com/allowed-class-names-in-activerecord-polymorphic-associations/).
|
@@ -27,11 +31,11 @@ In your model you can do the following:
|
|
27
31
|
|
28
32
|
```ruby
|
29
33
|
class Book < ActiveRecord::Base
|
30
|
-
|
34
|
+
belongs_to :owner, polymorphic: [User, Publisher]
|
31
35
|
end
|
32
36
|
```
|
33
37
|
|
34
|
-
You
|
38
|
+
You will use a `belongs_to` relatinoship as always, with the only change being that besides just indicating `polymorphic: true` you could specify the allowed polymorphic classes.
|
35
39
|
|
36
40
|
By using this you create a polymorphic relationship in `Book` called `owner` which can be a `User` or a `Publisher`.
|
37
41
|
If you try to set an `owner` from a class rather than the aforementioend ones, it will return the following error:
|
@@ -53,7 +57,7 @@ Instance:
|
|
53
57
|
|
54
58
|
```ruby
|
55
59
|
class Book < ActiveRecord::Base
|
56
|
-
|
60
|
+
belongs_to :owner, polymorphic: [Publisher::User, Publisher]
|
57
61
|
end
|
58
62
|
```
|
59
63
|
|
@@ -74,6 +78,25 @@ en:
|
|
74
78
|
class_not_allowed: "%{class} is not an allowed class"
|
75
79
|
```
|
76
80
|
|
81
|
+
## Development
|
82
|
+
|
83
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
84
|
+
|
85
|
+
## Contributing
|
86
|
+
|
87
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/gogrow-dev/belongs_to_polymorphic. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/gogrow-dev/belongs_to_polymorphic/blob/main/CODE_OF_CONDUCT.md).
|
88
|
+
|
77
89
|
## License
|
78
90
|
|
79
91
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
92
|
+
|
93
|
+
## Code of Conduct
|
94
|
+
|
95
|
+
Everyone interacting in the belongs_to_polymorphic project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/gogrow-dev/belongs_to_polymorphic/blob/main/CODE_OF_CONDUCT.md).
|
96
|
+
|
97
|
+
## Credits
|
98
|
+
|
99
|
+
belongs_to_polymorphic is maintained by [GoGrow](https://gogrow.dev) with the help of our
|
100
|
+
[contributors](https://github.com/gogrow-dev/belongs_to_polymorphic/contributors).
|
101
|
+
|
102
|
+
[<img src="https://user-images.githubusercontent.com/9309458/180014465-00477428-fd76-48f6-b984-5b401b8ce241.svg" height="50"/>](https://gogrow.dev)
|
data/Rakefile
ADDED
Binary file
|
Binary file
|
Binary file
|
@@ -4,14 +4,23 @@ module BelongsToPolymorphic
|
|
4
4
|
module Associations
|
5
5
|
def self.included(base)
|
6
6
|
base.extend ClassMethods
|
7
|
+
class << base
|
8
|
+
alias_method :default_belongs_to, :belongs_to
|
9
|
+
alias_method :belongs_to, :belongs_to_polymorphic
|
10
|
+
end
|
7
11
|
end
|
8
12
|
|
9
13
|
module ClassMethods
|
10
|
-
def belongs_to_polymorphic(name,
|
11
|
-
|
12
|
-
|
14
|
+
def belongs_to_polymorphic(name, **options)
|
15
|
+
default_belongs_to name, **options
|
16
|
+
polymorphic = options[:polymorphic]
|
17
|
+
|
18
|
+
return unless polymorphic.present? && polymorphic.class != TrueClass
|
19
|
+
|
20
|
+
allowed_classes = classify(polymorphic)
|
21
|
+
|
13
22
|
validates "#{name}_type", inclusion: {
|
14
|
-
in:
|
23
|
+
in: inclusion_classes(allowed_classes, options[:optional]),
|
15
24
|
message: I18n.t('belongs_to_polymorphic.errors.messages.class_not_allowed',
|
16
25
|
class: '%<value>s')
|
17
26
|
}
|
@@ -23,9 +32,27 @@ module BelongsToPolymorphic
|
|
23
32
|
|
24
33
|
private
|
25
34
|
|
26
|
-
def classes
|
35
|
+
def classify(classes)
|
36
|
+
Array.wrap(classes).map do |klass|
|
37
|
+
case klass
|
38
|
+
when Class then klass
|
39
|
+
else constantize(klass)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def constantize(klass)
|
45
|
+
const_class = case klass
|
46
|
+
when String then klass
|
47
|
+
when Symbol then klass.to_s
|
48
|
+
else type.class.name
|
49
|
+
end
|
50
|
+
const_class.classify.constantize
|
51
|
+
end
|
52
|
+
|
53
|
+
def inclusion_classes(allowed_classes, optional)
|
27
54
|
classes = allowed_classes.map(&:name)
|
28
|
-
classes << nil if
|
55
|
+
classes << nil if optional.present?
|
29
56
|
classes
|
30
57
|
end
|
31
58
|
|
@@ -4,7 +4,7 @@ require 'active_record'
|
|
4
4
|
require 'belongs_to_polymorphic/version'
|
5
5
|
require 'belongs_to_polymorphic/associations'
|
6
6
|
|
7
|
-
I18n.load_path <<
|
7
|
+
I18n.load_path << File.expand_path('config/locales/en.yml')
|
8
8
|
|
9
9
|
module BelongsToPolymorphic; end
|
10
10
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: belongs_to_polymorphic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nicolas Erlichman
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-12-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: '5.2'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
22
|
+
version: '7.1'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,87 +29,28 @@ dependencies:
|
|
29
29
|
version: '5.2'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
33
|
-
|
34
|
-
name: database_cleaner-active_record
|
35
|
-
requirement: !ruby/object:Gem::Requirement
|
36
|
-
requirements:
|
37
|
-
- - "~>"
|
38
|
-
- !ruby/object:Gem::Version
|
39
|
-
version: 1.8.0
|
40
|
-
type: :development
|
41
|
-
prerelease: false
|
42
|
-
version_requirements: !ruby/object:Gem::Requirement
|
43
|
-
requirements:
|
44
|
-
- - "~>"
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: 1.8.0
|
47
|
-
- !ruby/object:Gem::Dependency
|
48
|
-
name: rake
|
49
|
-
requirement: !ruby/object:Gem::Requirement
|
50
|
-
requirements:
|
51
|
-
- - "~>"
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: 13.0.6
|
54
|
-
type: :development
|
55
|
-
prerelease: false
|
56
|
-
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
requirements:
|
58
|
-
- - "~>"
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version: 13.0.6
|
61
|
-
- !ruby/object:Gem::Dependency
|
62
|
-
name: rspec
|
63
|
-
requirement: !ruby/object:Gem::Requirement
|
64
|
-
requirements:
|
65
|
-
- - "~>"
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
version: 3.11.0
|
68
|
-
type: :development
|
69
|
-
prerelease: false
|
70
|
-
version_requirements: !ruby/object:Gem::Requirement
|
71
|
-
requirements:
|
72
|
-
- - "~>"
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
version: 3.11.0
|
75
|
-
- !ruby/object:Gem::Dependency
|
76
|
-
name: simplecov
|
77
|
-
requirement: !ruby/object:Gem::Requirement
|
78
|
-
requirements:
|
79
|
-
- - "~>"
|
80
|
-
- !ruby/object:Gem::Version
|
81
|
-
version: 0.17.1
|
82
|
-
type: :development
|
83
|
-
prerelease: false
|
84
|
-
version_requirements: !ruby/object:Gem::Requirement
|
85
|
-
requirements:
|
86
|
-
- - "~>"
|
87
|
-
- !ruby/object:Gem::Version
|
88
|
-
version: 0.17.1
|
89
|
-
- !ruby/object:Gem::Dependency
|
90
|
-
name: sqlite3
|
91
|
-
requirement: !ruby/object:Gem::Requirement
|
92
|
-
requirements:
|
93
|
-
- - "~>"
|
94
|
-
- !ruby/object:Gem::Version
|
95
|
-
version: 1.4.2
|
96
|
-
type: :development
|
97
|
-
prerelease: false
|
98
|
-
version_requirements: !ruby/object:Gem::Requirement
|
99
|
-
requirements:
|
100
|
-
- - "~>"
|
101
|
-
- !ruby/object:Gem::Version
|
102
|
-
version: 1.4.2
|
103
|
-
description: ActiveRecord extension - Polymorphic associations with restricted allowed
|
104
|
-
classes.
|
32
|
+
version: '7.1'
|
33
|
+
description:
|
105
34
|
email:
|
106
35
|
- hello@gogrow.dev
|
107
36
|
executables: []
|
108
37
|
extensions: []
|
109
38
|
extra_rdoc_files: []
|
110
39
|
files:
|
40
|
+
- ".reek.yml"
|
41
|
+
- ".rspec"
|
42
|
+
- ".rubocop.yml"
|
43
|
+
- CHANGELOG.md
|
44
|
+
- CODE_OF_CONDUCT.md
|
45
|
+
- CONTRIBUTORS
|
46
|
+
- Gemfile
|
111
47
|
- LICENSE.txt
|
112
48
|
- README.md
|
49
|
+
- Rakefile
|
50
|
+
- config/locales/en.yml
|
51
|
+
- gemfiles/belongs_to_polymorphic-0.1.2.gem
|
52
|
+
- gemfiles/belongs_to_polymorphic-0.1.3.gem
|
53
|
+
- gemfiles/belongs_to_polymorphic-0.2.0.gem
|
113
54
|
- lib/belongs_to_polymorphic.rb
|
114
55
|
- lib/belongs_to_polymorphic/associations.rb
|
115
56
|
- lib/belongs_to_polymorphic/version.rb
|
@@ -118,6 +59,7 @@ licenses:
|
|
118
59
|
- MIT
|
119
60
|
metadata:
|
120
61
|
source_code_uri: https://github.com/gogrow-dev/belongs_to_polymorphic
|
62
|
+
changelog_uri: https://github.com/gogrow-dev/belongs_to_polymorphic/blob/master/CHANGELOG.md
|
121
63
|
rubygems_mfa_required: 'true'
|
122
64
|
post_install_message:
|
123
65
|
rdoc_options: []
|
@@ -127,7 +69,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
127
69
|
requirements:
|
128
70
|
- - ">="
|
129
71
|
- !ruby/object:Gem::Version
|
130
|
-
version: '
|
72
|
+
version: '2.5'
|
131
73
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
74
|
requirements:
|
133
75
|
- - ">="
|