Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

Commit

Permalink
Merge branch 'feature/remove-core-exts'
Browse files Browse the repository at this point in the history
  • Loading branch information
gix committed Mar 6, 2011
2 parents 5a179fb + 24b7166 commit e17349a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 8 deletions.
46 changes: 46 additions & 0 deletions lib/dm-sweatshop/support/class_attributes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
module DataMapper
class Sweatshop
module ClassAttributes
def self.reader(klass, *attributes)
attributes.each do |attribute|
klass.class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
unless defined? @@#{attribute}
@@#{attribute} = nil
end
def self.#{attribute}
@@#{attribute}
end
def #{attribute}
@@#{attribute}
end
RUBY
end
end

def self.writer(klass, *attributes)
attributes.each do |attribute|
klass.class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
unless defined? @@#{attribute}
@@#{attribute} = nil
end
def self.#{attribute}=(obj)
@@#{attribute} = obj
end
def #{attribute}=(obj)
@@#{attribute} = obj
end
RUBY
end
end

def self.accessor(klass, *attributes)
self.reader(klass, *attributes)
self.writer(klass, *attributes)
end
end
end
end
12 changes: 4 additions & 8 deletions lib/dm-sweatshop/unique.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
begin
require 'active_support/core_ext/class/attribute_accessors'
rescue LoadError
require 'extlib/class'
end
require 'dm-sweatshop/support/class_attributes'

module DataMapper
class Sweatshop
Expand Down Expand Up @@ -69,9 +65,9 @@ class UniqueWorker
puts "DataMapper::Sweatshop::Unique - ParseTree could not be loaded, anonymous uniques will not be allowed"
end

cattr_accessor :count_map
cattr_accessor :unique_map
cattr_accessor :parser
ClassAttributes.accessor(self, :count_map)
ClassAttributes.accessor(self, :unique_map)
ClassAttributes.accessor(self, :parser)

# Use the sexp representation of the block as a unique key for the block
# If you copy and paste a block, it will still have the same key
Expand Down

0 comments on commit e17349a

Please sign in to comment.