miscellany 0.1.10 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9ff0b4bf631a0cd63cc733ce24d2e301506a4e53b6cbd3401a7fd0e9a1a807be
4
- data.tar.gz: 21bf9c72bcd13371194e7d889aa5c2a1b5500a2e76f2e4e808a530e98472be75
3
+ metadata.gz: 54c8662a208b655e434d42348a8ae5ace33251ad3180b39d4a0f1bbf4567c6da
4
+ data.tar.gz: 7785ba04dcfa330d838a802d89f56909d799b054264f8085eddefc93b728ab9d
5
5
  SHA512:
6
- metadata.gz: af03a68cbb2fcf535d4afb0cc2aadc4c6faafee83ca6379b7e3850210f12e4ba2bb25bd8fa9f1e725fa4f1eb79a96fe063fc0b16d8c62abd335aed346481bce0
7
- data.tar.gz: bf6a692956fde6ba1aea228c0dfaa514bffbdefa5813e59ef9fd69ceab2badfd08da03eaa82cb5378b214b0f7fb02af671402cb075c67ced0ac6f4feebeee70c
6
+ metadata.gz: dd53eac07ade5122cdd43bd866e7bc758c38147e16760d1b6d1fd776807f1db81261069a598bfa3c7a627b81989737eca0798296284f88b36eb1cd3147924f6e
7
+ data.tar.gz: 61de91e1e72ea0105b536cd4e8d6c9ccb788f9d16418fc4e1b94af5a56ee3b7aa20e0d4dacd7c87bd6ffa5632a80f62575f473e876928f88d98a25f7f70fc3a0
@@ -0,0 +1,67 @@
1
+ module Miscellany
2
+ class LocalLruCache
3
+ def initialize(max_size)
4
+ @max_size = max_size
5
+ @data = {}
6
+ end
7
+
8
+ def max_size=(size)
9
+ raise ArgumentError.new(:max_size) if @max_size < 1
10
+ @max_size = size
11
+ if @max_size < @data.size
12
+ @data.keys[0..@max_size-@data.size].each do |k|
13
+ @data.delete(k)
14
+ end
15
+ end
16
+ end
17
+
18
+ def fetch(key)
19
+ if @data.key?(key)
20
+ self[key]
21
+ else
22
+ self[key] = yield
23
+ end
24
+ end
25
+
26
+ def [](key)
27
+ found = true
28
+ value = @data.delete(key){ found = false }
29
+ if found
30
+ @data[key] = value
31
+ else
32
+ nil
33
+ end
34
+ end
35
+
36
+ def []=(key,val)
37
+ @data.delete(key)
38
+ @data[key] = val
39
+ if @data.length > @max_size
40
+ @data.delete(@data.first[0])
41
+ end
42
+ val
43
+ end
44
+
45
+ def each
46
+ @data.reverse.each do |pair|
47
+ yield pair
48
+ end
49
+ end
50
+
51
+ def to_a
52
+ @data.to_a.reverse
53
+ end
54
+
55
+ def delete(k)
56
+ @data.delete(k)
57
+ end
58
+
59
+ def clear
60
+ @data.clear
61
+ end
62
+
63
+ def count
64
+ @data.count
65
+ end
66
+ end
67
+ end
@@ -1,3 +1,3 @@
1
1
  module Miscellany
2
- VERSION = "0.1.10".freeze
2
+ VERSION = "0.1.11".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: miscellany
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ethan Knapp
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-29 00:00:00.000000000 Z
11
+ date: 2023-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -100,7 +100,7 @@ dependencies:
100
100
  - - ">="
101
101
  - !ruby/object:Gem::Version
102
102
  version: '0'
103
- description:
103
+ description:
104
104
  email:
105
105
  - eknapp@instructure.com
106
106
  executables: []
@@ -121,6 +121,7 @@ files:
121
121
  - lib/miscellany/controller/http_error_handling.rb
122
122
  - lib/miscellany/controller/json_uploads.rb
123
123
  - lib/miscellany/controller/sliced_response.rb
124
+ - lib/miscellany/local_lru_cache.rb
124
125
  - lib/miscellany/param_validator.rb
125
126
  - lib/miscellany/version.rb
126
127
  - miscellany.gemspec
@@ -132,7 +133,7 @@ files:
132
133
  homepage: https://instructure.com
133
134
  licenses: []
134
135
  metadata: {}
135
- post_install_message:
136
+ post_install_message:
136
137
  rdoc_options: []
137
138
  require_paths:
138
139
  - lib
@@ -148,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
149
  version: '0'
149
150
  requirements: []
150
151
  rubygems_version: 3.1.6
151
- signing_key:
152
+ signing_key:
152
153
  specification_version: 4
153
154
  summary: Gem for a bunch of random, re-usable Rails Concerns & Helpers
154
155
  test_files: