bright_serializer 0.2.0 → 0.2.5
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 +4 -4
- data/.rubocop.yml +7 -1
- data/CHANGELOG.md +23 -1
- data/Gemfile.lock +40 -33
- data/bright_serializer.gemspec +1 -1
- data/lib/bright_serializer/attribute.rb +1 -1
- data/lib/bright_serializer/entity/base.rb +1 -1
- data/lib/bright_serializer/entity/parser.rb +1 -2
- data/lib/bright_serializer/inflector.rb +16 -0
- data/lib/bright_serializer/serializer.rb +4 -1
- data/lib/bright_serializer/version.rb +1 -1
- metadata +2 -3
- data/.github/workflows/build.yml +0 -23
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ae3444c6b0be4fc77c338286c25e97acc5501aeac9af722a53bf1182dad6034c
|
|
4
|
+
data.tar.gz: 75461556470937cd50f91326e591c73aea3a089cbfe3961200a8420d6682c019
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 17d5c832abe849c799e4c5240bdfda4ed8e292f0284a3004908d0e812a0bb90268f85be8f1e416c83b596446aec0bcef38d02d1e26e607fe6da902dfc6daa69f
|
|
7
|
+
data.tar.gz: 7e78a38854d53707fd8f6cd4eb3df7368f045fc20f086df1fd592c07cf723b69de458c2bfc2890457d245633f716bbc1e8d379cb0318f8486809fc42ff37fd72
|
data/.rubocop.yml
CHANGED
|
@@ -2,6 +2,9 @@ require:
|
|
|
2
2
|
- rubocop-performance
|
|
3
3
|
- rubocop-rspec
|
|
4
4
|
|
|
5
|
+
AllCops:
|
|
6
|
+
NewCops: enable
|
|
7
|
+
|
|
5
8
|
Metrics/BlockLength:
|
|
6
9
|
Enabled: false
|
|
7
10
|
|
|
@@ -30,4 +33,7 @@ Metrics/CyclomaticComplexity:
|
|
|
30
33
|
Enabled: false
|
|
31
34
|
|
|
32
35
|
Metrics/AbcSize:
|
|
33
|
-
Enabled: false
|
|
36
|
+
Enabled: false
|
|
37
|
+
|
|
38
|
+
RSpec/NestedGroups:
|
|
39
|
+
Enabled: false
|
data/CHANGELOG.md
CHANGED
|
@@ -4,11 +4,33 @@
|
|
|
4
4
|
|
|
5
5
|
* Your contribution
|
|
6
6
|
|
|
7
|
+
## 0.2.5 (2021-03-08)
|
|
8
|
+
|
|
9
|
+
* When serializing an Hash, check present of the key before trying string ([#57](https://github.com/petalmd/bright_serializer/pull/57))
|
|
10
|
+
|
|
11
|
+
## 0.2.4 (2021-02-19)
|
|
12
|
+
|
|
13
|
+
* Try symbol and string keys when the object to serialize is an Hash ([#54](https://github.com/petalmd/bright_serializer/pull/54))
|
|
14
|
+
|
|
15
|
+
## 0.2.3 (2021-01-04)
|
|
16
|
+
|
|
17
|
+
* Update dependencies ([v0.2.2...v0.2.3](https://github.com/petalmd/bright_serializer/compare/v0.2.2...v0.2.3))
|
|
18
|
+
|
|
19
|
+
## 0.2.2 (2020-07-22)
|
|
20
|
+
|
|
21
|
+
* Run CI build on all supported Ruby versions ([#11](https://github.com/petalmd/bright_serializer/pull/11))
|
|
22
|
+
* Update Rubocop 0.78.0 => 0.88.0 and run auto-correction
|
|
23
|
+
* Deep transform entity keys ([#12](https://github.com/petalmd/bright_serializer/pull/12))
|
|
24
|
+
|
|
25
|
+
## 0.2.1 (2020-07-21)
|
|
26
|
+
|
|
27
|
+
* Handle set_key_transform inherited from a parent serializer ([#10](https://github.com/petalmd/bright_serializer/pull/10))
|
|
28
|
+
|
|
7
29
|
## 0.2.0 (2020-07-17)
|
|
8
30
|
|
|
9
31
|
* Add RubyGems version badge
|
|
10
32
|
* Handle inherit from a parent serializer
|
|
11
|
-
* Define entity in serializer for grape_swagger (#9)
|
|
33
|
+
* Define entity in serializer for grape_swagger ([#9](https://github.com/petalmd/bright_serializer/pull/9))
|
|
12
34
|
|
|
13
35
|
## 0.1.1 (2020-07-13)
|
|
14
36
|
|
data/Gemfile.lock
CHANGED
|
@@ -1,52 +1,59 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
bright_serializer (0.2.
|
|
4
|
+
bright_serializer (0.2.5)
|
|
5
5
|
oj (~> 3)
|
|
6
6
|
|
|
7
7
|
GEM
|
|
8
8
|
remote: https://rubygems.org/
|
|
9
9
|
specs:
|
|
10
|
-
ast (2.4.
|
|
11
|
-
concurrent-ruby (1.1.
|
|
10
|
+
ast (2.4.1)
|
|
11
|
+
concurrent-ruby (1.1.7)
|
|
12
12
|
diff-lcs (1.4.4)
|
|
13
|
-
faker (2.
|
|
14
|
-
i18n (>= 1.6, <
|
|
15
|
-
i18n (1.
|
|
13
|
+
faker (2.15.1)
|
|
14
|
+
i18n (>= 1.6, < 2)
|
|
15
|
+
i18n (1.8.5)
|
|
16
16
|
concurrent-ruby (~> 1.0)
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
ast (~> 2.4.0)
|
|
17
|
+
oj (3.11.1)
|
|
18
|
+
parallel (1.20.1)
|
|
19
|
+
parser (3.0.0.0)
|
|
20
|
+
ast (~> 2.4.1)
|
|
22
21
|
rainbow (3.0.0)
|
|
23
|
-
rake (13.0.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
rspec-
|
|
28
|
-
|
|
29
|
-
rspec-
|
|
30
|
-
rspec-
|
|
22
|
+
rake (13.0.3)
|
|
23
|
+
regexp_parser (2.0.3)
|
|
24
|
+
rexml (3.2.4)
|
|
25
|
+
rspec (3.10.0)
|
|
26
|
+
rspec-core (~> 3.10.0)
|
|
27
|
+
rspec-expectations (~> 3.10.0)
|
|
28
|
+
rspec-mocks (~> 3.10.0)
|
|
29
|
+
rspec-core (3.10.0)
|
|
30
|
+
rspec-support (~> 3.10.0)
|
|
31
|
+
rspec-expectations (3.10.0)
|
|
31
32
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
32
|
-
rspec-support (~> 3.
|
|
33
|
-
rspec-mocks (3.
|
|
33
|
+
rspec-support (~> 3.10.0)
|
|
34
|
+
rspec-mocks (3.10.0)
|
|
34
35
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
35
|
-
rspec-support (~> 3.
|
|
36
|
-
rspec-support (3.
|
|
37
|
-
rubocop (0.
|
|
38
|
-
jaro_winkler (~> 1.5.1)
|
|
36
|
+
rspec-support (~> 3.10.0)
|
|
37
|
+
rspec-support (3.10.0)
|
|
38
|
+
rubocop (0.93.1)
|
|
39
39
|
parallel (~> 1.10)
|
|
40
|
-
parser (>= 2.
|
|
40
|
+
parser (>= 2.7.1.5)
|
|
41
41
|
rainbow (>= 2.2.2, < 4.0)
|
|
42
|
+
regexp_parser (>= 1.8)
|
|
43
|
+
rexml
|
|
44
|
+
rubocop-ast (>= 0.6.0)
|
|
42
45
|
ruby-progressbar (~> 1.7)
|
|
43
|
-
unicode-display_width (>= 1.4.0, <
|
|
44
|
-
rubocop-
|
|
45
|
-
|
|
46
|
-
rubocop-
|
|
47
|
-
rubocop (>= 0.
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
|
47
|
+
rubocop-ast (1.4.0)
|
|
48
|
+
parser (>= 2.7.1.5)
|
|
49
|
+
rubocop-performance (1.9.2)
|
|
50
|
+
rubocop (>= 0.90.0, < 2.0)
|
|
51
|
+
rubocop-ast (>= 0.4.0)
|
|
52
|
+
rubocop-rspec (1.44.1)
|
|
53
|
+
rubocop (~> 0.87)
|
|
54
|
+
rubocop-ast (>= 0.7.1)
|
|
55
|
+
ruby-progressbar (1.11.0)
|
|
56
|
+
unicode-display_width (1.7.0)
|
|
50
57
|
|
|
51
58
|
PLATFORMS
|
|
52
59
|
ruby
|
data/bright_serializer.gemspec
CHANGED
|
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
|
|
|
30
30
|
# Specify which files should be added to the gem when it is released.
|
|
31
31
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
32
32
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
33
|
-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
33
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|.github)/}) }
|
|
34
34
|
end
|
|
35
35
|
spec.bindir = 'exe'
|
|
36
36
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
@@ -21,7 +21,7 @@ module BrightSerializer
|
|
|
21
21
|
if @block
|
|
22
22
|
@block.arity.abs == 1 ? object.instance_eval(&@block) : object.instance_exec(object, params, &@block)
|
|
23
23
|
elsif object.is_a?(Hash)
|
|
24
|
-
object[key]
|
|
24
|
+
object.key?(key) ? object[key] : object[key.to_s]
|
|
25
25
|
else
|
|
26
26
|
object.send(key)
|
|
27
27
|
end
|
|
@@ -59,5 +59,21 @@ class Inflector
|
|
|
59
59
|
end
|
|
60
60
|
end
|
|
61
61
|
end
|
|
62
|
+
|
|
63
|
+
# File active_support/core_ext/hash/keys.rb, line 156
|
|
64
|
+
def deep_transform_keys_in_object!(object, &block)
|
|
65
|
+
case object
|
|
66
|
+
when Hash
|
|
67
|
+
object.keys.each do |key| # rubocop:disable Style/HashEachMethods
|
|
68
|
+
value = object.delete(key)
|
|
69
|
+
object[yield(key)] = deep_transform_keys_in_object!(value, &block)
|
|
70
|
+
end
|
|
71
|
+
object
|
|
72
|
+
when Array
|
|
73
|
+
object.map! { |e| deep_transform_keys_in_object!(e, &block) }
|
|
74
|
+
else
|
|
75
|
+
object
|
|
76
|
+
end
|
|
77
|
+
end
|
|
62
78
|
end
|
|
63
79
|
end
|
|
@@ -12,6 +12,7 @@ module BrightSerializer
|
|
|
12
12
|
DEFAULT_OJ_OPTIONS = { mode: :compat, time_format: :ruby, use_to_json: true }.freeze
|
|
13
13
|
|
|
14
14
|
def self.included(base)
|
|
15
|
+
super
|
|
15
16
|
base.extend ClassMethods
|
|
16
17
|
base.instance_variable_set(:@attributes_to_serialize, [])
|
|
17
18
|
end
|
|
@@ -54,6 +55,7 @@ module BrightSerializer
|
|
|
54
55
|
super
|
|
55
56
|
subclass.instance_variable_set(:@attributes_to_serialize, []) unless subclass.attributes_to_serialize
|
|
56
57
|
subclass.attributes_to_serialize.concat(@attributes_to_serialize)
|
|
58
|
+
subclass.instance_variable_set(:@transform_method, @transform_method) unless subclass.transform_method
|
|
57
59
|
end
|
|
58
60
|
|
|
59
61
|
def attributes(*attributes, **options, &block)
|
|
@@ -85,7 +87,8 @@ module BrightSerializer
|
|
|
85
87
|
def entity
|
|
86
88
|
{}.tap do |result|
|
|
87
89
|
@attributes_to_serialize.each do |attribute|
|
|
88
|
-
entity_value = attribute.entity&.to_h ||
|
|
90
|
+
entity_value = attribute.entity&.to_h ||
|
|
91
|
+
BrightSerializer::Entity::Base::DEFAULT_DEFINITION
|
|
89
92
|
result.merge!(attribute.transformed_key => entity_value)
|
|
90
93
|
end
|
|
91
94
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bright_serializer
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jean-Francis Bastien
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2021-03-08 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: oj
|
|
@@ -87,7 +87,6 @@ executables: []
|
|
|
87
87
|
extensions: []
|
|
88
88
|
extra_rdoc_files: []
|
|
89
89
|
files:
|
|
90
|
-
- ".github/workflows/build.yml"
|
|
91
90
|
- ".gitignore"
|
|
92
91
|
- ".rspec"
|
|
93
92
|
- ".rubocop.yml"
|
data/.github/workflows/build.yml
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
name: Build
|
|
2
|
-
|
|
3
|
-
on: [push]
|
|
4
|
-
|
|
5
|
-
jobs:
|
|
6
|
-
build:
|
|
7
|
-
|
|
8
|
-
runs-on: ubuntu-latest
|
|
9
|
-
|
|
10
|
-
steps:
|
|
11
|
-
- uses: actions/checkout@v1
|
|
12
|
-
- name: Set up Ruby 2.7
|
|
13
|
-
uses: actions/setup-ruby@v1
|
|
14
|
-
with:
|
|
15
|
-
ruby-version: 2.7
|
|
16
|
-
- name: Bundle install
|
|
17
|
-
run: |
|
|
18
|
-
gem install bundler
|
|
19
|
-
bundle install --jobs 4 --retry 3
|
|
20
|
-
- name: Specs
|
|
21
|
-
run: bundle exec rake
|
|
22
|
-
- name: Rubocop
|
|
23
|
-
run: bundle exec rubocop --parallel
|