class DataMapper::Sweatshop::UniqueWorker
Constants
- MAX_TRIES
Public Class Methods
key_for(&block)
click to toggle source
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
# 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