property_sets 3.8.0 → 3.10.0

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: ddab71bb5879d419307ca07fda5be61c6cacfb3dd3e5881457a9eaa88bf94888
4
- data.tar.gz: 1b5b98ff2a14ef8797ae7a1b45ee8f6e6c7b2ccfd0dc65bbcfb27cde59ea28e3
3
+ metadata.gz: 57d3eda9c41c2ac64bad8a55e313d58bd3918d9e61ff2be28283a9662c554a6e
4
+ data.tar.gz: e806ef107a1d4e21211658a40c829b2ffa553b05216e72a924932229b301d011
5
5
  SHA512:
6
- metadata.gz: ae6d4df148fdb6d1743abbd9986a33a8392064d45aa6ce36d871c64b16383c1d8279b3c29c1b627fef429d36cd0cabecba19b56b61b20ab3b6647716190faf40
7
- data.tar.gz: 7a4834b04e57c715883aa6bc27080820b8d4f74101cf7385df506800ead33f3944f6c9106fde57ded468107ced9cfa40ba33ea8151665076e689a13ef23e3e5d
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)
@@ -36,7 +33,7 @@ module PropertySets
36
33
  :class_name => property_class.name,
37
34
  :autosave => true,
38
35
  :dependent => :destroy,
39
- :inverse_of => self.name.underscore.to_sym,
36
+ :inverse_of => self.name.demodulize.underscore.to_sym,
40
37
  }.merge(options)
41
38
 
42
39
  # TODO: should check options are compatible? warn? raise?
@@ -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
- module_name = name.demodulize + module_name unless RAILS6
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
@@ -126,12 +117,12 @@ module PropertySets
126
117
  end
127
118
  end
128
119
 
129
- def save(*args)
130
- each { |p| p.save(*args) }
120
+ def save(...)
121
+ each { |p| p.save(...) }
131
122
  end
132
123
 
133
- def save!(*args)
134
- each { |p| p.save!(*args) }
124
+ def save!(...)
125
+ each { |p| p.save!(...) }
135
126
  end
136
127
 
137
128
  def protected?(arg)
@@ -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
- if ActiveRecord.version < Gem::Version.new("5.0")
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) if defined?(super) # Rails 4 does not define this
43
+ super(value)
48
44
  end
49
45
 
50
46
  define_method("#{old_attr}_will_change!") do
@@ -137,9 +137,10 @@ module PropertySets
137
137
  end
138
138
 
139
139
  def owner_class=(owner_class_name)
140
- @owner_class_sym = owner_class_name.underscore.to_sym
141
- belongs_to owner_class_sym
142
- validates_presence_of owner_class_sym
140
+ @owner_class_sym = owner_class_name.to_s.demodulize.underscore.to_sym
141
+
142
+ belongs_to owner_class_sym, class_name: owner_class_name
143
+ validates_presence_of owner_class_sym, class_name: owner_class_name
143
144
  validates_uniqueness_of :name, :scope => owner_class_key_sym, :case_sensitive => false
144
145
  attr_accessible owner_class_key_sym, owner_class_sym if defined?(ProtectedAttributes)
145
146
  end
@@ -1,3 +1,3 @@
1
1
  module PropertySets
2
- VERSION = "3.8.0"
2
+ VERSION = "3.10.0"
3
3
  end
data/lib/property_sets.rb CHANGED
@@ -7,22 +7,33 @@ 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
- const_name = "#{owner_class_name}#{association.to_s.singularize.camelcase}".to_sym
16
+ const_name = "#{owner_class_name.demodulize}#{association.to_s.singularize.camelcase}"
17
+ namespace = owner_class_name.deconstantize.safe_constantize || Object
13
18
 
14
- unless Object.const_defined?(const_name)
15
- property_class = Class.new(ActiveRecord::Base) do
19
+ unless namespace.const_defined?(const_name, false)
20
+ property_class = Class.new(parent_for_property_class(namespace, owner_class_name)) do
16
21
  include PropertySets::PropertySetModel::InstanceMethods
17
22
  extend PropertySets::PropertySetModel::ClassMethods
18
23
  end
19
24
 
20
- Object.const_set(const_name, property_class)
25
+ namespace.const_set(const_name, property_class)
21
26
 
22
27
  property_class.owner_class = owner_class_name
23
28
  property_class.owner_assoc = association
24
29
  end
25
30
 
26
- Object.const_get(const_name)
31
+ namespace.const_get(const_name.to_s)
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
27
38
  end
28
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.8.0
4
+ version: 3.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Morten Primdahl
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-17 00:00:00.000000000 Z
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: '4.2'
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: '4.2'
29
+ version: '6.0'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '7.1'
@@ -132,7 +132,7 @@ homepage: http://github.com/zendesk/property_sets
132
132
  licenses:
133
133
  - MIT
134
134
  metadata: {}
135
- post_install_message:
135
+ post_install_message:
136
136
  rdoc_options: []
137
137
  require_paths:
138
138
  - lib
@@ -140,15 +140,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
140
140
  requirements:
141
141
  - - ">="
142
142
  - !ruby/object:Gem::Version
143
- version: '2.4'
143
+ version: '2.7'
144
144
  required_rubygems_version: !ruby/object:Gem::Requirement
145
145
  requirements:
146
146
  - - ">="
147
147
  - !ruby/object:Gem::Version
148
148
  version: '0'
149
149
  requirements: []
150
- rubygems_version: 3.1.6
151
- signing_key:
150
+ rubygems_version: 3.0.3.1
151
+ signing_key:
152
152
  specification_version: 4
153
153
  summary: Property sets for ActiveRecord.
154
154
  test_files: []