Sha256: b861134075e57c3d55d7e8dc271a5fdd69aff4da3f5de4e0445f47465cec9a8c
Contents?: true
Size: 1.51 KB
Versions: 6
Compression:
Stored size: 1.51 KB
Contents
class Card module Auth # singleton methods for managing setup state module Setup @simulating_setup_need = nil SETUP_COMPLETED_KEY = "SETUP_COMPLETED".freeze # app is not totally set up yet # @return [true/false] 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, user_account_count.positive?) ) # every deck starts with two accounts: WagnBot and Anonymous end # act as if site is not set up # @param mode [true/false] simulate setup need if true def simulate_setup_need! mode=true @simulating_setup_need = mode end # for testing setup def hide_accounts! mode=true Card.cache.delete(SETUP_COMPLETED_KEY) if mode @hidden_accounts = mode && user_account_ids end def instant_account_activation simulate_setup_need! yield ensure simulate_setup_need! false end private def user_account_ids as_bot { Card.search user_account_wql.merge(return: :id) } end def user_account_wql { right_id: Card::AccountID, creator_id: ["ne", Card::WagnBotID] } end def user_account_count wql = user_account_wql wql[:not] = { id: ["in"].concat(@hidden_accounts) } if @hidden_accounts as_bot { Card.count_by_wql wql } end end end end
Version data entries
6 entries across 6 versions & 1 rubygems