rhino_project_core 0.21.0.beta.44 → 0.21.0.beta.45

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: ab10733b21c66a2aa8ac802f0e041d62eb4be44965b2ad20450d65ded5b4810f
4
- data.tar.gz: f054c012a1b61256105da6d82fcd2c334708d53d9fe3f35cfb8806552032f2b5
3
+ metadata.gz: 2067ef29a2dafd97f80be50db1bd8d96de7826914480ffe7b2455afb3a2c3846
4
+ data.tar.gz: 9847bf820bd6b94b0affb6fc0a98778fad403de9b431ab0dc7fa0c4812232a69
5
5
  SHA512:
6
- metadata.gz: 309de9afa5962ba4ab8cf68d1955b1632d6367270b98298265586265a364b0be933a7c3b7420f4b8e05d8051df9a8caa26a7b190eab17590bf7fb3ad2e08a00c
7
- data.tar.gz: 29fde4a30fd5349843a65a3686909994ef7e4ffc7a63430339c1a3f7d70a067a0d1adf96ebb4875b6794dcc27702cd4d8e2c4bb92f9b106cb4a6dc31d5b69845
6
+ metadata.gz: 5eceb42ab45721610b6d13f0fe81b8c49db1272b5b5b1f9ff61dfa0aec10980c598832222cd06af2bad04fd693ca34de7acccd6091e205c750bc94569b9d53e6
7
+ data.tar.gz: 807591098866d30ea4843849292f5efe54ac4e44e486775039403eb4a1f4e3a58fa80eed31f6e0c61e2a42334b030b45c882f1c7cc0a5a69a85599a9c151a2ad
@@ -26,7 +26,7 @@ module Rhino
26
26
  g.vertex_iterator { |c| Rhino.resource_classes.each(&c) }
27
27
 
28
28
  # If its owned by another resoource, link it
29
- g.adjacent_iterator { |v, c| c.call(v.resource_owned_by.to_s.camelize.constantize) if v&.resource_owned_by && !v.global_owner? }
29
+ g.adjacent_iterator { |v, c| c.call(v.owner_class) if v&.resource_owned_by && !v.global_owner? }
30
30
 
31
31
  g.directed = true
32
32
  end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rhino
4
+ module Resource
5
+ module ActiveRecordExtension
6
+ module Owner
7
+ extend ActiveSupport::Concern
8
+
9
+ # The self is actually required to work with class_attribute properly
10
+ class_methods do
11
+ def owner_class
12
+ reflect_on_association(resource_owned_by).klass
13
+ end
14
+
15
+ # Test if rhino_owner[rdoc-ref:rhino_owner] is the global owner
16
+ # Also available on the instance
17
+ def global_owned?
18
+ chained_scope = self
19
+ while !chained_scope.auth_owner? && !chained_scope.base_owner? && !chained_scope.global_owner?
20
+ chained_scope = chained_scope.owner_class
21
+ end
22
+
23
+ chained_scope.global_owner?
24
+ end
25
+
26
+ private
27
+ def simple_joins_for(parent)
28
+ # FIXME: There is probably a more rubyish way to do this
29
+ chained_scope = self
30
+ joins = []
31
+
32
+ # The ownership could be a many, so we classify first
33
+ while chained_scope.owner_class.name != parent.to_s.classify
34
+ joins << chained_scope.resource_owned_by
35
+ chained_scope = chained_scope.owner_class
36
+ end
37
+ joins << chained_scope.resource_owned_by
38
+
39
+ joins.reverse
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -5,6 +5,7 @@ require_relative 'active_record_extension/properties'
5
5
  require_relative 'active_record_extension/reference'
6
6
  require_relative 'active_record_extension/describe'
7
7
  require_relative 'active_record_extension/routing'
8
+ require_relative 'active_record_extension/owner'
8
9
  require_relative 'active_record_extension/params'
9
10
  require_relative 'active_record_extension/serialization'
10
11
  require_relative 'active_record_extension/search'
@@ -35,13 +35,13 @@ module Rhino
35
35
  self == Rhino.base_owner
36
36
  end
37
37
 
