Class: FatModelAuth::CannedGateKeeper

Inherits:
Object
  • Object
show all
Defined in:
lib/fat_model_auth/canned_gate_keeper.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ CannedGateKeeper

Returns a new instance of CannedGateKeeper.



20
21
22
23
# File 'lib/fat_model_auth/canned_gate_keeper.rb', line 20

def initialize(params)
  @map = {}
  add_rules(params)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/fat_model_auth/canned_gate_keeper.rb', line 32

def method_missing(method, *args)
  unless @map.has_key? method
    raise NoMethodError, "undefined method allows(user).#{method} for #{self.class}"
  end
  
  @map[method].call
end

Class Method Details

.allows(method) ⇒ Object



4
5
6
# File 'lib/fat_model_auth/canned_gate_keeper.rb', line 4

def self.allows(method)
  self.new(method => true)
end

.build(params) ⇒ Object



12
13
14
# File 'lib/fat_model_auth/canned_gate_keeper.rb', line 12

def self.build(params)
  self.new(params)
end

.denies(method) ⇒ Object



8
9
10
# File 'lib/fat_model_auth/canned_gate_keeper.rb', line 8

def self.denies(method)
  self.new(method => false)
end

Instance Method Details

#add_rules(params) ⇒ Object



25
26
27
28
29
30
# File 'lib/fat_model_auth/canned_gate_keeper.rb', line 25

def add_rules(params)
  for param in params
    response = param.pop
    @map["to_#{param.pop}?".to_sym] = lambda { response }
  end
end

#allows(user) ⇒ Object



16
17
18
# File 'lib/fat_model_auth/canned_gate_keeper.rb', line 16

def allows(user)
  self
end