Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Sweatshop
- self.record_map = Hash.new {|h,k| h[k] = Hash.new {|h,k| h[k] = 0}}
- def self.record(klass, name, instance)
- # self.record_map[klass][name.to_sym] << instance
- self.record_map[klass][name.to_sym] += 1
- instance
- end
- def self.pick(klass, name)
- # self.record_map[klass][name.to_sym].pick || raise(NoFixtureExist, "no #{name} context fixtures have been generated for the #{klass} class")
- offset = (rand * self.record_map[klass][name.to_sym]).to_i + 1
- klass.first(:offset => offset) || raise(NoFixtureExist, "no #{name} context fixtures have been generated for the #{klass} class")
- end
- end
Add Comment
Please, Sign In to add comment