Class: Poke::LastRecentlyUsed
- Inherits:
-
Object
- Object
- Poke::LastRecentlyUsed
- Defined in:
- lib/poke/last_recently_used.rb
Class Method Summary collapse
- .all ⇒ Object
- .groups ⇒ Object
- .position(namespace:, key:) ⇒ Object
- .requests ⇒ Object
- .use!(namespace:, key:) ⇒ Object
Class Method Details
.all ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/poke/last_recently_used.rb', line 9 def self.all @all ||= if File.exist?(Poke::Config.lru_path) JSON.parse(File.read(Poke::Config.lru_path)) else {} end end |
.groups ⇒ Object
17 18 19 |
# File 'lib/poke/last_recently_used.rb', line 17 def self.groups all['groups'] ||= {} end |
.position(namespace:, key:) ⇒ Object
34 35 36 |
# File 'lib/poke/last_recently_used.rb', line 34 def self.position(namespace:, key:) all.dig(namespace, 'lru')&.index(key) || Float::INFINITY end |
.requests ⇒ Object
21 22 23 |
# File 'lib/poke/last_recently_used.rb', line 21 def self.requests all['requests'] ||= {} end |
.use!(namespace:, key:) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/poke/last_recently_used.rb', line 25 def self.use!(namespace:, key:) all[namespace] ||= {} all[namespace]['lru'] ||= [] all[namespace]['lru'].delete(key.to_s) all[namespace]['lru'].unshift(key.to_s) File.write(Poke::Config.lru_path, all.to_json) end |