Module: Pundit::Before::ClassMethods

Defined in:
lib/pundit/before.rb

Instance Method Summary collapse

Instance Method Details

#_normalize_callback_option(options, from, to) ⇒ Object



80
81
82
83
84
85
# File 'lib/pundit/before.rb', line 80

def _normalize_callback_option(options, from, to)
  return unless (from = options.delete(from))

  from = CallbackFilter.new(from)
  options[to] = Array(options[to]).unshift(from)
end

#_normalize_callback_options(options) ⇒ Object



75
76
77
78
# File 'lib/pundit/before.rb', line 75

def _normalize_callback_options(options)
  _normalize_callback_option(options, :only, :if)
  _normalize_callback_option(options, :except, :unless)
end

#before(*method_names, **options, &block) ⇒ Object



60
61
62
63
64
65
66
67
68
# File 'lib/pundit/before.rb', line 60

def before(*method_names, **options, &block)
  _normalize_callback_options(options)

  if block_given?
    set_callback :_pundit_before, :before, **options, &block
  else
    set_callback :_pundit_before, :before, *method_names, **options
  end
end

#skip_before(*method_names, **options) ⇒ Object



70
71
72
73
# File 'lib/pundit/before.rb', line 70

def skip_before(*method_names, **options)
  _normalize_callback_options(options)
  skip_callback :_pundit_before, :before, *method_names, **options
end