Class: KMDB::User

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
CustomRecord, HasProperties
Defined in:
lib/kmdb/models/user.rb

Constant Summary collapse

CACHE_EXPIRY =
3_600

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HasProperties

included

Methods included from CustomRecord

included

Class Method Details

.find_or_create(name:) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/kmdb/models/user.rb', line 28

def self.find_or_create(name:)
  if raw = _redis.get(name)
    Marshal.load(raw)
  else
    super.tap do |user|
      _redis.set(name, Marshal.dump(user), ex: CACHE_EXPIRY)
    end
  end
end

Instance Method Details

#destroyObject



38
39
40
41
# File 'lib/kmdb/models/user.rb', line 38

def destroy
  super
  _redis.del(name)
end

#prop(name) ⇒ Object

return (latest) value of property



22
23
24
# File 'lib/kmdb/models/user.rb', line 22

def prop(name)
  properties.named(name).first.andand.value
end