Class: FatModelAuth::GateKeeper
- Inherits:
-
Object
- Object
- FatModelAuth::GateKeeper
- Defined in:
- lib/fat_model_auth/gate_keeper.rb
Defined Under Namespace
Classes: Checker
Instance Method Summary collapse
- #add_rules(params) ⇒ Object
- #check(model, user) ⇒ Object
-
#initialize(params) ⇒ GateKeeper
constructor
A new instance of GateKeeper.
Constructor Details
#initialize(params) ⇒ GateKeeper
Returns a new instance of GateKeeper.
5 6 7 8 |
# File 'lib/fat_model_auth/gate_keeper.rb', line 5 def initialize(params) @map = {} add_rules(params) end |
Instance Method Details
#add_rules(params) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/fat_model_auth/gate_keeper.rb', line 10 def add_rules(params) *methods, = params unless .is_a?(Hash) && ([:if] || [:unless]) raise ArgumentError, 'allows requires an :if or :unless condition' end auth_condition = [:if] || negate([:unless]) methods.each do |method| key = :"to_#{method}?" raise ArgumentError, "rule for :#{method} is already defined" if @map.key?(key) @map[key] = auth_condition end end |