belongs_to_polymorphic 0.2.1 → 0.2.99

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d402b15fb6ad50264ee7615b4bc0984cbd270f5522f34d769ea43521253812cd
4
- data.tar.gz: 416ce0c45d6dc7895e924ffd171ad4bbd10044bed41412650d8b60852178db65
3
+ metadata.gz: 0b3dd994cf6abe5f08b084c8afcc0fbd514c5cdd3e09b4f23524217629d98479
4
+ data.tar.gz: 48613eda5ff2b2f918f1f91a709a9c76ef8de1b43f3cbe244faea15e1c04a0e6
5
5
  SHA512:
6
- metadata.gz: 11793f6048d74f56bfe08f5ddc43a35f443a53fff51855178bc2054c4137af2ae370cd62079a94fe121042da854f47c9cd7a489ae4007f48b73973976890475a
7
- data.tar.gz: 9813cbd602f9628fbf2b1bcd91c32ac2d9514a4ec4ac7d773c802132a36512e737d5cf6309d83fab859d883a4c58a44ab58c514fbf1e8e3825ecd902607838f0
6
+ metadata.gz: 1caf26e74b7f0e396d1b777b4c9809454aac1fb7d25bbf47e32ef953e5376c95f32520d5719c5ea15e5a717eafe06e62f718914d3be16528d9cf49b799545dc8
7
+ data.tar.gz: b5160319a363eec808fb350b4f0add1dd1623e540876feb22d2ea59c1eaa3a84b48dbe2b522a6f6d19f5b21e7f66ef542e6b474a692e395d043425d4dca626b3
data/CHANGELOG.md CHANGED
@@ -33,4 +33,13 @@ Whereas in this version, you would have:
33
33
  class User < ApplicationRecord
34
34
  belongs_to :profile, polymorphic: [Person, Company]
35
35
  end
