Class: AccessAllow::Check

Inherits:
Object
  • Object
show all
Defined in:
lib/access_allow/check.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, ability_namespace, ability_name) ⇒ Check

Returns a new instance of Check.



22
23
24
25
26
27
# File 'lib/access_allow/check.rb', line 22

def initialize(user, ability_namespace, ability_name)
  @user = user
  @ability_manager = user ? AccessAllow::AbilitiesManager.new(user) : nil
  @ability_namespace = ability_namespace.to_sym
  @ability_name = ability_name.to_sym
end

Class Method Details

.call(user, config) ⇒ Object



6
7
8
# File 'lib/access_allow/check.rb', line 6

def call(user, config)
  build_perms_checker(user, config).possible?
end

.call!(user, config) ⇒ Object



10
11
12
# File 'lib/access_allow/check.rb', line 10

def call!(user, config)
  build_perms_checker(user, config).possible!
end

Instance Method Details

#possible!Object



37
38
39
# File 'lib/access_allow/check.rb', line 37

def possible!
  possible? || raise(AccessAllow::ViolationError, error_message(false))
end

#possible?Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
35
# File 'lib/access_allow/check.rb', line 29

def possible?
  unless user
    Rails.logger.info error_message(false)
    return false
  end
  ability_manager.has?(ability_namespace, ability_name).tap { |can| Rails.logger.info error_message(can) unless can }
end