Class: RailsMFA::SimpleStore

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_mfa/configuration.rb

Overview

Fallback in case Rails.cache is unavailable (for plain Ruby apps)

Instance Method Summary collapse

Constructor Details

#initializeSimpleStore

Returns a new instance of SimpleStore.



22
23
24
# File 'lib/rails_mfa/configuration.rb', line 22

def initialize
  @store = {}
end

Instance Method Details

#delete(key) ⇒ Object



38
39
40
# File 'lib/rails_mfa/configuration.rb', line 38

def delete(key)
  @store.delete(key)
end

#read(key) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/rails_mfa/configuration.rb', line 30

def read(key)
  entry = @store[key]
  return nil unless entry
  return nil if entry[:expires_at] && Time.now > entry[:expires_at]

  entry[:value]
end

#write(key, value, expires_in: nil) ⇒ Object



26
27
28
# File 'lib/rails_mfa/configuration.rb', line 26

def write(key, value, expires_in: nil)
  @store[key] = { value: value, expires_at: expires_in ? Time.now + expires_in : nil }
end