global model cleanup
# File lib/dm-core/spec/lib/spec_helper.rb, line 15 def self.cleanup_models descendants = DataMapper::Model.descendants.to_a while model = descendants.shift model_name = model.name.to_s.strip unless model_name.empty? || model_name[0] == ## parts = model_name.split('::') constant_name = parts.pop.to_sym base = parts.empty? ? Object : DataMapper::Ext::Object.full_const_get(parts.join('::')) base.class_eval { remove_const(constant_name) if const_defined?(constant_name) } end remove_ivars(model) model.instance_methods(false).each { |method| model.send(:undef_method, method) } end DataMapper::Model.descendants.clear end
# File lib/dm-core/spec/setup.rb, line 24 def configure @configured = begin setup_logger require_plugins require_spec_adapter true end end
# File lib/dm-core/spec/setup.rb, line 33 def configured? @configured end
# File lib/dm-core/spec/lib/spec_helper.rb, line 37 def self.remove_ivars(object, instance_variables = object.instance_variables) seen = {} stack = instance_variables.map { |var| [ object, var ] } while node = stack.pop object, ivar = node # skip "global" and non-DM objects next if object.kind_of?(DataMapper::Logger) || object.kind_of?(DataMapper::DescendantSet) || object.kind_of?(DataMapper::Adapters::AbstractAdapter) || object.class.name.to_s[0, 13] == 'DataObjects::' # skip classes and modules in the DataMapper namespace next if object.kind_of?(Module) && object.name.to_s[0, 12] == 'DataMapper::' # skip when the ivar is no longer defined in the object next unless object.instance_variable_defined?(ivar) value = object.instance_variable_get(ivar) # skip descendant sets next if value.kind_of?(DataMapper::DescendantSet) object.__send__(:remove_instance_variable, ivar) unless object.frozen? # skip when the value was seen next if seen.key?(value.object_id) seen[value.object_id] = true stack.concat value.instance_variables.map { |ivar| [ value, ivar ] } end end
# File lib/dm-core/spec/setup.rb, line 54 def require_plugins plugins = ENV['PLUGINS'] || ENV['PLUGIN'] plugins = plugins.to_s.split(/[,\s]+/) unless ENV['ADAPTER'] == 'in_memory' plugins.push('dm-migrations') end plugins.uniq.each { |plugin| require plugin } end
# File lib/dm-core/spec/setup.rb, line 44 def require_spec_adapter desired_adapter = ENV['ADAPTER'] if desired_adapter.nil? || desired_adapter == 'in_memory' ENV['ADAPTER_SUPPORTS'] = 'all' Adapters.use(Adapters::InMemoryAdapter) else require "dm-#{desired_adapter}-adapter/spec/setup" end end
# File lib/dm-core/spec/setup.rb, line 8 def root @root ||= default_root end
# File lib/dm-core/spec/setup.rb, line 12 def root=(path) @root = Pathname(path) end
Generated with the Darkfish Rdoc Generator 2.