Improved code layout.

This commit is contained in:
Martin Edenhofer 2016-01-24 01:14:14 +01:00
parent 06a32ad071
commit aa4fffad32

View file

@ -3,34 +3,32 @@
class ObjectLookup < ApplicationModel
@@cache_object = {} # rubocop:disable Style/ClassVars
def self.by_id( id )
def self.by_id(id)
# use cache
return @@cache_object[ id ] if @@cache_object[ id ]
# lookup
lookup = self.lookup( id: id )
lookup = self.lookup(id: id)
return if !lookup
@@cache_object[ id ] = lookup.name
lookup.name
end
def self.by_name( name )
def self.by_name(name)
# use cache
return @@cache_object[ name ] if @@cache_object[ name ]
# lookup
lookup = self.lookup( name: name )
lookup = self.lookup(name: name)
if lookup
@@cache_object[ name ] = lookup.id
return lookup.id
end
# create
lookup = create(
name: name
)
lookup = create(name: name)
@@cache_object[ name ] = lookup.id
lookup.id
end