36
- ```
36
+ ```
37
+
38
+ ## [0.2.1] - 2022-12-27
39
+
40
+ - Fixed bundled gem size
41
+
42
+ ## [0.2.99] - 2022-12-28
43
+
44
+ - Add deprecation message
45
+
data/README old.md ADDED
@@ -0,0 +1,98 @@
1
+ # Belongs to Polymorphic
2
+
3
+ An ActiveRecord extension defining the concept *belongs to polymorphic*, which allows us to use polymorphic associations (belongs_to) and restrict which classes are allowed to be related to.
4
+
5
+
6
+ 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/).
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'belongs_to_polymorphic'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle install
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install belongs_to_polymorphic
23
+
24
+ ## Usage
25
+
26
+ In your model you can do the following:
27
+
28
+ ```ruby
29
+ class Book < ActiveRecord::Base
30
+ belongs_to_polymorphic :owner, allowed_classes: [User, Publisher]
31
+ end
32
+ ```
33
+
34
+ You can also add any options that a regular `belongs_to` with `polymorphic: true` could use.
35
+
36
+ By using this you create a polymorphic relationship in `Book` called `owner` which can be a `User` or a `Publisher`.
37
+ If you try to set an `owner` from a class rather than the aforementioend ones, it will return the following error:
38
+ ```ruby
39
+ #ActiveRecord::RecordInvalid: Validation failed: Owner type OtherThing class is not an allowed class.
40
+ ```
41
+
42
+ It also automatically adds some helpers
43
+
44
+ Class:
45
+ - `Book.owner_types`: returns the allowed classes
46
+ - `Book.with_owner(#{type})`: generic finder method
47
+ - `Book.with_owner_#{allowed_class_name}`: scope for each allowed class
48
+
49
+ Instance:
50
+ - `book.owner_type_#{allowed_class_name}?`: check if it is from that specific class
51
+
52
+ ### Usage with namespaced models
53
+
54
+ ```ruby
55
+ class Book < ActiveRecord::Base
56
+ belongs_to_polymorphic :owner, allowed_classes: [Publisher::User, Publisher]
57
+ end
58
+ ```
59
+
60
+ It will allow you to use:
61
+ - `Book.with_owner(Publisher::User)`
62
+ - `Book.with_owner_publisher_user`
63
+ - `book.owner_type_publisher_user?`
64
+
65
+ ## I18n
66
+
67
+ Belongs to Polymoprhic uses I18n to define the not allowed class error. To customize it, you can set up your locale file:
68
+
69
+ ```yaml
70
+ en:
71
+ belongs_to_polymoprhic:
72
+ errors:
73
+ messages:
74
+ class_not_allowed: "%{class} is not an allowed class"
75
+ ```
76
+
77
+ ## Development
78
+
79
+ 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.
80
+
81
+ ## Contributing
82
+
83
+ 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).
84
+
85
+ ## License
86
+
87
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
88
+
89
+ ## Code of Conduct
90
+
91
+ 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).
92
+
93
+ ## Credits
94
+
95
+ belongs_to_polymorphic is maintained by [GoGrow](https://gogrow.dev) with the help of our
96
+ [contributors](https://github.com/gogrow-dev/belongs_to_polymorphic/contributors).
97
+
98
+ [<img src="https://user-images.githubusercontent.com/9309458/180014465-00477428-fd76-48f6-b984-5b401b8ce241.svg" height="50"/>](https://gogrow.dev)
data/README.md CHANGED
@@ -1,98 +1,13 @@
1
- # Belongs to Polymorphic
1
+ # Belongs to Polymorphic ⚠️ This project is no longer maintained! ⚠️
2
2
  [![Gem Version](https://badge.fury.io/rb/belongs_to_polymorphic.svg)](https://badge.fury.io/rb/belongs_to_polymorphic)
3
3
  [![Ruby](https://github.com/gogrow-dev/belongs_to_polymorphic/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/gogrow-dev/belongs_to_polymorphic/actions/workflows/main.yml)
4
4
  [![Maintainability](https://api.codeclimate.com/v1/badges/1e3960d9aa00b8328a30/maintainability)](https://codeclimate.com/github/gogrow-dev/belongs_to_polymorphic/maintainability)
5
5
  [![Test Coverage](https://api.codeclimate.com/v1/badges/1e3960d9aa00b8328a30/test_coverage)](https://codeclimate.com/github/gogrow-dev/belongs_to_polymorphic/test_coverage)
6
6
 
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.
8
-
9
-
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/).
11
-
12
- ## Installation
13
-
14
- Add this line to your application's Gemfile:
15
-
16
- ```ruby
17
- gem 'belongs_to_polymorphic'
18
- ```
19
-
20
- And then execute:
21
-
22
- $ bundle install
23
-
24
- Or install it yourself as:
25
-
26
- $ gem install belongs_to_polymorphic
27
-
28
- ## Usage
29
-
30
- In your model you can do the following:
31
-
32
- ```ruby
33
- class Book < ActiveRecord::Base
34
- belongs_to :owner, polymorphic: [User, Publisher]
35
- end
36
- ```
37
-
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.
39
-
40
- By using this you create a polymorphic relationship in `Book` called `owner` which can be a `User` or a `Publisher`.
41
- If you try to set an `owner` from a class rather than the aforementioend ones, it will return the following error:
42
- ```ruby
43
- #ActiveRecord::RecordInvalid: Validation failed: Owner type OtherThing class is not an allowed class.
44
- ```
45
-
46
- It also automatically adds some helpers
47
-
48
- Class:
49
- - `Book.owner_types`: returns the allowed classes
50
- - `Book.with_owner(#{type})`: generic finder method
51
- - `Book.with_owner_#{allowed_class_name}`: scope for each allowed class
52
-
53
- Instance:
54
- - `book.owner_type_#{allowed_class_name}?`: check if it is from that specific class
55
-
56
- ### Usage with namespaced models
57
-
58
- ```ruby
59
- class Book < ActiveRecord::Base
60
- belongs_to :owner, polymorphic: [Publisher::User, Publisher]
61
- end
62
- ```
63
-
64
- It will allow you to use:
65
- - `Book.with_owner(Publisher::User)`
66
- - `Book.with_owner_publisher_user`
67
- - `book.owner_type_publisher_user?`
68
-
69
- ## I18n
70
-
71
- Belongs to Polymoprhic uses I18n to define the not allowed class error. To customize it, you can set up your locale file:
72
-
73
- ```yaml
74
- en:
75
- belongs_to_polymoprhic:
76
- errors:
77
- messages:
78
- class_not_allowed: "%{class} is not an allowed class"
79
- ```
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
-
89
- ## License
90
-
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).
7
+ The `belongs_to_polymoprhic` gem has been deprecated and has been replaced by `safe_polymorphic`.
8
+ See:
9
+ * https://rubygems.org/gems/safe_polymorphic
10
+ * https://github.com/gogrow-dev/safe_polymorphic
96
11
 
97
12
  ## Credits
98
13
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BelongsToPolymorphic
4
- VERSION = '0.2.1'
4
+ VERSION = '0.2.99'
5
5
  end
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.2.1
4
+ version: 0.2.99
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-12-27 00:00:00.000000000 Z
11
+ date: 2022-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -45,6 +45,7 @@ files:
45
45
  - CONTRIBUTORS
46
46
  - Gemfile
47
47
  - LICENSE.txt
48
+ - README old.md
48
49
  - README.md
49
50
  - Rakefile
50
51
  - config/locales/en.yml
@@ -58,7 +59,10 @@ metadata:
58
59
  source_code_uri: https://github.com/gogrow-dev/belongs_to_polymorphic
59
60
  changelog_uri: https://github.com/gogrow-dev/belongs_to_polymorphic/blob/master/CHANGELOG.md
60
61
  rubygems_mfa_required: 'true'
61
- post_install_message:
62
+ post_install_message: |2
63
+ ! The `belongs_to_polymoprhic` gem has been deprecated and has been replaced by `safe_polymorphic`.
64
+ ! See: https://rubygems.org/gems/safe_polymorphic
65
+ ! And: https://github.com/gogrow-dev/safe_polymorphic
62
66
  rdoc_options: []
63
67
  require_paths:
64
68
  - lib