Module: Surrounded::Context::InstanceMethods

Defined in:
lib/surrounded/context.rb

Instance Method Summary collapse

Instance Method Details

#rebind(**options_hash) ⇒ Object

Reuse the same context object but pass new values



109
110
111
112
113
114
115
116
117
# File 'lib/surrounded/context.rb', line 109

def rebind(**options_hash)
  clear_instance_variables
  begin
    initialize(**options_hash)
  rescue ArgumentError
    initialize(*options_hash.values)
  end
  self
end

#role?(name, &block) ⇒ Boolean

Check whether a given name is a role inside the context. The provided block is used to evaluate whether or not the caller is allowed to inquire about the roles.

Returns:

  • (Boolean)


92
93
94
95
96
# File 'lib/surrounded/context.rb', line 92

def role?(name, &block)
  return false unless role_map.role?(name)
  accessor = block.binding.eval('self')
  role_map.role_player?(accessor) && role_map.assigned_player(name)
end

#role_player?(obj) ⇒ Boolean

Check if a given object is a role player in the context.

Returns:

  • (Boolean)


99
100
101
# File 'lib/surrounded/context.rb', line 99

def role_player?(obj)
  role_map.role_player?(obj)
end

#triggersObject

Return a Set of all defined triggers



104
105
106
# File 'lib/surrounded/context.rb', line 104

def triggers
  self.class.triggers
end