memory_record 0.0.15 → 0.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5782c36c4656fbfea525ca83150171f5e7d72ef6e12c4a3bc5bb0c9cbebf999d
4
- data.tar.gz: ae386371adb57bc10e97a3ec86c732eeb343fa53912ae7fc75fe6ddb41d15ae0
3
+ metadata.gz: bd17d93951ecd00a25da9401976fd6001479b0a259064154d5871459b9d28f86
4
+ data.tar.gz: b14110ba80d0173912f0cfc75ea7f1ff8c193f07b5ffb87e7886bf23f91482e9
5
5
  SHA512:
6
- metadata.gz: 2c93d3d610e960a3a6b8da1041e8e6814de11ea93f5b341a18c39d8f80cf502b7bb05f1b07f1fa32fe575270809df31de441928bb0ec123cde3d0c02c7335a04
7
- data.tar.gz: fb32e99ced614b0dc378662072f769e59d2bf28578537d48f734a078d793fc2b861f99bd96dff1496ed62ce80ddf10717ef4a861beff64a794ce4b00fd739866
6
+ metadata.gz: 1500621e070dcce0990e6a51b72aece8cdd85fb127f27bf50f0622f770db76d3beabac8ec851e28f0f04bb1e147fd9a52c59d96f706a8b236a20ddd34356310c
7
+ data.tar.gz: c5560f63361c6770e9f3e0d79e61fa547930112a2cf61250ba8dd846d1b212d7666f4fa7122fcd6a2e9cd7ea125eefd46f5921a5ad1cac035a5dac6e3bab5dab
data/README.md CHANGED
@@ -27,7 +27,44 @@ $ bundle install
27
27
 
28
28
  ## Examples
29
29
 
30
- ### Basic usage
30
+ ### Basic usage 1
31
+
32
+ ```ruby
33
+ class Palette
34
+ include MemoryRecord
35
+ memory_record [
36
+ { key: :coral, },
37
+ { key: :tomato, },
38
+ { key: :gold, },
39
+ ]
40
+ end
41
+
42
+ Palette[:tomato].key # => :tomato
43
+ Palette[:tomato].name # => "tomato"
44
+ Palette[:tomato].code # => 1
45
+ ```
46
+
47
+ ### Basic usage 2
48
+
49
+ ```ruby
50
+ class Palette
51
+ include MemoryRecord
52
+ memory_record [
53
+ { key: :coral, r: 255, g: 127, b: 0 },
54
+ { key: :tomato, r: 255, g: 99, b: 71 },
55
+ { key: :gold, r: 255, g: 215, b: 0 },
56
+ ]
57
+ end
58
+
59
+ Palette[:tomato].key # => :tomato
60
+ Palette[:tomato].name # => "tomato"
61
+ Palette[:tomato].code # => 1
62
+ Palette[:tomato].r # => 255
63
+ Palette[:tomato].g # => 99
64
+ Palette[:tomato].b # => 71
65
+ ```
66
+
67
+ ### Basic usage 3
31
68
 
32
69
  ```ruby
33
70
  class Palette
@@ -53,6 +90,7 @@ end
53
90
 
54
91
  Palette[:tomato].key # => :tomato
55
92
  Palette[:tomato].name # => "Tomato"
93
+ Palette[:tomato].code # => 1
56
94
  Palette[:tomato].rgb # => [255, 99, 71]
57
95
  Palette[:tomato].hex # => "#FF6347"
58
96
  Palette.collect(&:hex) # => ["#FF7F00", "#FF6347", "#FFD700"]
@@ -217,6 +255,7 @@ class ColorInfo
217
255
  end
218
256
 
219
257
  color_info = ColorInfo.first
258
+ color_info.as_json # => {:key=>:blue, :rgb=>[0, 0, 255], :a=>1, :code=>0}
220
259
  color_info.as_json(only: :key) # => {:key => :blue}
221
260
  color_info.as_json(except: [:rgb, :code]) # => {:key => :blue}
222
261
  color_info.as_json(only: [], methods: :hex) # => {:hex => "#0000FF"}
@@ -224,6 +263,7 @@ color_info.as_json(only: [], include: {children: {only: :x}} ) # => {:children =
224
263
 
225
264
  ColorInfo.as_json(only: :key) # => [{:key=>:blue}, {:key=>:red}]
226
265
  ColorInfo.to_json(only: :key) # => "[{\"key\":\"blue\"},{\"key\":\"red\"}]"
266
+ ```
227
267
 
