property_sets 3.9.0 → 3.10.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/lib/property_sets/active_record_extension.rb +1 -10
- data/lib/property_sets/delegator.rb +2 -6
- data/lib/property_sets/version.rb +1 -1
- data/lib/property_sets.rb +11 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57d3eda9c41c2ac64bad8a55e313d58bd3918d9e61ff2be28283a9662c554a6e
|
4
|
+
data.tar.gz: e806ef107a1d4e21211658a40c829b2ffa553b05216e72a924932229b301d011
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2447f302325286caf0d5c2e48060e35f419e6e881369072bb4ed5485b1eda4640aec4223d0dbff1cdd7c0ddce241b252eec2f032517e95bb2ef1e80cf4154e1
|
7
|
+
data.tar.gz: 60e7ab51f65d11aca4c42a3e775ae2f17913927f002bb542c347d3bbc085dacdca76913bba406a2cb496336cfbcf812d1d6614330cdda97822dc99826fbb234d
|
@@ -5,9 +5,6 @@ require 'set'
|
|
5
5
|
module PropertySets
|
6
6
|
module ActiveRecordExtension
|
7
7
|
module ClassMethods
|
8
|
-
|
9
|
-
RAILS6 = ActiveRecord::VERSION::MAJOR >= 6
|
10
|
-
|
11
8
|
def property_set(association, options = {}, &block)
|
12
9
|
unless include?(PropertySets::ActiveRecordExtension::InstanceMethods)
|
13
10
|
self.send(:prepend, PropertySets::ActiveRecordExtension::InstanceMethods)
|
@@ -49,16 +46,10 @@ module PropertySets
|
|
49
46
|
end
|
50
47
|
end
|
51
48
|
|
52
|
-
# eg 5: AccountSettingsAssociationExtension
|
53
|
-
# eg 6: Account::SettingsAssociationExtension
|
54
|
-
|
55
49
|
# stolen/adapted from AR's collection_association.rb #define_extensions
|
56
50
|
|
57
51
|
module_name = "#{association.to_s.camelize}AssociationExtension"
|
58
|
-
|
59
|
-
|
60
|
-
target = RAILS6 ? self : self.parent
|
61
|
-
association_module = target.const_get module_name
|
52
|
+
association_module = self.const_get module_name
|
62
53
|
|
63
54
|
association_module.module_eval do
|
64
55
|
include PropertySets::ActiveRecordExtension::AssociationExtensions
|
@@ -27,11 +27,7 @@ module PropertySets
|
|
27
27
|
|
28
28
|
mappings.each do |old_attr, new_attr|
|
29
29
|
self.delegated_property_set_attributes << old_attr.to_s
|
30
|
-
|
31
|
-
attribute old_attr, ActiveRecord::Type::Value.new
|
32
|
-
else
|
33
|
-
attribute old_attr, ActiveModel::Type::Value.new
|
34
|
-
end
|
30
|
+
attribute old_attr, ActiveModel::Type::Value.new
|
35
31
|
define_method(old_attr) {
|
36
32
|
association = send(setname)
|
37
33
|
type = association.association_class.type(new_attr)
|
@@ -44,7 +40,7 @@ module PropertySets
|
|
44
40
|
send("#{old_attr}_will_change!")
|
45
41
|
end
|
46
42
|
send(setname).send("#{new_attr}=", value)
|
47
|
-
super(value)
|
43
|
+
super(value)
|
48
44
|
end
|
49
45
|
|
50
46
|
define_method("#{old_attr}_will_change!") do
|
data/lib/property_sets.rb
CHANGED
@@ -7,13 +7,17 @@ begin
|
|
7
7
|
rescue LoadError
|
8
8
|
end
|
9
9
|
|
10
|
+
if "#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}" == "6.1"
|
11
|
+
ActiveRecord::Base.singleton_class.alias_method :connection_class_for_self, :connection_classes
|
12
|
+
end
|
13
|
+
|
10
14
|
module PropertySets
|
11
15
|
def self.ensure_property_set_class(association, owner_class_name)
|
12
16
|
const_name = "#{owner_class_name.demodulize}#{association.to_s.singularize.camelcase}"
|
13
17
|
namespace = owner_class_name.deconstantize.safe_constantize || Object
|
14
18
|
|
15
19
|
unless namespace.const_defined?(const_name, false)
|
16
|
-
property_class = Class.new(
|
20
|
+
property_class = Class.new(parent_for_property_class(namespace, owner_class_name)) do
|
17
21
|
include PropertySets::PropertySetModel::InstanceMethods
|
18
22
|
extend PropertySets::PropertySetModel::ClassMethods
|
19
23
|
end
|
@@ -26,4 +30,10 @@ module PropertySets
|
|
26
30
|
|
27
31
|
namespace.const_get(const_name.to_s)
|
28
32
|
end
|
33
|
+
|
34
|
+
def self.parent_for_property_class(namespace, owner_class_name)
|
35
|
+
namespace.const_get(owner_class_name).connection_class_for_self
|
36
|
+
rescue NameError
|
37
|
+
::ActiveRecord::Base
|
38
|
+
end
|
29
39
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: property_sets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Morten Primdahl
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -16,7 +16,7 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '6.0'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: '7.1'
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
29
|
+
version: '6.0'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '7.1'
|