Permalink
Browse files

Changed the Thread.current hash keys to use the dm prefix

* Moved class variable declation to Resoruce::ClassMethods#included
* Object#extend is public, updated calls to not use Object#send
* Updated Resource::ClassMethods#method_missing to be private
* Minor cleanup
  • Loading branch information...
1 parent d901026 commit 2514de17b074b45ad04657b8727616cd0c0091ef Dan Kubb committed Apr 11, 2008
@@ -49,12 +49,12 @@ def rollback_transaction
end
def within_transaction?
- !Thread.current["doa_#{@uri.scheme}_transaction"].nil?
+ !Thread.current["dm_doa_#{@uri.scheme}_transaction"].nil?
end
def create_connection
if within_transaction?
- Thread.current["doa_#{@uri.scheme}_transaction"]
+ Thread.current["dm_doa_#{@uri.scheme}_transaction"]
else
# DataObjects::Connection.new(uri) will give you back the right
# driver based on the Uri#scheme.
@@ -6,10 +6,10 @@
module DataMapper
module Associations
def self.extended(base)
- base.send(:extend, ManyToOne)
- base.send(:extend, OneToMany)
- base.send(:extend, ManyToMany)
- base.send(:extend, OneToOne)
+ base.extend ManyToOne
+ base.extend OneToMany
+ base.extend ManyToMany
+ base.extend OneToOne
end
def relationships
@@ -11,7 +11,7 @@ def self.adapters
end
def self.context
- Thread.current[:repository_contexts] ||= []
+ Thread.current[:dm_repository_contexts] ||= []
end
attr_reader :name, :adapter
@@ -13,15 +13,10 @@ module Resource
# Resource module methods
def self.included(base)
- base.send(:extend, ClassMethods)
- base.send(:extend, DataMapper::Hook::ClassMethods)
+ base.extend ClassMethods
+ base.extend DataMapper::Associations
base.send(:include, DataMapper::Hook)
- base.send(:extend, DataMapper::Scope::ClassMethods)
- base.instance_variable_set(:@resource_names, Hash.new { |h,k| h[k] = repository(k).adapter.resource_naming_convention.call(base.name) })
- base.instance_variable_set(:@properties, Hash.new { |h,k| h[k] = (k == :default ? PropertySet.new : h[:default].dup) })
-
- # Associations:
- base.send(:extend, DataMapper::Associations)
+ base.send(:include, DataMapper::Scope)
end
def self.dependencies
@@ -211,16 +206,9 @@ def private_attributes=(values_hash)
end
module ClassMethods
-
- alias_method :_method_missing, :method_missing
-
- def method_missing(method, *args)
- if relationships.has_key?(method)
- return DataMapper::Query::Path.new([relationships[method]],method)
- end
- result = properties(repository.name)[method]
- return result if result
- _method_missing(method,args)
+ def self.extended(base)
+ base.instance_variable_set(:@resource_names, Hash.new { |h,k| h[k] = repository(k).adapter.resource_naming_convention.call(base.name) })
+ base.instance_variable_set(:@properties, Hash.new { |h,k| h[k] = k == :default ? PropertySet.new : h[:default].dup })
end
def repository(name = default_repository_name)
@@ -231,9 +219,9 @@ def default_repository_name
:default
end
- # FIXME: should this be renamed container_name, since it
- # effectively returns the name of the container in the repository
- # that we store the data in
+ # FIXME: should this be renamed, since it returns the name of
+ # physical storage location, and resource_name is a confusing
+ # name when there is already a resource object.
def resource_name(repository_name)
@resource_names[repository_name]
end
@@ -313,6 +301,19 @@ def copy(source, destination, options = {})
end
end
end
+
+ private
+
+ def method_missing(method, *args, &block)
+ if relationship = relationships[method]
+ return DataMapper::Query::Path.new([ relationship ],method)
+ end
+ if property = properties(repository.name)[method]
+ return property
+ end
+ super
+ end
+
end # module ClassMethods
end # module Resource
end # module DataMapper
@@ -1,5 +1,9 @@
module DataMapper
module Scope
+ def self.included(base)
+ base.extend(ClassMethods)
+ end
+
module ClassMethods
protected
@@ -23,7 +27,7 @@ def with_exclusive_scope(query, &block)
private
def scope_stack
- scope_stack_for = Thread.current[:scope_stack] ||= Hash.new { |h,k| h[k] = [] }
+ scope_stack_for = Thread.current[:dm_scope_stack] ||= Hash.new { |h,k| h[k] = [] }
scope_stack_for[self]
end

0 comments on commit 2514de1

Please sign in to comment.