Class: Avo::Index::ResourceControlsComponent
- Inherits:
-
ResourceComponent
- Object
- ResourceComponent
- Avo::Index::ResourceControlsComponent
- Defined in:
- app/components/avo/index/resource_controls_component.rb
Instance Method Summary collapse
- #can_detach? ⇒ Boolean
- #can_edit? ⇒ Boolean
- #can_view? ⇒ Boolean
- #edit_path ⇒ Object
-
#initialize(resource: nil, reflection: nil, parent_model: nil) ⇒ ResourceControlsComponent
constructor
A new instance of ResourceControlsComponent.
- #parent_resource ⇒ Object
- #show_path ⇒ Object
- #singular_resource_name ⇒ Object
Constructor Details
#initialize(resource: nil, reflection: nil, parent_model: nil) ⇒ ResourceControlsComponent
Returns a new instance of ResourceControlsComponent.
4 5 6 7 8 |
# File 'app/components/avo/index/resource_controls_component.rb', line 4 def initialize(resource: nil, reflection: nil, parent_model: nil) @resource = resource @reflection = reflection @parent_model = parent_model end |
Instance Method Details
#can_detach? ⇒ Boolean
10 11 12 13 14 15 |
# File 'app/components/avo/index/resource_controls_component.rb', line 10 def can_detach? @reflection.present? && @resource.model.present? && (@reflection.is_a?(::ActiveRecord::Reflection::HasManyReflection) || @reflection.is_a?(::ActiveRecord::Reflection::ThroughReflection)) && ("detach") end |
#can_edit? ⇒ Boolean
17 18 19 |
# File 'app/components/avo/index/resource_controls_component.rb', line 17 def can_edit? @resource..(:edit, raise_exception: false) end |
#can_view? ⇒ Boolean
21 22 23 |
# File 'app/components/avo/index/resource_controls_component.rb', line 21 def can_view? @resource..(:show, raise_exception: false) end |
#edit_path ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/components/avo/index/resource_controls_component.rb', line 38 def edit_path args = {} if @parent_model.present? args = { via_resource_class: parent_resource.model_class, via_resource_id: @parent_model.id } end helpers.edit_resource_path(model: @resource.model, resource: @resource, **args) end |
#parent_resource ⇒ Object
59 60 61 62 63 |
# File 'app/components/avo/index/resource_controls_component.rb', line 59 def parent_resource return nil if @parent_model.blank? ::Avo::App.get_resource_by_model_name @parent_model.class end |
#show_path ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/components/avo/index/resource_controls_component.rb', line 25 def show_path args = {} if @parent_model.present? args = { via_resource_class: parent_resource.model_class, via_resource_id: @parent_model.id } end helpers.resource_path(model: @resource.model, resource: @resource, **args) end |
#singular_resource_name ⇒ Object
51 52 53 54 55 56 57 |
# File 'app/components/avo/index/resource_controls_component.rb', line 51 def singular_resource_name if @reflection.present? ::Avo::App.get_resource_by_model_name(@reflection.class_name).name else @resource.singular_name.present? ? @resource.singular_name : @resource.model_class.model_name.name.downcase end end |