user_info.rb 409 B

12345678910111213141516171819202122
  1. module UserInfo
  2. def self.current_user_id
  3. Thread.current[:user_id]
  4. end
  5. def self.current_user_id=(user_id)
  6. Thread.current[:user_id] = user_id
  7. end
  8. def self.ensure_current_user_id
  9. if UserInfo.current_user_id.nil?
  10. UserInfo.current_user_id = 1
  11. reset_current_user_id = true
  12. end
  13. yield
  14. return if !reset_current_user_id
  15. UserInfo.current_user_id = nil
  16. end
  17. end