Sha256: 954e079e2ba8e9b9ab5f71b67e07aadf80fa638ae9aa7eec85c1d963f960e47c

Contents?: true

Size: 688 Bytes

Versions: 31

Compression:

Stored size: 688 Bytes

Contents

module Deny
  extend ActiveSupport::Concern

  # es.
  # 
  # deny! :if => user.logged_in?
  # deny! :if => -> { ... }
  # deny!
  #
  # before_filter :deny! :if => :guest?
  #
  # def guest?
  #   !current_user
  # end
  
  def deny!(options = {})
    negate = false
    expr = if options.has_key?(:if)
      options.delete(:if)
    elsif options.has_key?(:unless)
      negate = true
      options.delete(:unless)
    else
      true
    end

    condition = if expr.is_a?(Proc)
      expr.arity != 0 ? expr.call(self) : expr.call
    else
      expr
    end
    condition = negate ? !condition : condition
  
    if condition
      raise DeniedError.new
    end
 
    false
  end

end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
fullstack-cms-0.4.6 app/support/deny.rb
fullstack-cms-0.4.5 app/support/deny.rb
fullstack-cms-0.4.4 app/support/deny.rb
fullstack-cms-0.4.3 app/support/deny.rb
fullstack-cms-0.4.2 app/support/deny.rb
fullstack-cms-0.4.1 app/support/deny.rb
fullstack-cms-0.3.39 app/support/deny.rb
fullstack-cms-0.3.38 app/support/deny.rb
fullstack-cms-0.3.37 app/support/deny.rb
fullstack-cms-0.3.36 app/support/deny.rb
fullstack-cms-0.3.35 app/support/deny.rb
fullstack-cms-0.3.34 app/support/deny.rb
fullstack-cms-0.3.33 app/support/deny.rb
fullstack-cms-0.3.32 app/support/deny.rb
fullstack-cms-0.3.31 app/support/deny.rb
fullstack-cms-0.3.30 app/support/deny.rb
fullstack-cms-0.3.29 app/support/deny.rb
fullstack-cms-0.3.28 app/support/deny.rb
fullstack-cms-0.3.27 app/support/deny.rb
fullstack-cms-0.3.26 app/support/deny.rb