Class: DataMapper::Sweatshop::UniqueWorker

Inherits:
Object
  • Object
show all
Defined in:
lib/dm-sweatshop/unique.rb

Constant Summary collapse

MAX_TRIES =
10

Class Method Summary collapse

Class Method Details

.key_for(&block) ⇒ Object

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

return <Object> the unique key for the block


78
79
80
81
82
83
84
85
86
# File 'lib/dm-sweatshop/unique.rb', line 78

def self.key_for(&block)
  raise "You need to install ParseTree to use anonymous an anonymous unique (gem install ParseTree). In the mean time, explicitly declare a key: unique(:my_key) { ... }" unless Object::const_defined?("ParseTree")

  klass = Class.new
  name = "tmp"
  klass.send(:define_method, name, &block)
  self.parser ||= ParseTree.new(false)
  self.parser.parse_tree_for_method(klass, name).last
end