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.



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

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



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

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



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

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

.build(params) ⇒ Object



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

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

.denies(method) ⇒ Object



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

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

Instance Method Details

#add_rules(params) ⇒ Object



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

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

#allows(user) ⇒ Object



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

def allows(user)
  self
end