lib/surrounded/context.rb in surrounded-0.9.9 vs lib/surrounded/context.rb in surrounded-0.9.10
- old
+ new
@@ -5,10 +5,11 @@
require 'surrounded/context/forwarding'
require 'surrounded/context/trigger_controls'
require 'surrounded/access_control'
require 'surrounded/shortcuts'
require 'surrounded/east_oriented'
+require 'surrounded/context/name_collision_detector'
# Extend your classes with Surrounded::Context to handle their
# initialization and application of behaviors to the role players
# passed into the constructor.
#
@@ -16,25 +17,37 @@
# which encapsulate the interaction and behavior of objects inside.
module Surrounded
module Context
def self.extended(base)
base.class_eval {
- extend RoleBuilders, Initializing, Forwarding
+ extend RoleBuilders, Initializing, Forwarding, NameCollisionDetector
@triggers = Set.new
include InstanceMethods
trigger_mod = Module.new
const_set('TriggerMethods', trigger_mod)
include trigger_mod
extend TriggerControls
+
}
+ define_exceptions(base)
end
private
+ def self.define_exceptions(klass)
+ self.constants.select{|const|
+ self.const_get(const) < ::StandardError
+ }.map{|exception|
+ unless klass.const_defined?(exception)
+ klass.const_set(exception, Class.new(self.const_get(exception)))
+ end
+ }
+ end
+
# Set the default type of implementation for role methods for all contexts.
def self.default_role_type
@default_role_type ||= :module
end
@@ -133,9 +146,10 @@
def role_map
@role_map ||= role_mapper_class.new
end
def map_roles(role_object_array)
+ detect_collisions role_object_array
role_object_array.to_a.each do |role, object|
if self.respond_to?("map_role_#{role}")
self.send("map_role_#{role}", object)
else
map_role(role, role_behavior_name(role), object)
\ No newline at end of file