38
- # Test if rhino_owner[rdoc-ref:rhino_owner] is the base owner
38
+ # Test if rhino_owner[rdoc-ref:rhino_owner] is the global owner
39
39
  # Also available on the instance
40
40
  def global_owner?
41
41
  self.resource_owned_by == :global
42
42
  end
43
43
 
44
- # Test if rhino_owner[rdoc-ref:rhino_owner] is the base owner
44
+ # Test if rhino_owner[rdoc-ref:rhino_owner] is globally owned at the top of the hierarchy
45
45
  # Also available on the instance
46
46
  def global_owned?
47
47
  chained_scope = self
@@ -133,40 +133,40 @@ module Rhino
133
133
  end
134
134
 
135
135
  private
136
- def simple_joins_for(parent)
137
- # FIXME: There is probably a more rubyish way to do this
138
- chained_scope = self
139
- joins = []
140
-
141
- # The ownership could be a many, so we classify first
142
- while chained_scope.resource_owned_by.to_s.classify != parent.to_s.classify
136
+ def simple_joins_for(parent)
137
+ # FIXME: There is probably a more rubyish way to do this
138
+ chained_scope = self
139
+ joins = []
140
+
141
+ # The ownership could be a many, so we classify first
142
+ while chained_scope.resource_owned_by.to_s.classify != parent.to_s.classify
143
+ joins << chained_scope.resource_owned_by
144
+ chained_scope = chained_scope.resource_owned_by.to_s.classify.constantize
145
+ end
143
146
  joins << chained_scope.resource_owned_by
144
- chained_scope = chained_scope.resource_owned_by.to_s.classify.constantize
145
- end
146
- joins << chained_scope.resource_owned_by
147
147
 
148
- joins.reverse
149
- end
148
+ joins.reverse
149
+ end
150
150
 
151
- def simple_joins_for_base_owner
152
- simple_joins_for(Rhino.base_owner)
153
- end
151
+ def simple_joins_for_base_owner
152
+ simple_joins_for(Rhino.base_owner)
153
+ end
154
154
  end
155
155
  # rubocop:enable Style/RedundantSelf
156
156
  end
157
157
 
158
158
  private
159
- # We use the parent as the starting point because if the record is not
160
- # persisted yet, we won't be able to find it
161
- def owner_ids(joins)
162
- bo = Rhino.base_owner
159
+ # We use the parent as the starting point because if the record is not
160
+ # persisted yet, we won't be able to find it
161
+ def owner_ids(joins)
162
+ bo = Rhino.base_owner
163
163
 
164
- return [] unless owner
164
+ return [] unless owner
165
165
 
166
- parent_klass = owner.class
167
- pk = parent_klass.primary_key
166
+ parent_klass = owner.class
167
+ pk = parent_klass.primary_key
168
168
 
169
- parent_klass.joins(parent_klass.send(joins)).where("#{pk}": owner[pk]).pluck("#{bo.table_name}.#{bo.primary_key}")
170
- end
169
+ parent_klass.joins(parent_klass.send(joins)).where("#{pk}": owner[pk]).pluck("#{bo.table_name}.#{bo.primary_key}")
170
+ end
171
171
  end
172
172
  end
data/lib/rhino/version.rb CHANGED
@@ -10,7 +10,7 @@ module Rhino
10
10
  MAJOR = 0
11
11
  MINOR = 21
12
12
  TINY = 0
13
- PRE = "beta.44"
13
+ PRE = "beta.45"
14
14
 
15
15
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
16
16
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rhino_project_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.21.0.beta.44
4
+ version: 0.21.0.beta.45
5
5
  platform: ruby
6
6
  authors:
7
7
  - JP Rosevear
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-23 00:00:00.000000000 Z
11
+ date: 2024-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -465,6 +465,7 @@ files:
465
465
  - lib/rhino/resource/active_model_extension/serialization.rb
466
466
  - lib/rhino/resource/active_record_extension.rb
467
467
  - lib/rhino/resource/active_record_extension/describe.rb
468
+ - lib/rhino/resource/active_record_extension/owner.rb
468
469
  - lib/rhino/resource/active_record_extension/params.rb
469
470
  - lib/rhino/resource/active_record_extension/properties.rb
470
471
  - lib/rhino/resource/active_record_extension/properties_describe.rb