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



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

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)


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

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

#triggersObject

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



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

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