Guest User

Untitled

a guest
Apr 25th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. class Sweatshop
  2. self.record_map = Hash.new {|h,k| h[k] = Hash.new {|h,k| h[k] = 0}}
  3.  
  4. def self.record(klass, name, instance)
  5. # self.record_map[klass][name.to_sym] << instance
  6. self.record_map[klass][name.to_sym] += 1
  7. instance
  8. end
  9.  
  10. def self.pick(klass, name)
  11. # self.record_map[klass][name.to_sym].pick || raise(NoFixtureExist, "no #{name} context fixtures have been generated for the #{klass} class")
  12. offset = (rand * self.record_map[klass][name.to_sym]).to_i + 1
  13. klass.first(:offset => offset) || raise(NoFixtureExist, "no #{name} context fixtures have been generated for the #{klass} class")
  14. end
  15.  
  16. end
Add Comment
Please, Sign In to add comment