Class: Clowk::Subdomain
- Inherits:
-
Object
- Object
- Clowk::Subdomain
- Defined in:
- lib/clowk/subdomain.rb
Constant Summary collapse
- CACHE_TTL =
60- DEFAULT_SUBDOMAIN_BASE =
"clowk.dev"
Class Method Summary collapse
- .clear_cache! ⇒ Object
- .read_cache(key) ⇒ Object
- .resolve_url! ⇒ Object
- .write_cache(key, value, ttl:) ⇒ Object
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Subdomain
constructor
A new instance of Subdomain.
- #resolve_url! ⇒ Object
Constructor Details
Class Method Details
.clear_cache! ⇒ Object
17 18 19 |
# File 'lib/clowk/subdomain.rb', line 17 def clear_cache! @cache_mutex.synchronize { @cache = {} } end |
.read_cache(key) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/clowk/subdomain.rb', line 21 def read_cache(key) @cache_mutex.synchronize do entry = cache[key] return unless entry return entry[:value] if entry[:expires_at] > Time.now cache.delete(key) nil end end |
.resolve_url! ⇒ Object
13 14 15 |
# File 'lib/clowk/subdomain.rb', line 13 def resolve_url!(...) new(...).resolve_url! end |
.write_cache(key, value, ttl:) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/clowk/subdomain.rb', line 33 def write_cache(key, value, ttl:) @cache_mutex.synchronize do cache[key] = { value: value, expires_at: Time.now + ttl } end end |
Instance Method Details
#resolve_url! ⇒ Object
54 55 56 57 58 59 |
# File 'lib/clowk/subdomain.rb', line 54 def resolve_url! return resolve_from_key if publishable_key.present? return normalize_url(subdomain_url) if subdomain_url.present? raise ConfigurationError, "set publishable_key or subdomain_url to build Clowk URLs" end |