lib/reality/facets/target_manager.rb in reality-facets-1.3.0 vs lib/reality/facets/target_manager.rb in reality-facets-1.4.0
- old
+ new
@@ -25,11 +25,11 @@
@inverse_access_method = (options[:inverse_access_method] || @key).to_sym
@container_key = container_key.nil? ? nil : container_key.to_sym
@extension_module = nil
if @container_key && !target_manager.target_by_key?(@container_key)
- raise "Target '#{key}' defines container as '#{@container_key}' but no such target exists."
+ Reality::Facets.error("Target '#{key}' defines container as '#{@container_key}' but no such target exists.")
end
@target_manager.send(:register_target, self)
end
@@ -52,12 +52,12 @@
end
@extension_module
end
def apply_extension_to(object)
- raise "Can not apply extension to model object of type #{object.class} as it is not of expected model type #{model_class.name} for target #{key}" unless object.is_a?(model_class)
- raise "Attempted to apply extension multiple time to model object of type #{model_class.name} for target #{key}" if object.instance_variable_defined?('@facet_extension_active')
+ Reality::Facets.error("Can not apply extension to model object of type #{object.class} as it is not of expected model type #{model_class.name} for target #{key}") unless object.is_a?(model_class)
+ Reality::Facets.error("Attempted to apply extension multiple time to model object of type #{model_class.name} for target #{key}") if object.instance_variable_defined?('@facet_extension_active')
object.class.send(:include, extension_module)
object.instance_variable_set('@facet_container', target_manager.container)
object.instance_variable_set('@facet_extension_active', true)
if self.container_key
@@ -93,19 +93,19 @@
!!target_map[key]
end
def target_by_key(key)
target = target_map[key.to_sym]
- raise "Can not find target with key '#{key}'" unless target
+ Reality::Facets.error("Can not find target with key '#{key}'") unless target
target
end
def target_by_model_class(model_class)
target_map.each do |key, target|
return target if target.model_class == model_class
end
- raise "Can not find target with model class '#{model_class.name}'"
+ Reality::Facets.error("Can not find target with model class '#{model_class.name}'")
end
def apply_extension(model)
self.target_by_model_class(model.class).apply_extension_to(model)
end
@@ -128,11 +128,11 @@
end
private
def register_target(target)
- raise "Attempting to define target #{target.key} when targets have been locked." if (@targets_locked ||= false)
- raise "Attempting to redefine target #{target.key}" if target_map[target.key]
+ Reality::Facets.error("Attempting to define target #{target.key} when targets have been locked.") if (@targets_locked ||= false)
+ Reality::Facets.error("Attempting to redefine target #{target.key}") if target_map[target.key]
target_map[target.key] = target
end
def target_map
@target_map ||= Reality::OrderedHash.new