rhino_project_core 0.21.0.beta.44 → 0.21.0.beta.46

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: ab10733b21c66a2aa8ac802f0e041d62eb4be44965b2ad20450d65ded5b4810f
4
- data.tar.gz: f054c012a1b61256105da6d82fcd2c334708d53d9fe3f35cfb8806552032f2b5
3
+ metadata.gz: 5523b3587da0f1a5099bb649e0f1243a716a85b27379372ab513c9beb759f3fa
4
+ data.tar.gz: be28497ecfe5fec48183bdddab3b5a13f4e4c0d4a3fa0e2c01bc9153509bf31e
5
5
  SHA512:
6
- metadata.gz: 309de9afa5962ba4ab8cf68d1955b1632d6367270b98298265586265a364b0be933a7c3b7420f4b8e05d8051df9a8caa26a7b190eab17590bf7fb3ad2e08a00c
7
- data.tar.gz: 29fde4a30fd5349843a65a3686909994ef7e4ffc7a63430339c1a3f7d70a067a0d1adf96ebb4875b6794dcc27702cd4d8e2c4bb92f9b106cb4a6dc31d5b69845
6
+ metadata.gz: f5728dd8cc8a7cd570b01af965bd87365f216910ac66011b40023d1e8a632be9edf4275de5b66ed1d89ea054c741e6ea55b0393fd1f848c3ee2d8fa5933009f3
7
+ data.tar.gz: 5a10bba5d890d5f71d8930b34e65de0094130c7b477ffcfc5121877e432103107e45fbf2b360cd4b11bfb1e3741cebe78962b902a7edb47d4ebc554f6890d0cb
@@ -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'
@@ -23,6 +24,7 @@ module Rhino
23
24
  include Rhino::Resource::ActiveRecordExtension::Reference
24
25
  include Rhino::Resource::ActiveRecordExtension::Describe
25
26
  include Rhino::Resource::ActiveRecordExtension::Routing
27
+ include Rhino::Resource::ActiveRecordExtension::Owner
26
28
  include Rhino::Resource::ActiveRecordExtension::Params
27
29
  include Rhino::Resource::ActiveRecordExtension::Serialization
28
30
  include Rhino::Resource::ActiveRecordExtension::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
@@ -89,7 +89,6 @@ module Rhino
89
89
  #
90
90
  def rhino_owner(name, **_options)
91
91
  self.resource_owned_by = name
92
- rhino_policy :global if global_owned?
93
92
  end
94
93
 
95
94
  # Sets rhino_owner[rdoc-ref:rhino_owner] to be the base owner
@@ -133,40 +132,40 @@ module Rhino
133
132
  end
134
133
 
135
134
  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
135
+ def simple_joins_for(parent)
136
+ # FIXME: There is probably a more rubyish way to do this
137
+ chained_scope = self
138
+ joins = []
139
+
140
+ # The ownership could be a many, so we classify first
141
+ while chained_scope.resource_owned_by.to_s.classify != parent.to_s.classify
142
+ joins << chained_scope.resource_owned_by
143
+ chained_scope = chained_scope.resource_owned_by.to_s.classify.constantize
144
+ end
143
145
  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
146
 
148
- joins.reverse
149
- end
147
+ joins.reverse
148
+ end
150
149
 
151
- def simple_joins_for_base_owner
152
- simple_joins_for(Rhino.base_owner)
153
- end
150
+ def simple_joins_for_base_owner
151
+ simple_joins_for(Rhino.base_owner)
152
+ end
154
153
  end
155
154
  # rubocop:enable Style/RedundantSelf
156
155
  end
157
156
 
158
157
  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
158
+ # We use the parent as the starting point because if the record is not
159
+ # persisted yet, we won't be able to find it
160
+ def owner_ids(joins)
161
+ bo = Rhino.base_owner
163
162
 
164
- return [] unless owner
163
+ return [] unless owner
165
164
 
166
- parent_klass = owner.class
167
- pk = parent_klass.primary_key
165
+ parent_klass = owner.class
166
+ pk = parent_klass.primary_key
168
167
 
169
- parent_klass.joins(parent_klass.send(joins)).where("#{pk}": owner[pk]).pluck("#{bo.table_name}.#{bo.primary_key}")
170
- end
168
+ parent_klass.joins(parent_klass.send(joins)).where("#{pk}": owner[pk]).pluck("#{bo.table_name}.#{bo.primary_key}")
169
+ end
171
170
  end
172
171
  end
@@ -1,15 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'resource/owner'
4
- require_relative 'resource/properties'
5
- require_relative 'resource/reference'
6
- require_relative 'resource/describe'
7
- require_relative 'resource/routing'
8
- require_relative 'resource/params'
9
- require_relative 'resource/serialization'
10
- require_relative 'resource/sieves'
3
+ require_relative "resource/owner"
4
+ require_relative "resource/properties"
5
+ require_relative "resource/reference"
6
+ require_relative "resource/describe"
7
+ require_relative "resource/routing"
8
+ require_relative "resource/params"
9
+ require_relative "resource/serialization"
10
+ require_relative "resource/sieves"
11
11
 
12
- require_relative '../../app/policies/rhino/crud_policy'
12
+ require_relative "../../app/policies/rhino/crud_policy"
13
13
 
14
14
  module Rhino
15
15
  module Resource
@@ -25,7 +25,7 @@ module Rhino
25
25
  include Rhino::Resource::Sieves
26
26
 
27
27
  included do
28
- class_attribute :_policy_class, default: Rhino::CrudPolicy
28
+ class_attribute :_policy_class
29
29
 
30
30
  def owner
31
31
  send self.class.resource_owned_by
@@ -41,7 +41,11 @@ module Rhino
41
41
 
42
42
  class_methods do
43
43
  def policy_class
44
- _policy_class
44
+ self._policy_class ||= begin
45
+ return Rhino::GlobalPolicy if global_owned?
46
+
47
+ Rhino::CrudPolicy
48
+ end
45
49
  end
46
50
 
47
51
  def rhino_policy(policy)
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.46"
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.46
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