Sha256: 126c590e054f22c0721cbf819243a37a2ea760094378b41117c38bb079b22528

Contents?: true

Size: 1019 Bytes

Versions: 6

Compression:

Stored size: 1019 Bytes

Contents

CanCan::Ability.module_eval do
  def relevant_rules(action, subject, attribute = nil)
    rules.reverse.select do |rule|
      rule.expanded_actions = expand_actions(rule.actions)
      rule.relevant? action, subject, attribute
    end
  end

  def relevant_rules_for_match(action, subject, attribute = nil)
    relevant_rules(action, subject, attribute).each do |rule|
      if rule.only_raw_sql?
        raise ::Exception, "The can? and cannot? call cannot be used with a raw sql 'can' definition. The checking code cannot be determined for #{action.inspect} #{subject.inspect}"
      end
    end
  end

  def can?(action, subject, attribute = nil)
    match = relevant_rules_for_match(action, subject, attribute).detect do |rule|
      rule.matches_conditions?(action, subject, attribute)
    end
    match ? match.base_behavior : false
  end

  def can(*args, &block)
    rules << CanCan::Rule.new(true, *args, &block)
  end

  def cannot(*args, &block)
    rules << CanCan::Rule.new(false, *args, &block)
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
spree_admin_roles_and_access-2.0.0 config/initializers/cancan_ability.rb
spree_admin_roles_and_access-1.3.0 config/initializers/cancan_ability.rb
spree_admin_roles_and_access-1.2.1 config/initializers/cancan_ability.rb
spree_admin_roles_and_access-1.2.0 config/initializers/cancan_ability.rb
spree_admin_roles_and_access-1.1.0 config/initializers/cancan_ability.rb
spree_admin_roles_and_access-1.0.0 config/initializers/cancan_ability.rb