polymorphic_aliases 0.2.0 → 0.2.4
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 066cdf5b1b77d94585d077761c890cd67c185bf78ec0d5533f5fa8ce167dd17c
|
4
|
+
data.tar.gz: 895246b8536d46e522c6bc32274298a7e023d2df7d35c268a31cb244b8fd150c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 62018234327a9c53377c194a6b3e8adea8c14b6a9655c158eb4d6c30e56e820a5b28739238c94249ecde38e1c8ecf22b009f506b6628e8f35b6e480baab96478
|
7
|
+
data.tar.gz: 1a4f6de24c7c9bd5f82dcc37f884d411b908de9dfc2a229e9bee78429d3ffbde506d0a4ffbf39604ddfd465ad29bee727427d855b6e268586535e5064f220b4b
|
data/README.md
CHANGED
@@ -47,6 +47,12 @@ Add this line to your application's Gemfile:
|
|
47
47
|
gem "polymorphic_aliases"
|
48
48
|
```
|
49
49
|
|
50
|
+
Or if you want to target the `main` branch:
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
gem "polymorphic_aliases", github: "mansakondo/polymorphic_aliases"
|
54
|
+
```
|
55
|
+
|
50
56
|
And then execute:
|
51
57
|
```bash
|
52
58
|
$ bundle
|
metadata
CHANGED
@@ -1,35 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: polymorphic_aliases
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mansakondo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 6.1.3
|
20
17
|
- - ">="
|
21
18
|
- !ruby/object:Gem::Version
|
22
|
-
version: 6.
|
19
|
+
version: '6.0'
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
|
-
- - "
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '6.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: appraisal
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
28
32
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
30
38
|
- - ">="
|
31
39
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
40
|
+
version: '0'
|
33
41
|
description:
|
34
42
|
email:
|
35
43
|
- mansakondo22@gmail.com
|
@@ -41,7 +49,6 @@ files:
|
|
41
49
|
- README.md
|
42
50
|
- Rakefile
|
43
51
|
- lib/polymorphic_aliases.rb
|
44
|
-
- lib/polymorphic_aliases/active_model/attribute_methods/polymorphic_attribute_aliases.rb
|
45
52
|
- lib/polymorphic_aliases/active_record/associations/builder/belongs_to_polymorphic_association.rb
|
46
53
|
- lib/polymorphic_aliases/railtie.rb
|
47
54
|
- lib/polymorphic_aliases/version.rb
|
@@ -68,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
75
|
- !ruby/object:Gem::Version
|
69
76
|
version: '0'
|
70
77
|
requirements: []
|
71
|
-
rubygems_version: 3.2.
|
78
|
+
rubygems_version: 3.2.32
|
72
79
|
signing_key:
|
73
80
|
specification_version: 4
|
74
81
|
summary: An ActiveRecord extension to use aliases for your polymorphic associations.
|
data/lib/polymorphic_aliases/active_model/attribute_methods/polymorphic_attribute_aliases.rb
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module PolymorphicAttributeAliases
|
4
|
-
VALID_PREFIXES = %w( reload_ ).freeze
|
5
|
-
VALID_SUFFIXES = %w( = ).freeze
|
6
|
-
|
7
|
-
private_constant :VALID_PREFIXES, :VALID_SUFFIXES
|
8
|
-
|
9
|
-
def method_missing(method, *args, &block)
|
10
|
-
prefix, attribute_name, suffix = decompose_method_name(method)
|
11
|
-
|
12
|
-
self.class.reflect_on_all_associations(:belongs_to).each do |reflection|
|
13
|
-
begin
|
14
|
-
next unless (types = reflection.options[:types])
|
15
|
-
next unless (target_type = attributes["#{reflection.name}_type"])
|
16
|
-
next unless types.any? { |type| type.to_s.constantize == target_type.constantize }
|
17
|
-
next unless target_type.constantize == attribute_name.camelize.constantize
|
18
|
-
|
19
|
-
association_method_name = prefix + reflection.name.to_s + suffix
|
20
|
-
return send(:"#{association_method_name}", *args, &block)
|
21
|
-
rescue
|
22
|
-
return super
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
super
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def decompose_method_name(method_name)
|
32
|
-
method_name = method_name.to_s
|
33
|
-
|
34
|
-
prefix = ""
|
35
|
-
affix = method_name
|
36
|
-
suffix = ""
|
37
|
-
|
38
|
-
VALID_PREFIXES.each do |valid_prefix|
|
39
|
-
next unless method_name.start_with?(valid_prefix)
|
40
|
-
prefix = valid_prefix
|
41
|
-
affix = method_name.delete_prefix(valid_prefix)
|
42
|
-
|
43
|
-
break
|
44
|
-
end
|
45
|
-
|
46
|
-
VALID_SUFFIXES.each do |valid_suffix|
|
47
|
-
next unless method_name.ends_with?(valid_suffix)
|
48
|
-
suffix = valid_suffix
|
49
|
-
affix = affix.delete_suffix(valid_suffix)
|
50
|
-
|
51
|
-
break
|
52
|
-
end
|
53
|
-
|
54
|
-
return prefix, affix, suffix
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
ActiveModel::AttributeMethods.prepend(PolymorphicAttributeAliases)
|