module Lucky::ActionPipes

Direct including types

Defined in:

lucky/action_pipes.cr

Instance Method Summary

Macro Summary

Instance Method Detail

def continue : Lucky::ActionPipes::Continue #

Call this in a pipe to continue to the next pipe or action


[View source]

Macro Detail

macro after(method_name) #

Run a method after an action ends

after isn't as common as before but can still be useful. One example would be to log a successful transaction to analytics. Methods will run in the order that each after is defined. Also, each method must return either a Lucky::Response like redirect, html, json, etc, or call #continue:

class Purchases::Create < BrowserAction
  after log_transaction

  post "/purchases" do
    # purchase the product
  end

  def log_transaction
    # send the purchase to analytics
    continue
  end
end

[View source]
macro before(method_name) #

Run a method before an action is called

Methods will run in the order that each before is defined. Also, each method must return a Lucky::Response like redirect, html, json, etc, or call #continue:

class Users::Destroy < BrowserAction
  before check_if_signed_in
  before confirm_destroy

  delete "/:user_id" do
    # destroy the user :(
  end

  def check_if_signed_in
    if current_user.nil?
      redirect to: SignInPage
    else
      continue
    end
  end

  def confirm_destroy
    # confirm that the user should be destroyed
    continue
  end
end

[View source]
macro skip(*pipes) #

Skips before or after pipes

skip require_sign_in, require_organization

[View source]