A corporation manager and dashboard for EVE Online
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

41 regels
937 B

  1. class AdminSetting < ActiveRecord::Base
  2. def self.to_bool(value)
  3. value == 't'
  4. end
  5. def self.from_bool(value)
  6. value ? 't' : 'f'
  7. end
  8. def self.add(key, value)
  9. value = self.from_bool(value) if value == true || value == false
  10. self.create(key: key, value: value)
  11. end
  12. def self.get(key)
  13. existing = Rails.cache.read("admin_setting/#{key}")
  14. return existing unless existing.nil?
  15. setting = self.find_by(key: key)
  16. return nil if setting.nil?
  17. Rails.cache.write("admin_setting/#{key}", setting.value)
  18. setting.value
  19. end
  20. def self.get_bool(key)
  21. self.to_bool(self.get(key))
  22. end
  23. def self.set(key, value)
  24. existing = self.get(key)
  25. return false if existing.nil? || existing == value
  26. self.find_by(key: key).update(value: value)
  27. Rails.cache.write("admin_setting/#{key}", value)
  28. true
  29. end
  30. def self.set_bool(key, value)
  31. self.set(key, self.from_bool(value))
  32. end
  33. end