Module: ActionPolicy::Graphiti::ResourceAnalyzer
- Defined in:
- lib/action_policy/graphiti/resource_analyzer.rb
Overview
A helper module used to get resource details
Class Method Summary collapse
- .base_model_name(polymorphic_resource) ⇒ Object
- .base_resource_class(polymorphic_resource) ⇒ Object
- .model_name(resource) ⇒ Object
- .resource_class(resource) ⇒ Object
Class Method Details
.base_model_name(polymorphic_resource) ⇒ Object
29 30 31 |
# File 'lib/action_policy/graphiti/resource_analyzer.rb', line 29 def self.base_model_name(polymorphic_resource) base_resource_class(polymorphic_resource)&.name&.delete_suffix("Resource") end |
.base_resource_class(polymorphic_resource) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/action_policy/graphiti/resource_analyzer.rb', line 15 def self.base_resource_class(polymorphic_resource) return unless ResourceValidator.polymorphic_graphiti_resource?(polymorphic_resource) resource_class = polymorphic_resource.is_a?(Class) ? polymorphic_resource : polymorphic_resource.class polymorphic_marker_index = resource_class.ancestors.find_index(::Graphiti::Resource::Polymorphism) resource_class.ancestors[polymorphic_marker_index + 1] end |
.model_name(resource) ⇒ Object
25 26 27 |
# File 'lib/action_policy/graphiti/resource_analyzer.rb', line 25 def self.model_name(resource) resource_class(resource)&.name&.delete_suffix("Resource") end |
.resource_class(resource) ⇒ Object
9 10 11 12 13 |
# File 'lib/action_policy/graphiti/resource_analyzer.rb', line 9 def self.resource_class(resource) return unless ResourceValidator.graphiti_resource?(resource) resource.is_a?(Class) ? resource : resource.class end |