Module: Card::Auth::Setup

Included in:
Card::Auth
Defined in:
lib/card/auth/setup.rb

Overview

singleton methods for managing setup state

Constant Summary collapse

SETUP_COMPLETED_KEY =
"SETUP_COMPLETED".freeze

Instance Method Summary collapse

Instance Method Details

#hide_accounts!(mode = true) ⇒ Object

for testing setup



26
27
28
29
# File 'lib/card/auth/setup.rb', line 26

def hide_accounts! mode=true
  Card.cache.delete(SETUP_COMPLETED_KEY) if mode
  @hidden_accounts = mode && 
end

#instant_account_activationObject



31
32
33
34
35
36
# File 'lib/card/auth/setup.rb', line 31

def 
  simulate_setup_need!
  yield
ensure
  simulate_setup_need! false
end

#needs_setup?true/false

app is not totally set up yet

Returns:

  • (true/false)


10
11
12
13
14
15
16
17
# File 'lib/card/auth/setup.rb', line 10

def needs_setup?
  # FIXME: - should not require a cache lookup with every request!!
  @simulating_setup_need || (
    !Card.cache.read(SETUP_COMPLETED_KEY) &&
    !Card.cache.write(SETUP_COMPLETED_KEY, .positive?)
  )
  # every deck starts with two accounts: WagnBot and Anonymous
end

#simulate_setup_need!(mode = true) ⇒ Object

act as if site is not set up

Parameters:

  • mode (true/false) (defaults to: true)

    simulate setup need if true



21
22
23
# File 'lib/card/auth/setup.rb', line 21

def simulate_setup_need! mode=true
  @simulating_setup_need = mode
end