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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 398cef71aad0b7039708dc1384634c230d52686183cfdc97f4b89fc9eac151c1
4
- data.tar.gz: 246e934baa307893bf03ca5bf9784f1dc33fb8171f489956c736820ab4665cd6
3
+ metadata.gz: 6ada7adcb127eacab83e0d83846bc7f6e89e0f425a09d382265fd6d430be3096
4
+ data.tar.gz: d87b6b3ab26276906053ba64503b9689bf1535344c094ca05a0c67d2b5f78bc5
5
5
  SHA512:
6
- metadata.gz: 8ccc73b6b361000a2225f2f5afe0c1e311379ac176da62678fc1b08e6897dfb6c981d3baa830b52deee9b47917a4b41d2ea471d8ab8c2c2ba3522cd20697a112
7
- data.tar.gz: 97f19afba6b7455bf82779794338d97a457028802ca093cd1b0aa766a1a62c8e1596ae9aa536834946bd0c47c7c63d5ffe04da9bd99cb866017d983eb0f05881
6
+ metadata.gz: 1ad9b5ea959c6088cfd852b41ad05314fb3beb54e5b13640c628d795665f8c37ca438eff25df05103b2e5d3d80c9a5f1d7a2426838a5098aadab77a4e94d85d4
7
+ data.tar.gz: 861df89b3c66f10ee62053d34af0b6a6de026e903b2a0d6ce667ef535a3af30450cae139c699a332a7790168e2a2ee4b7dd3653a86b6ccf4ab0ef5863d4bcb14
data/.gitignore CHANGED
@@ -16,3 +16,4 @@ test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
18
  /*.html
19
+ *.ruby-version
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
@@ -36,7 +36,7 @@ module MemoryRecord
36
36
  hash
37
37
  end
38
38
 
39
- def as_json(**options)
39
+ def as_json(options = {})
40
40
  serializable_hash(options)
41
41
  end
42
42
 
@@ -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.18'
2
+ VERSION = '0.0.20'
3
3
  end
@@ -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 "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.18
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: 2020-04-30 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
@@ -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.0.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