Class: Olivander::Resources::RoutedResource
- Inherits:
-
Object
- Object
- Olivander::Resources::RoutedResource
- Defined in:
- app/controllers/concerns/olivander/resources/route_builder.rb
Instance Attribute Summary collapse
-
#actions ⇒ Object
Returns the value of attribute actions.
-
#model ⇒ Object
Returns the value of attribute model.
-
#namespaces ⇒ Object
Returns the value of attribute namespaces.
-
#nested_models ⇒ Object
Returns the value of attribute nested_models.
Instance Method Summary collapse
- #collection_actions ⇒ Object
- #crud_actions ⇒ Object
- #datatable_bulk_actions ⇒ Object
-
#initialize(model, namespaces, crud_actions) ⇒ RoutedResource
constructor
A new instance of RoutedResource.
- #member_actions ⇒ Object
- #persisted_crud_actions ⇒ Object
- #resolve_crud_action_collection(ca) ⇒ Object
- #resolve_crud_action_verb(ca) ⇒ Object
- #unpersisted_crud_actions ⇒ Object
Constructor Details
#initialize(model, namespaces, crud_actions) ⇒ RoutedResource
Returns a new instance of RoutedResource.
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 68 def initialize(model, namespaces, crud_actions) self.model = model self.nested_models = [] self.namespaces = namespaces self.actions = [] %i[index new create edit show update destroy].each do |ca| next unless crud_actions.include?(ca) actions << ResourceAction.new(ca, controller: model, verb: resolve_crud_action_verb(ca), collection: resolve_crud_action_collection(ca), crud_action: true) end end |
Instance Attribute Details
#actions ⇒ Object
Returns the value of attribute actions.
66 67 68 |
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 66 def actions @actions end |
#model ⇒ Object
Returns the value of attribute model.
66 67 68 |
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 66 def model @model end |
#namespaces ⇒ Object
Returns the value of attribute namespaces.
66 67 68 |
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 66 def namespaces @namespaces end |
#nested_models ⇒ Object
Returns the value of attribute nested_models.
66 67 68 |
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 66 def nested_models @nested_models end |
Instance Method Details
#collection_actions ⇒ Object
106 107 108 |
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 106 def collection_actions actions.select { |x| x.collection } end |
#crud_actions ⇒ Object
98 99 100 |
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 98 def crud_actions actions.select { |x| x.crud_action } end |
#datatable_bulk_actions ⇒ Object
110 111 112 |
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 110 def datatable_bulk_actions collection_actions.select { |x| x.show_in_datatable && !x.crud_action } end |
#member_actions ⇒ Object
102 103 104 |
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 102 def member_actions actions.select { |x| !x.collection } end |
#persisted_crud_actions ⇒ Object
119 120 121 122 |
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 119 def persisted_crud_actions allowed = %i[show edit destroy] crud_actions.select { |x| allowed.include?(x.sym) } end |
#resolve_crud_action_collection(ca) ⇒ Object
94 95 96 |
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 94 def resolve_crud_action_collection(ca) %i[index new create].include?(ca) end |
#resolve_crud_action_verb(ca) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 81 def resolve_crud_action_verb(ca) case ca when :create :post when :update :patch when :destroy :delete else :get end end |
#unpersisted_crud_actions ⇒ Object
114 115 116 117 |
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 114 def unpersisted_crud_actions allowed = %i[index new] crud_actions.select { |x| allowed.include?(x.sym) } end |