safe_polymorphic 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +21 -0
- data/CHANGELOG.md +6 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +89 -0
- data/LICENSE.md +21 -0
- data/README.md +84 -0
- data/Rakefile +12 -0
- data/config/locales/en.yml +5 -0
- data/lib/safe_polymorphic/associations.rb +91 -0
- data/lib/safe_polymorphic/version.rb +5 -0
- data/lib/safe_polymorphic.rb +14 -0
- data/safe_polymorphic.gemspec +33 -0
- metadata +81 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cdcf7aaf3518f1d4a718593cc9e384e2d867e8bc92a519d0ef192535ed754cbf
|
4
|
+
data.tar.gz: 0a9b9ab48c6efdda379cfc5956bf6579cf230bcb092c5f98df6225e76815314e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4acc62a25aaf5cf4a3739f4578870555b1e85fac29d3058f358f51f0805c1857c8b4b31bf18b3b384c7591b3822e51599164c6e4420500ad7896faec5b6cc099
|
7
|
+
data.tar.gz: 036dba54db4d711e0e7b8319f383259c38717ac73b196fde6545082cc7168587af2aa429441409eb393eb6232f3af00c75f19412548a9d2636babad9c1c3023e
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.6
|
3
|
+
NewCops: disable
|
4
|
+
|
5
|
+
Style/Documentation:
|
6
|
+
Enabled: false
|
7
|
+
|
8
|
+
Metrics/BlockLength:
|
9
|
+
Exclude:
|
10
|
+
- "spec/**/*"
|
11
|
+
|
12
|
+
Style/StringLiterals:
|
13
|
+
Enabled: true
|
14
|
+
EnforcedStyle: single_quotes
|
15
|
+
|
16
|
+
Style/StringLiteralsInInterpolation:
|
17
|
+
Enabled: true
|
18
|
+
EnforcedStyle: double_quotes
|
19
|
+
|
20
|
+
Layout/LineLength:
|
21
|
+
Max: 120
|
data/CHANGELOG.md
ADDED
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 nicolas@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/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 safe_polymorphic.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem 'database_cleaner-active_record', '~> 1.8.0', require: false
|
9
|
+
gem 'rake', '~> 13.0'
|
10
|
+
gem 'rspec', '~> 3.0'
|
11
|
+
gem 'rubocop', '~> 1.21'
|
12
|
+
gem 'simplecov', '~> 0.17.1'
|
13
|
+
gem 'sqlite3', '~> 1.4.2', require: false
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
safe_polymorphic (0.1.0)
|
5
|
+
activerecord (>= 5.2, < 7.1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activemodel (7.0.4)
|
11
|
+
activesupport (= 7.0.4)
|
12
|
+
activerecord (7.0.4)
|
13
|
+
activemodel (= 7.0.4)
|
14
|
+
activesupport (= 7.0.4)
|
15
|
+
activesupport (7.0.4)
|
16
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
|
+
i18n (>= 1.6, < 2)
|
18
|
+
minitest (>= 5.1)
|
19
|
+
tzinfo (~> 2.0)
|
20
|
+
ast (2.4.2)
|
21
|
+
concurrent-ruby (1.1.10)
|
22
|
+
database_cleaner (1.8.5)
|
23
|
+
database_cleaner-active_record (1.8.0)
|
24
|
+
activerecord
|
25
|
+
database_cleaner (~> 1.8.0)
|
26
|
+
diff-lcs (1.5.0)
|
27
|
+
docile (1.4.0)
|
28
|
+
i18n (1.12.0)
|
29
|
+
concurrent-ruby (~> 1.0)
|
30
|
+
json (2.6.3)
|
31
|
+
minitest (5.16.3)
|
32
|
+
parallel (1.22.1)
|
33
|
+
parser (3.1.3.0)
|
34
|
+
ast (~> 2.4.1)
|
35
|
+
rainbow (3.1.1)
|
36
|
+
rake (13.0.6)
|
37
|
+
regexp_parser (2.6.1)
|
38
|
+
rexml (3.2.5)
|
39
|
+
rspec (3.12.0)
|
40
|
+
rspec-core (~> 3.12.0)
|
41
|
+
rspec-expectations (~> 3.12.0)
|
42
|
+
rspec-mocks (~> 3.12.0)
|
43
|
+
rspec-core (3.12.0)
|
44
|
+
rspec-support (~> 3.12.0)
|
45
|
+
rspec-expectations (3.12.1)
|
46
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
47
|
+
rspec-support (~> 3.12.0)
|
48
|
+
rspec-mocks (3.12.1)
|
49
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
50
|
+
rspec-support (~> 3.12.0)
|
51
|
+
rspec-support (3.12.0)
|
52
|
+
rubocop (1.41.1)
|
53
|
+
json (~> 2.3)
|
54
|
+
parallel (~> 1.10)
|
55
|
+
parser (>= 3.1.2.1)
|
56
|
+
rainbow (>= 2.2.2, < 4.0)
|
57
|
+
regexp_parser (>= 1.8, < 3.0)
|
58
|
+
rexml (>= 3.2.5, < 4.0)
|
59
|
+
rubocop-ast (>= 1.23.0, < 2.0)
|
60
|
+
ruby-progressbar (~> 1.7)
|
61
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
62
|
+
rubocop-ast (1.24.0)
|
63
|
+
parser (>= 3.1.1.0)
|
64
|
+
ruby-progressbar (1.11.0)
|
65
|
+
simplecov (0.17.1)
|
66
|
+
docile (~> 1.1)
|
67
|
+
json (>= 1.8, < 3)
|
68
|
+
simplecov-html (~> 0.10.0)
|
69
|
+
simplecov-html (0.10.2)
|
70
|
+
sqlite3 (1.4.4)
|
71
|
+
tzinfo (2.0.5)
|
72
|
+
concurrent-ruby (~> 1.0)
|
73
|
+
unicode-display_width (2.3.0)
|
74
|
+
|
75
|
+
PLATFORMS
|
76
|
+
arm64-darwin-21
|
77
|
+
x86_64-linux
|
78
|
+
|
79
|
+
DEPENDENCIES
|
80
|
+
database_cleaner-active_record (~> 1.8.0)
|
81
|
+
rake (~> 13.0)
|
82
|
+
rspec (~> 3.0)
|
83
|
+
rubocop (~> 1.21)
|
84
|
+
safe_polymorphic!
|
85
|
+
simplecov (~> 0.17.1)
|
86
|
+
sqlite3 (~> 1.4.2)
|
87
|
+
|
88
|
+
BUNDLED WITH
|
89
|
+
2.3.7
|
data/LICENSE.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 Nicolas Erlichman, GoGrow
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# SafePolymorphic
|
2
|
+
|
3
|
+
An ActiveRecord extension which allows us to safely use polymorphic associations, by validating which classes are allowed to be related to, while also adding some helper methods.
|
4
|
+
|
5
|
+
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/).
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Install the gem and add to the application's Gemfile by executing:
|
10
|
+
|
11
|
+
$ bundle add safe_polymorphic
|
12
|
+
|
13
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
14
|
+
|
15
|
+
$ gem install safe_polymorphic
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
In your model you can do the following:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
class Book < ActiveRecord::Base
|
23
|
+
belongs_to :owner, polymorphic: [User, Publisher]
|
24
|
+
end
|
25
|
+
```
|
26
|
+
|
27
|
+
Define a `belongs_to` relatinoship and instead of just adding the option `polymorphic: true`, we are able to specify the allowed polymorphic classes.
|
28
|
+
|
29
|
+
By using this, we will create a polymorphic relationship in `Book` called `owner` which can only be a `User` or a `Publisher`.
|
30
|
+
If we try to set an `owner` from a class rather than the aforementioend ones, it will return the following error:
|
31
|
+
```ruby
|
32
|
+
#ActiveRecord::RecordInvalid: Validation failed: Owner type OtherThing class is not an allowed class.
|
33
|
+
```
|
34
|
+
|
35
|
+
### Usage with namespaced models
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
class Book < ActiveRecord::Base
|
39
|
+
belongs_to :owner, polymorphic: [Publisher::User, Publisher]
|
40
|
+
end
|
41
|
+
```
|
42
|
+
|
43
|
+
### Helper methods
|
44
|
+
|
45
|
+
Class methods:
|
46
|
+
- `Book.owner_types`: returns the allowed classes
|
47
|
+
- `Book.with_owner(#{type})`: generic finder method
|
48
|
+
- `Book.with_owner_#{allowed_class_name}`: scope for each allowed class
|
49
|
+
|
50
|
+
Instance methods:
|
51
|
+
- `book.owner_type_#{allowed_class_name}?`: check if it is from that specific class
|
52
|
+
|
53
|
+
### Helper methods with namespaced models
|
54
|
+
|
55
|
+
Class methods:
|
56
|
+
- `Book.with_owner(Publisher::User)`
|
57
|
+
- `Book.with_owner_publisher_user`
|
58
|
+
- `book.owner_type_publisher_user?`
|
59
|
+
|
60
|
+
## I18n
|
61
|
+
|
62
|
+
Safe Polymoprhic uses I18n to define the not allowed class error. To customize it, you can set up your locale file:
|
63
|
+
|
64
|
+
```yaml
|
65
|
+
en:
|
66
|
+
safe_polymoprhic:
|
67
|
+
errors:
|
68
|
+
messages:
|
69
|
+
class_not_allowed: "%{class} is not an allowed class"
|
70
|
+
```
|
71
|
+
|
72
|
+
## Development
|
73
|
+
|
74
|
+
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.
|
75
|
+
|
76
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
77
|
+
|
78
|
+
## Contributing
|
79
|
+
|
80
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/safe_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/[USERNAME]/safe_polymorphic/blob/main/CODE_OF_CONDUCT.md).
|
81
|
+
|
82
|
+
## Code of Conduct
|
83
|
+
|
84
|
+
Everyone interacting in the SafePolymorphic project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/safe_polymorphic/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SafePolymorphic
|
4
|
+
module Associations
|
5
|
+
def self.included(base)
|
6
|
+
base.extend ClassMethods
|
7
|
+
class << base
|
8
|
+
alias_method :unsafe_polymorphic, :belongs_to
|
9
|
+
alias_method :belongs_to, :safe_polymorphic
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
module ClassMethods
|
14
|
+
def safe_polymorphic(name, **options)
|
15
|
+
unsafe_polymorphic name, **options
|
16
|
+
polymorphic = options[:polymorphic]
|
17
|
+
|
18
|
+
return unless polymorphic.present? && polymorphic.class != TrueClass
|
19
|
+
|
20
|
+
allowed_classes = classify(polymorphic)
|
21
|
+
|
22
|
+
validates "#{name}_type", inclusion: inclusion_validation(allowed_classes, options[:optional])
|
23
|
+
|
24
|
+
define_singleton_method("#{name}_types") { allowed_classes }
|
25
|
+
define_generic_finder_method(name)
|
26
|
+
define_scopes_and_instance_methods(name, allowed_classes)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def inclusion_validation(allowed_classes, optional)
|
32
|
+
{
|
33
|
+
in: inclusion_classes(allowed_classes, optional),
|
34
|
+
message: I18n.t('safe_polymorphic.errors.messages.class_not_allowed',
|
35
|
+
class: '%<value>s')
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
def classify(classes)
|
40
|
+
Array.wrap(classes).map do |klass|
|
41
|
+
case klass
|
42
|
+
when Class then klass
|
43
|
+
else constantize(klass)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def constantize(klass)
|
49
|
+
const_class = case klass
|
50
|
+
when String then klass
|
51
|
+
when Symbol then klass.to_s
|
52
|
+
else type.class.name
|
53
|
+
end
|
54
|
+
const_class.classify.constantize
|
55
|
+
end
|
56
|
+
|
57
|
+
def inclusion_classes(allowed_classes, optional)
|
58
|
+
classes = allowed_classes.map(&:name)
|
59
|
+
classes << nil if optional.present?
|
60
|
+
classes
|
61
|
+
end
|
62
|
+
|
63
|
+
# Generates a generic finder method
|
64
|
+
def define_generic_finder_method(name)
|
65
|
+
define_singleton_method("with_#{name}") do |type|
|
66
|
+
type = case type
|
67
|
+
when Class then type.name
|
68
|
+
when String then type
|
69
|
+
else type.class.name
|
70
|
+
end
|
71
|
+
where("#{name}_type" => type)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def define_scopes_and_instance_methods(name, allowed_classes)
|
76
|
+
allowed_classes.each do |model|
|
77
|
+
model_name = model.name
|
78
|
+
model_name_sanitized = model_name.underscore.tr('/', '_')
|
79
|
+
# generates scope for each allowed class
|
80
|
+
scope "with_#{name}_#{model_name_sanitized}",
|
81
|
+
-> { where("#{name}_type" => model_name) }
|
82
|
+
|
83
|
+
# generates instance method for each allowed class to check if type is that class
|
84
|
+
define_method("#{name}_type_#{model_name_sanitized}?") do
|
85
|
+
public_send("#{name}_type") == model_name
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'safe_polymorphic/version'
|
4
|
+
require 'active_record'
|
5
|
+
require_relative 'safe_polymorphic/associations'
|
6
|
+
|
7
|
+
I18n.load_path << File.expand_path('config/locales/en.yml')
|
8
|
+
|
9
|
+
module SafePolymorphic
|
10
|
+
class Error < StandardError; end
|
11
|
+
end
|
12
|
+
|
13
|
+
# Extend ActiveRecord::Base with belongs to polymorphic associations
|
14
|
+
ActiveRecord::Base.include SafePolymorphic::Associations
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/safe_polymorphic/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'safe_polymorphic'
|
7
|
+
spec.version = SafePolymorphic::VERSION
|
8
|
+
spec.licenses = ['MIT']
|
9
|
+
spec.authors = ['Nicolas Erlichman']
|
10
|
+
spec.email = ['nicolas@gogrow.dev']
|
11
|
+
|
12
|
+
spec.summary = 'ActiveRecord extension - ' \
|
13
|
+
'Polymorphic associations with restricted allowed classes.'
|
14
|
+
spec.homepage = 'https://github.com/gogrow-dev/safe_polymorphic'
|
15
|
+
spec.required_ruby_version = '>= 2.6.0'
|
16
|
+
|
17
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
18
|
+
spec.metadata['source_code_uri'] = spec.homepage
|
19
|
+
spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/master/CHANGELOG.md"
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(__dir__) do
|
24
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
25
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|circleci)|appveyor)})
|
26
|
+
end
|
27
|
+
end
|
28
|
+
spec.bindir = 'exe'
|
29
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ['lib']
|
31
|
+
|
32
|
+
spec.add_dependency 'activerecord', '>= 5.2', '< 7.1'
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: safe_polymorphic
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nicolas Erlichman
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-12-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.2'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '7.1'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '5.2'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '7.1'
|
33
|
+
description:
|
34
|
+
email:
|
35
|
+
- nicolas@gogrow.dev
|
36
|
+
executables: []
|
37
|
+
extensions: []
|
38
|
+
extra_rdoc_files: []
|
39
|
+
files:
|
40
|
+
- ".rspec"
|
41
|
+
- ".rubocop.yml"
|
42
|
+
- CHANGELOG.md
|
43
|
+
- CODE_OF_CONDUCT.md
|
44
|
+
- Gemfile
|
45
|
+
- Gemfile.lock
|
46
|
+
- LICENSE.md
|
47
|
+
- README.md
|
48
|
+
- Rakefile
|
49
|
+
- config/locales/en.yml
|
50
|
+
- lib/safe_polymorphic.rb
|
51
|
+
- lib/safe_polymorphic/associations.rb
|
52
|
+
- lib/safe_polymorphic/version.rb
|
53
|
+
- safe_polymorphic.gemspec
|
54
|
+
homepage: https://github.com/gogrow-dev/safe_polymorphic
|
55
|
+
licenses:
|
56
|
+
- MIT
|
57
|
+
metadata:
|
58
|
+
homepage_uri: https://github.com/gogrow-dev/safe_polymorphic
|
59
|
+
source_code_uri: https://github.com/gogrow-dev/safe_polymorphic
|
60
|
+
changelog_uri: https://github.com/gogrow-dev/safe_polymorphic/blob/master/CHANGELOG.md
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 2.6.0
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubygems_version: 3.3.7
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: ActiveRecord extension - Polymorphic associations with restricted allowed
|
80
|
+
classes.
|
81
|
+
test_files: []
|