memory_record 0.0.18 → 0.0.20
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +10 -10
- data/examples/0100_basic.rb +8 -8
- data/examples/0370_valid_key.rb +5 -5
- data/lib/memory_record/memory_record/serialization.rb +1 -1
- data/lib/memory_record/memory_record.rb +6 -6
- data/lib/memory_record/version.rb +1 -1
- data/spec/memory_record_spec.rb +9 -9
- metadata +6 -7
- data/.ruby-version +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ada7adcb127eacab83e0d83846bc7f6e89e0f425a09d382265fd6d430be3096
|
4
|
+
data.tar.gz: d87b6b3ab26276906053ba64503b9689bf1535344c094ca05a0c67d2b5f78bc5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ad9b5ea959c6088cfd852b41ad05314fb3beb54e5b13640c628d795665f8c37ca438eff25df05103b2e5d3d80c9a5f1d7a2426838a5098aadab77a4e94d85d4
|
7
|
+
data.tar.gz: 861df89b3c66f10ee62053d34af0b6a6de026e903b2a0d6ce667ef535a3af30450cae139c699a332a7790168e2a2ee4b7dd3653a86b6ccf4ab0ef5863d4bcb14
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -168,21 +168,21 @@ Palette.fetch_if(:xxx) # => <KeyError: ...>
|
|
168
168
|
### Key validation
|
169
169
|
|
170
170
|
```ruby
|
171
|
-
Palette.
|
172
|
-
Palette.
|
173
|
-
Palette.
|
174
|
-
Palette.
|
175
|
-
Palette.
|
176
|
-
Palette.
|
177
|
-
|
178
|
-
Palette.
|
179
|
-
Palette.
|
171
|
+
Palette.lookup_key(:tomato) # => :tomato
|
172
|
+
Palette.lookup_key("tomato") # => :tomato
|
173
|
+
Palette.lookup_key(1) # => :tomato
|
174
|
+
Palette.lookup_key(:xxx) # => nil
|
175
|
+
Palette.lookup_key(:xxx, :tomato) # => :tomato
|
176
|
+
Palette.lookup_key(:xxx) { :tomato } # => :tomato
|
177
|
+
|
178
|
+
Palette.lookup_key(:xxx, :tomato) # => :tomato
|
179
|
+
Palette.lookup_key(:xxx, :black) rescue $! # => #<KeyError: Palette.fetch(:black) does not match anything
|
180
180
|
```
|
181
181
|
|
182
182
|
#### A common example in Rails
|
183
183
|
|
184
184
|
```ruby
|
185
|
-
palette_key = Palette.
|
185
|
+
palette_key = Palette.lookup_key(params[:palette_key], :tomato)
|
186
186
|
```
|
187
187
|
|
188
188
|
### How to refer to other keys
|
data/examples/0100_basic.rb
CHANGED
@@ -28,12 +28,12 @@ Palette[:tomato].rgb # => [255, 99, 71]
|
|
28
28
|
Palette[:tomato].hex # => "#FF6347"
|
29
29
|
Palette.collect(&:hex) # => ["#FF7F00", "#FF6347", "#FFD700"]
|
30
30
|
|
31
|
-
Palette.
|
32
|
-
Palette.
|
33
|
-
Palette.
|
34
|
-
Palette.
|
35
|
-
Palette.
|
36
|
-
Palette.
|
31
|
+
Palette.lookup_key(:tomato) # => :tomato
|
32
|
+
Palette.lookup_key("tomato") # => :tomato
|
33
|
+
Palette.lookup_key(1) # => :tomato
|
34
|
+
Palette.lookup_key(:xxx) # => nil
|
35
|
+
Palette.lookup_key(:xxx, :tomato) # => :tomato
|
36
|
+
Palette.lookup_key(:xxx) { :tomato } # => :tomato
|
37
37
|
|
38
|
-
Palette.
|
39
|
-
Palette.
|
38
|
+
Palette.lookup_key(:xxx, :tomato) # => :tomato
|
39
|
+
Palette.lookup_key(:xxx, :black) rescue $! # => #<KeyError: Palette.fetch(:black) does not match anything
|
data/examples/0370_valid_key.rb
CHANGED
@@ -8,8 +8,8 @@ class Color
|
|
8
8
|
]
|
9
9
|
end
|
10
10
|
|
11
|
-
Color.
|
12
|
-
Color.
|
13
|
-
Color.
|
14
|
-
Color.
|
15
|
-
Color.
|
11
|
+
Color.lookup_key(:blue) # => :blue
|
12
|
+
Color.lookup_key(:unknown) # => nil
|
13
|
+
Color.lookup_key(:unknown, :blue) # => :blue
|
14
|
+
Color.lookup_key(:unknown) { :blue } # => :blue
|
15
|
+
Color.lookup_key(:unknown) { :xxx } rescue $! # => #<KeyError: Color.fetch(:xxx) does not match anything
|
@@ -152,12 +152,12 @@ module MemoryRecord
|
|
152
152
|
end
|
153
153
|
end
|
154
154
|
|
155
|
-
# Color.
|
156
|
-
# Color.
|
157
|
-
# Color.
|
158
|
-
# Color.
|
159
|
-
# Color.
|
160
|
-
def
|
155
|
+
# Color.lookup_key(:blue) # => :blue
|
156
|
+
# Color.lookup_key(:unknown) # => nil
|
157
|
+
# Color.lookup_key(:unknown, :blue) # => :blue
|
158
|
+
# Color.lookup_key(:unknown) { :blue } # => :blue
|
159
|
+
# Color.lookup_key(:unknown) { :xxx } # => KeyError Exception
|
160
|
+
def lookup_key(key, default = nil, &block)
|
161
161
|
if block_given? && default
|
162
162
|
raise ArgumentError, "Can't use default and block together"
|
163
163
|
end
|
data/spec/memory_record_spec.rb
CHANGED
@@ -166,7 +166,7 @@ RSpec.describe MemoryRecord do
|
|
166
166
|
def element(options)
|
167
167
|
Class.new {
|
168
168
|
include MemoryRecord
|
169
|
-
memory_record options do
|
169
|
+
memory_record **options do
|
170
170
|
[
|
171
171
|
{x: 1, y: 1, z: 1},
|
172
172
|
]
|
@@ -318,18 +318,18 @@ RSpec.describe MemoryRecord do
|
|
318
318
|
# end
|
319
319
|
# end
|
320
320
|
|
321
|
-
describe "
|
321
|
+
describe "lookup_key" do
|
322
322
|
it do
|
323
323
|
model = class_new [
|
324
324
|
{ key: :blue },
|
325
325
|
]
|
326
|
-
assert { model.
|
327
|
-
assert { model.
|
328
|
-
assert { model.
|
329
|
-
assert { model.
|
330
|
-
assert { model.
|
331
|
-
assert_raises(KeyError) { model.
|
332
|
-
assert_raises(KeyError) { model.
|
326
|
+
assert { model.lookup_key(:blue) == :blue }
|
327
|
+
assert { model.lookup_key(:unknown) == nil }
|
328
|
+
assert { model.lookup_key(:unknown, :blue) == :blue }
|
329
|
+
assert { model.lookup_key(:unknown) { :blue } == :blue }
|
330
|
+
assert { model.lookup_key(:unknown) { :blue } == :blue }
|
331
|
+
assert_raises(KeyError) { model.lookup_key(:unknown) { :xxx } }
|
332
|
+
assert_raises(KeyError) { model.lookup_key(:unknown, :xxx) }
|
333
333
|
end
|
334
334
|
end
|
335
335
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: memory_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.20
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- akicho8
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -103,7 +103,6 @@ extra_rdoc_files: []
|
|
103
103
|
files:
|
104
104
|
- ".gitignore"
|
105
105
|
- ".rspec"
|
106
|
-
- ".ruby-version"
|
107
106
|
- ".travis.yml"
|
108
107
|
- Gemfile
|
109
108
|
- LICENSE.txt
|
@@ -148,7 +147,7 @@ homepage: ''
|
|
148
147
|
licenses:
|
149
148
|
- MIT
|
150
149
|
metadata: {}
|
151
|
-
post_install_message:
|
150
|
+
post_install_message:
|
152
151
|
rdoc_options: []
|
153
152
|
require_paths:
|
154
153
|
- lib
|
@@ -163,8 +162,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
163
162
|
- !ruby/object:Gem::Version
|
164
163
|
version: '0'
|
165
164
|
requirements: []
|
166
|
-
rubygems_version: 3.
|
167
|
-
signing_key:
|
165
|
+
rubygems_version: 3.5.18
|
166
|
+
signing_key:
|
168
167
|
specification_version: 4
|
169
168
|
summary: A simple library that handles a few records easily
|
170
169
|
test_files:
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2.6.5
|