Module: Surrounded::AccessControl::AccessMethods

Defined in:
lib/surrounded/access_control.rb

Instance Method Summary collapse

Instance Method Details

#all_triggersObject

Return a Set of all defined triggers regardless of any disallow blocks



50
51
52
# File 'lib/surrounded/access_control.rb', line 50

def all_triggers
  self.class.triggers
end

#allow?(name) ⇒ Boolean

Ask if the context will allow access to a trigger given the current players.

Returns:

  • (Boolean)


64
65
66
67
68
69
70
71
72
73
# File 'lib/surrounded/access_control.rb', line 64

def allow?(name)
  unless self.respond_to?(name)
    raise NoMethodError, %{undefined method `#{name}' for #{self.inspect}}
  end
  if self.respond_to?("disallow_#{name}?")
    !self.public_send("disallow_#{name}?")
  else
    true
  end
end

#triggersObject

Return a Set of triggers which may be run according to any restrictions defined in disallow blocks.



56
57
58
59
60
61
# File 'lib/surrounded/access_control.rb', line 56

def triggers
  all_triggers.select {|name|
    method_restrictor = "disallow_#{name}?"
    !self.respond_to?(method_restrictor, true) || !self.send(method_restrictor)
  }.to_set
end