Class: Olivander::Resources::RoutedResource

Inherits:
Object
  • Object
show all
Defined in:
app/controllers/concerns/olivander/resources/route_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 68

def initialize(model, namespaces, crud_actions)
  self.model = model
  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

#actionsObject

Returns the value of attribute actions.



66
67
68
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 66

def actions
  @actions
end

#modelObject

Returns the value of attribute model.



66
67
68
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 66

def model
  @model
end

#namespacesObject

Returns the value of attribute namespaces.



66
67
68
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 66

def namespaces
  @namespaces
end

Instance Method Details

#collection_actionsObject



105
106
107
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 105

def collection_actions
  actions.select { |x| x.collection }
end

#crud_actionsObject



97
98
99
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 97

def crud_actions
  actions.select { |x| x.crud_action }
end

#datatable_bulk_actionsObject



109
110
111
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 109

def datatable_bulk_actions
  collection_actions.select { |x| x.show_in_datatable && !x.crud_action }
end

#member_actionsObject



101
102
103
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 101

def member_actions
  actions.select { |x| !x.collection }
end

#persisted_crud_actionsObject



118
119
120
121
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 118

def persisted_crud_actions
  allowed = %i[show edit destroy]
  crud_actions.select { |x| allowed.include?(x.sym) }
end

#resolve_crud_action_collection(ca) ⇒ Object



93
94
95
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 93

def resolve_crud_action_collection(ca)
  %i[index new create].include?(ca)
end

#resolve_crud_action_verb(ca) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 80

def resolve_crud_action_verb(ca)
  case ca
  when :create
    :post
  when :update
    :patch
  when :destroy
    :delete
  else
    :get
  end
end

#unpersisted_crud_actionsObject



113
114
115
116
# File 'app/controllers/concerns/olivander/resources/route_builder.rb', line 113

def unpersisted_crud_actions
  allowed = %i[index new]
  crud_actions.select { |x| allowed.include?(x.sym) }
end