module Algernon::Routing::Route

Public Instance Methods

detect_action(options) click to toggle source
# File lib/algernon/routing/route.rb, line 23
def detect_action(options)
  actions = [:index, :new, :create, :show, :edit, :update, :destroy]
  actions -= options[:except] if options.key?(:except)
  actions &= options[:only] if options.key?(:only)
  actions
end
resources(controller, options = {}) click to toggle source
# File lib/algernon/routing/route.rb, line 8
def resources(controller, options = {})
  actions = detect_action(options)

  # rubocop:disable Metrics/LineLength
  get("/#{controller}", to: "#{controller}#index") if actions.include?(:index)
  get("/#{controller}/new", to: "#{controller}#new") if actions.include?(:new)
  post("/#{controller}", to: "#{controller}#create") if actions.include?(:create)
  get("/#{controller}/:id", to: "#{controller}#show") if actions.include?(:show)
  get("/#{controller}/:id/edit", to: "#{controller}#edit") if actions.include?(:edit)
  put("/#{controller}/:id", to: "#{controller}#update") if actions.include?(:update)
  patch("/#{controller}/:id", to: "#{controller}#update") if actions.include?(:update)
  delete("/#{controller}/:id", to: "#{controller}#destroy") if actions.include?(:destroy)
  # rubocop:enable Metrics/LineLength
end
root(target) click to toggle source
# File lib/algernon/routing/route.rb, line 4
def root(target)
  get("/", to: target)
end