lib/surrounded/context/role_builders.rb in surrounded-0.9.4 vs lib/surrounded/context/role_builders.rb in surrounded-0.9.5
- old
+ new
@@ -11,11 +11,11 @@
else
meth = method(type)
meth.call(name, &block)
end
rescue NameError => e
- raise e.extend(InvalidRoleType)
+ raise InvalidRoleType, e.message
end
alias_method :role_methods, :role
# Create a named behavior for a role using the standard library SimpleDelegator.
def wrap(name, &block)
@@ -34,23 +34,25 @@
klass = private_const_set(wrapper_name, DelegateClass(Object.const_get(class_name.to_s)))
klass.class_eval(&block)
klass.send(:include, Surrounded)
end
- # Create an object which will bind methods to the role player
+ # Create an object which will bind methods to the role player.
+ #
+ # This object will behave differently that a wrapper or delegate_class.
+ # The interface object should only be used for objects whose methods
+ # _will not_ call to the other objects in the context.
+ # Because the interface methods are applied individually to an object,
+ # that object is unaware of the other objects in the context and cannot
+ # access them from any of its methods.
def interface(name, &block)
# AdminInterface
interface_name = RoleName(name, 'Interface')
behavior = private_const_set(interface_name, Module.new(&block))
require 'surrounded/context/negotiator'
- undef_method(name)
-
- # AdminInterfaceProxy
- proxy = private_const_set(RoleName(interface_name, 'Proxy'), Negotiator.for_role(behavior))
- define_method(name) do
- instance_variable_set("@#{name}", proxy.new(role_map.assigned_player(name), behavior))
- end
+ # Admin
+ private_const_set(RoleName(name), Negotiator.for_role(behavior))
end
private
def RoleName(text, suffix=nil)
RoleName.new(text, suffix)
\ No newline at end of file