memory_record 0.0.19 → 0.0.20

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: b1ff4966063583e1b982805aaa2cb70ca4a4489498892280850e43b608def31a
4
- data.tar.gz: 3efe77744703e2765bcc77f8e5888ba568ac5ba88ce29f7c1afaa13059e9fe86
3
+ metadata.gz: 6ada7adcb127eacab83e0d83846bc7f6e89e0f425a09d382265fd6d430be3096
4
+ data.tar.gz: d87b6b3ab26276906053ba64503b9689bf1535344c094ca05a0c67d2b5f78bc5
5
5
  SHA512:
6
- metadata.gz: 34edd3b363bc9fe46aea07e9ea3626ece155a7cd5aefbafb90319a49a2d8c9a48dc7b23940478b40a19ea364a38ebe99e383ba9e620894dfa281e9f8c642b4ed
7
- data.tar.gz: 371a5cd5f00281683650b9614b036b0bb70d964e8cd24b5bd147ef62de988be36ebc8887bc54a8b60bc019d7389fcd05b85697cbaea7258eca03389252500a12
6
+ metadata.gz: 1ad9b5ea959c6088cfd852b41ad05314fb3beb54e5b13640c628d795665f8c37ca438eff25df05103b2e5d3d80c9a5f1d7a2426838a5098aadab77a4e94d85d4
7
+ data.tar.gz: 861df89b3c66f10ee62053d34af0b6a6de026e903b2a0d6ce667ef535a3af30450cae139c699a332a7790168e2a2ee4b7dd3653a86b6ccf4ab0ef5863d4bcb14
data/README.md CHANGED
@@ -168,21 +168,21 @@ Palette.fetch_if(:xxx) # => <KeyError: ...>
168
168
  ### Key validation
169
169
 
170
170
  ```ruby
171
- Palette.valid_key(:tomato) # => :tomato
172
- Palette.valid_key("tomato") # => :tomato
173
- Palette.valid_key(1) # => :tomato
174
- Palette.valid_key(:xxx) # => nil
175
- Palette.valid_key(:xxx, :tomato) # => :tomato
176
- Palette.valid_key(:xxx) { :tomato } # => :tomato
177
-
178
- Palette.valid_key(:xxx, :tomato) # => :tomato
179
- Palette.valid_key(:xxx, :black) rescue $! # => #<KeyError: Palette.fetch(:black) does not match anything
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.valid_key(params[:palette_key], :tomato)
185
+ palette_key = Palette.lookup_key(params[:palette_key], :tomato)
186
186
  ```
187
187
 
188
188
  ### How to refer to other keys
@@ -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.valid_key(:tomato) # => :tomato
32
- Palette.valid_key("tomato") # => :tomato
33
- Palette.valid_key(1) # => :tomato
34
- Palette.valid_key(:xxx) # => nil
35
- Palette.valid_key(:xxx, :tomato) # => :tomato
36
- Palette.valid_key(:xxx) { :tomato } # => :tomato
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.valid_key(:xxx, :tomato) # => :tomato
39
- Palette.valid_key(:xxx, :black) rescue $! # => #<KeyError: Palette.fetch(:black) does not match anything
38
+ Palette.lookup_key(:xxx, :tomato) # => :tomato
39
+ Palette.lookup_key(:xxx, :black) rescue $! # => #<KeyError: Palette.fetch(:black) does not match anything
@@ -8,8 +8,8 @@ class Color
8
8
  ]
9
9
  end
10
10
 
11
- Color.valid_key(:blue) # => :blue
12
- Color.valid_key(:unknown) # => nil
13
- Color.valid_key(:unknown, :blue) # => :blue
14
- Color.valid_key(:unknown) { :blue } # => :blue
15
- Color.valid_key(:unknown) { :xxx } rescue $! # => #<KeyError: Color.fetch(:xxx) does not match anything
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.valid_key(:blue) # => :blue
156
- # Color.valid_key(:unknown) # => nil
157
- # Color.valid_key(:unknown, :blue) # => :blue
158
- # Color.valid_key(:unknown) { :blue } # => :blue
159
- # Color.valid_key(:unknown) { :xxx } # => KeyError Exception
160
- def valid_key(key, default = nil, &block)
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
@@ -1,3 +1,3 @@
1
1
  module MemoryRecord
2
- VERSION = '0.0.19'
2
+ VERSION = '0.0.20'
3
3
  end
@@ -318,18 +318,18 @@ RSpec.describe MemoryRecord do
318
318
  # end
319
319
  # end
320
320
 
321
- describe "valid_key" do
321
+ describe "lookup_key" do
322
322
  it do
323
323
  model = class_new [
324
324
  { key: :blue },
325
325
  ]
326
- assert { model.valid_key(:blue) == :blue }
327
- assert { model.valid_key(:unknown) == nil }
328
- assert { model.valid_key(:unknown, :blue) == :blue }
329
- assert { model.valid_key(:unknown) { :blue } == :blue }
330
- assert { model.valid_key(:unknown) { :blue } == :blue }
331
- assert_raises(KeyError) { model.valid_key(:unknown) { :xxx } }
332
- assert_raises(KeyError) { model.valid_key(:unknown, :xxx) }
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.19
4
+ version: 0.0.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - akicho8
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-04 00:00:00.000000000 Z
11
+ date: 2024-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -162,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
162
  - !ruby/object:Gem::Version
163
163
  version: '0'
164
164
  requirements: []
165
- rubygems_version: 3.3.4
165
+ rubygems_version: 3.5.18
166
166
  signing_key:
167
167
  specification_version: 4
168
168
  summary: A simple library that handles a few records easily