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



48
49
50
# File 'lib/surrounded/access_control.rb', line 48

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)

Raises:

  • (NoMethodError)


61
62
63
64
65
# File 'lib/surrounded/access_control.rb', line 61

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

#triggersObject

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



54
55
56
57
58
# File 'lib/surrounded/access_control.rb', line 54

def triggers
  all_triggers.select {|name|
    allow?(name)
  }.to_set
end