228
268
  #### Case of ActiveModelSerializers
229
269
 
@@ -38,6 +38,7 @@ end
38
38
 
39
39
  ColorInfo.first.key # => :blue
40
40
 
41
+ ColorInfo.first.as_json # => {:key=>:blue, :rgb=>[0, 0, 255], :a=>1, :code=>0}
41
42
  ColorInfo.first.as_json(only: :key) # => {:key=>:blue}
42
43
  ColorInfo.first.as_json(except: [:rgb, :code, :a]) # => {:key=>:blue}
43
44
  ColorInfo.first.as_json(only: [], methods: :hex) # => {:hex=>"#0000FF"}
@@ -2,7 +2,7 @@ require "bundler/inline"
2
2
 
3
3
  gemfile do
4
4
  gem "memory_record", path: ".."
5
- gem "active_model_serializers"
5
+ gem "active_model_serializers", "0.10.7" # It does not work with version 0.10.10
6
6
  end
7
7
 
8
8
  class ColorInfo
@@ -18,5 +18,5 @@ class ColorInfoSerializer < ActiveModel::Serializer
18
18
  end
19
19
 
20
20
  pp ActiveModelSerializers::SerializableResource.new(ColorInfo.first).as_json # => {:key=>:blue, :name=>"blue"}
21
- # >> [active_model_serializers] Rendered ColorInfoSerializer with ActiveModelSerializers::Adapter::Attributes (0.14ms)
21
+ # >> [active_model_serializers] Rendered ColorInfoSerializer with ActiveModelSerializers::Adapter::Attributes (0.12ms)
22
22
  # >> {:key=>:blue, :name=>"blue"}
@@ -4,21 +4,21 @@ require 'memory_record'
4
4
  class A
5
5
  include MemoryRecord
6
6
  memory_record [
7
- { key: :a, x: 1, y: 2 },
7
+ { key: :foo },
8
8
  ]
9
9
 
10
- def z
11
- x + y
10
+ def name
11
+ super.to_s.upcase
12
12
  end
13
13
  end
14
14
 
15
15
  class B < A
16
16
  memory_record_reset superclass.collect(&:attributes)
17
17
 
18
- def z
19
- super * 2
18
+ def name
19
+ "(#{super})"
20
20
  end
21
21
  end
22
22
 
23
- B.values # => [#<B:0x00007feea40395b8 @attributes={:key=>:a, :x=>1, :y=>2, :code=>0}>]
24
- B.first.z # => 6
23
+ A.first.name # => "FOO"
24
+ B.first.name # => "(FOO)"
@@ -1,3 +1,3 @@
1
1
  module MemoryRecord
2
- VERSION = '0.0.15'
2
+ VERSION = '0.0.17'
3
3
  end
@@ -298,22 +298,23 @@ RSpec.describe MemoryRecord do
298
298
  end
299
299
  end
300
300
 
301
- context 'active_model_serializers' do
302
- require "active_model_serializers"
303
-
304
- class ColorInfo
305
- include MemoryRecord
306
- memory_record [
307
- { key: :blue, },
308
- ]
309
- end
310
-
311
- class ColorInfoSerializer < ActiveModel::Serializer
312
- attributes :key
313
- end
314
-
315
- it do
316
- assert { ActiveModelSerializers::SerializableResource.new(ColorInfo.first).as_json == {:key => :blue} }
317
- end
318
- end
301
+ # broken with version 0.10.10
302
+ # context 'active_model_serializers' do
303
+ # require "active_model_serializers"
304
+ #
305
+ # class ColorInfo
306
+ # include MemoryRecord
307
+ # memory_record [
308
+ # { key: :blue, },
309
+ # ]
310
+ # end
311
+ #
312
+ # class ColorInfoSerializer < ActiveModel::Serializer
313
+ # attributes :key
314
+ # end
315
+ #
316
+ # it do
317
+ # assert { ActiveModelSerializers::SerializableResource.new(ColorInfo.first).as_json == {:key => :blue} }
318
+ # end
319
+ # end
319
320
  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.15
4
+ version: 0.0.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - akicho8
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-25 00:00:00.000000000 Z
11
+ date: 2019-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -161,8 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
161
  - !ruby/object:Gem::Version
162
162
  version: '0'
163
163
  requirements: []
164
- rubyforge_project:
165
- rubygems_version: 2.7.6
164
+ rubygems_version: 3.0.3
166
165
  signing_key:
167
166
  specification_version: 4
168
167
  summary: A simple library that handles a few records easily