Improved code layout.
This commit is contained in:
parent
06a32ad071
commit
aa4fffad32
1 changed files with 5 additions and 7 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue