- A
- B
- G
- J
- R
- S
Test if rhino_owner
is the auth owner Also available on the instance
Source: show
# File rhino/rhino/lib/rhino/resource/owner.rb 28 def auth_owner? 29 self == Rhino.auth_owner 30 end
Source: show
# File rhino/rhino/lib/rhino/resource/owner.rb 19 def auth_owner_ids 20 owner_ids(:joins_for_auth_owner) 21 end
Test if rhino_owner
is the base owner Also available on the instance
Source: show
# File rhino/rhino/lib/rhino/resource/owner.rb 34 def base_owner? 35 self == Rhino.base_owner 36 end
Source: show
# File rhino/rhino/lib/rhino/resource/owner.rb 15 def base_owner_ids 16 owner_ids(:joins_for_base_owner) 17 end
Test if rhino_owner
is the base owner Also available on the instance
Source: show
# File rhino/rhino/lib/rhino/resource/owner.rb 46 def global_owned? 47 chained_scope = self 48 while !chained_scope.auth_owner? && !chained_scope.base_owner? && !chained_scope.global_owner? 49 chained_scope = chained_scope.resource_owned_by.to_s.classify.safe_constantize 50 end 51 52 chained_scope.global_owner? 53 end
Test if rhino_owner
is the base owner Also available on the instance
Source: show
# File rhino/rhino/lib/rhino/resource/owner.rb 40 def global_owner? 41 self.resource_owned_by == :global 42 end
Source: show
# File rhino/rhino/lib/rhino/resource/owner.rb 127 def joins_for(parent) 128 return {} if parent.to_s.classify == self.to_s.classify 129 130 joins = simple_joins_for(parent) 131 132 joins.inject({}) { |a, n| { n => a } } 133 end
Source: show
# File rhino/rhino/lib/rhino/resource/owner.rb 105 def joins_for_auth_owner 106 return {} if auth_owner? 107 108 # Find the reflection to the auth owner 109 return Rhino.base_to_auth if base_owner? 110 111 joins = simple_joins_for_base_owner 112 113 # Only chain extra to auth if its not the same 114 joins.inject(Rhino.same_owner? ? {} : Rhino.base_to_auth) { |a, n| { n => a } } 115 end
Source: show
# File rhino/rhino/lib/rhino/resource/owner.rb 117 def joins_for_base_owner 118 return {} if base_owner? 119 120 return Rhino.auth_to_base if auth_owner? 121 122 joins = simple_joins_for_base_owner 123 124 joins.inject({}) { |a, n| { n => a } } 125 end
In Rhino
the owner specifies which reference is next in the hierarchy. A resource can only have one owned. This owner will either be global for resources that are not owned by the base owner or a belongs to reference that will eventually lead to the base owner. The resource must respond to send(:owner_name) on the instance unless it is global. Such as:
rhino_owner :user
Will indicate the resource has a has_one reference to user
Examples
# Blog is owned by user
class Blog < ApplicationRecord
include Rhino::Resource::ActiveRecord
rhino_owner :user
end
# BlogPost is owned by Blog
class Blog < ApplicationRecord
include Rhino::Resource::ActiveRecord
rhino_owner :blog
end
# Category is global
class Category < ApplicationRecord
include Rhino::Resource::ActiveRecord
# Can also use rhino_owner_global as a short cut
rhino_owner :global
end
Source: show
# File rhino/rhino/lib/rhino/resource/owner.rb 90 def rhino_owner(name, **_options) 91 self.resource_owned_by = name 92 rhino_policy :global if global_owned? 93 end
Sets rhino_owner
to be the base owner
Source: show
# File rhino/rhino/lib/rhino/resource/owner.rb 96 def rhino_owner_base(...) 97 rhino_owner(Rhino.base_owner.model_name.i18n_key, ...) 98 end
Sets rhino_owner
to be global
Source: show
# File rhino/rhino/lib/rhino/resource/owner.rb 101 def rhino_owner_global(...) 102 rhino_owner(:global, ...) 103 end
Source: show
# File rhino/rhino/lib/rhino/resource/owner.rb 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 146 joins << chained_scope.resource_owned_by 147 148 joins.reverse 149 end