Class: TurboBoost::Commands::StateStore
- Inherits:
-
ActiveSupport::Cache::MemoryStore
- Object
- ActiveSupport::Cache::MemoryStore
- TurboBoost::Commands::StateStore
- Includes:
- Enumerable
- Defined in:
- lib/turbo_boost/commands/state_store.rb
Defined Under Namespace
Classes: NoCoder
Constant Summary collapse
- SGID_PURPOSE =
name.dup.freeze
Instance Method Summary collapse
-
#initialize(payload = {}) ⇒ StateStore
constructor
A new instance of StateStore.
- #merge!(other = {}) ⇒ Object
- #to_gid ⇒ Object
- #to_gid_param ⇒ Object
- #to_h ⇒ Object
- #to_sgid ⇒ Object
- #to_sgid_param ⇒ Object
- #to_uid ⇒ Object
Constructor Details
#initialize(payload = {}) ⇒ StateStore
Returns a new instance of StateStore.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/turbo_boost/commands/state_store.rb', line 18 def initialize(payload = {}) super(coder: NoCoder.new, compress: false, expires_in: 1.day, size: 16.kilobytes) begin payload = case payload when SignedGlobalID then URI::UID.from_sgid(payload, for: SGID_PURPOSE)&.decode when GlobalID then URI::UID.from_gid(payload)&.decode when String then URI::UID.from_sgid(payload, for: SGID_PURPOSE)&.decode || URI::UID.from_gid(payload, for: SGID_PURPOSE)&.decode else payload end rescue => error Rails.logger.error "Failed to decode URI::UID when creating a TurboBoost::Commands::StateStore! #{error.message}" payload = {} end merge! payload end |
Instance Method Details
#merge!(other = {}) ⇒ Object
47 48 49 50 |
# File 'lib/turbo_boost/commands/state_store.rb', line 47 def merge!(other = {}) other.to_h.each { |key, val| write key, val } self end |
#to_gid ⇒ Object
57 58 59 |
# File 'lib/turbo_boost/commands/state_store.rb', line 57 def to_gid to_uid.to_gid end |
#to_gid_param ⇒ Object
61 62 63 |
# File 'lib/turbo_boost/commands/state_store.rb', line 61 def to_gid_param to_gid.to_param end |
#to_h ⇒ Object
39 40 41 42 43 |
# File 'lib/turbo_boost/commands/state_store.rb', line 39 def to_h @data .each_with_object({}) { |(key, entry), memo| memo[key] = entry.value } .with_indifferent_access end |
#to_sgid ⇒ Object
65 66 67 |
# File 'lib/turbo_boost/commands/state_store.rb', line 65 def to_sgid to_uid.to_sgid for: SGID_PURPOSE, expires_in: 1.day end |
#to_sgid_param ⇒ Object
69 70 71 |
# File 'lib/turbo_boost/commands/state_store.rb', line 69 def to_sgid_param to_sgid.to_param end |
#to_uid ⇒ Object
52 53 54 55 |
# File 'lib/turbo_boost/commands/state_store.rb', line 52 def to_uid cleanup URI::UID.build to_h, include_blank: false end |