type_lookup.rb 742 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
  2. class TypeLookup < ApplicationModel
  3. @@cache_object = {}
  4. def self.by_id( id )
  5. # use cache
  6. return @@cache_object[ id ] if @@cache_object[ id ]
  7. # lookup
  8. lookup = self.lookup( :id => id )
  9. return if !lookup
  10. @@cache_object[ id ] = lookup.name
  11. lookup.name
  12. end
  13. def self.by_name( name )
  14. # use cache
  15. return @@cache_object[ name ] if @@cache_object[ name ]
  16. # lookup
  17. lookup = self.lookup( :name => name )
  18. if lookup
  19. @@cache_object[ name ] = lookup.id
  20. return lookup.id
  21. end
  22. # create
  23. lookup = self.create(
  24. :name => name
  25. )
  26. @@cache_object[ name ] = lookup.id
  27. lookup.id
  28. end
  29. end