seri 1.1.6 → 1.1.11
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/.circleci/config.yml +2 -1
- data/.rubocop.yml +30 -0
- data/Gemfile.lock +32 -29
- data/LICENSE.txt +1 -1
- data/lib/serializer/value.rb +43 -41
- data/lib/serializer/value_fetcher.rb +49 -47
- data/lib/serializer/version.rb +1 -1
- data/seri.gemspec +3 -4
- metadata +11 -13
- data/bin/console +0 -14
- data/bin/setup +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93d4a3c7d7f2166ee7b8f3a32a398b4047f46d19a73ce59cca497cc74843cfe4
|
4
|
+
data.tar.gz: 4e1e7a46dc70f2f1a0d9ffb93b11b625da277beee9593348736f91fd912a31f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ce7148279857a7c35a535e250124dbb2b2a3957b246ab0c737d631ec9129451977f53e9abdb65d403acd72650587648d497dad330c80f710c31033b5cbff563
|
7
|
+
data.tar.gz: d433c26c41157799e77a6f8d786b3d7418cfe6147fe70187dd34dc9c44eea617b6ce9918df0c375e77e2fa1203607d968e1c7a3a098cd9b8c1cb365a53ae71ec
|
data/.circleci/config.yml
CHANGED
@@ -4,7 +4,7 @@ jobs:
|
|
4
4
|
build:
|
5
5
|
docker:
|
6
6
|
# specify the version you desire here
|
7
|
-
- image: circleci/ruby:2.
|
7
|
+
- image: circleci/ruby:2.7.1
|
8
8
|
|
9
9
|
working_directory: ~/repo
|
10
10
|
|
@@ -21,6 +21,7 @@ jobs:
|
|
21
21
|
- run:
|
22
22
|
name: install dependencies
|
23
23
|
command: |
|
24
|
+
gem install bundler:1.17.3
|
24
25
|
bundle install --jobs=4 --retry=3 --path vendor/bundle
|
25
26
|
|
26
27
|
- save_cache:
|
data/.rubocop.yml
CHANGED
@@ -3,6 +3,36 @@ Metrics/BlockLength:
|
|
3
3
|
- 'spec/**/*.rb'
|
4
4
|
Style/Documentation:
|
5
5
|
Enabled: false
|
6
|
+
Style/FrozenStringLiteralComment:
|
7
|
+
Enabled: false
|
6
8
|
# This is causing breaking changes:
|
7
9
|
Style/ExpandPathArguments:
|
8
10
|
Enabled: false
|
11
|
+
Layout/EmptyLinesAroundAttributeAccessor:
|
12
|
+
Enabled: false
|
13
|
+
Layout/SpaceAroundMethodCallOperator:
|
14
|
+
Enabled: false
|
15
|
+
Lint/DeprecatedOpenSSLConstant:
|
16
|
+
Enabled: false
|
17
|
+
Lint/MixedRegexpCaptureTypes:
|
18
|
+
Enabled: false
|
19
|
+
Lint/RaiseException:
|
20
|
+
Enabled: false
|
21
|
+
Lint/StructNewOverride:
|
22
|
+
Enabled: false
|
23
|
+
Style/ExponentialNotation:
|
24
|
+
Enabled: false
|
25
|
+
Style/HashEachMethods:
|
26
|
+
Enabled: false
|
27
|
+
Style/HashTransformKeys:
|
28
|
+
Enabled: false
|
29
|
+
Style/HashTransformValues:
|
30
|
+
Enabled: false
|
31
|
+
Style/RedundantFetchBlock:
|
32
|
+
Enabled: false
|
33
|
+
Style/RedundantRegexpCharacterClass:
|
34
|
+
Enabled: false
|
35
|
+
Style/RedundantRegexpEscape:
|
36
|
+
Enabled: false
|
37
|
+
Style/SlicingWithRange:
|
38
|
+
Enabled: false
|
data/Gemfile.lock
CHANGED
@@ -1,54 +1,57 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
seri (1.1.
|
4
|
+
seri (1.1.11)
|
5
5
|
oj (~> 3.7)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
ast (2.4.
|
10
|
+
ast (2.4.1)
|
11
11
|
diff-lcs (1.3)
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
ast (~> 2.4.0)
|
17
|
-
psych (3.1.0)
|
12
|
+
oj (3.10.6)
|
13
|
+
parallel (1.19.2)
|
14
|
+
parser (2.7.1.4)
|
15
|
+
ast (~> 2.4.1)
|
18
16
|
rainbow (3.0.0)
|
19
|
-
rake (
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
rspec-
|
24
|
-
|
25
|
-
rspec-
|
26
|
-
rspec-
|
17
|
+
rake (13.0.1)
|
18
|
+
regexp_parser (1.7.1)
|
19
|
+
rexml (3.2.4)
|
20
|
+
rspec (3.9.0)
|
21
|
+
rspec-core (~> 3.9.0)
|
22
|
+
rspec-expectations (~> 3.9.0)
|
23
|
+
rspec-mocks (~> 3.9.0)
|
24
|
+
rspec-core (3.9.1)
|
25
|
+
rspec-support (~> 3.9.1)
|
26
|
+
rspec-expectations (3.9.1)
|
27
27
|
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
-
rspec-support (~> 3.
|
29
|
-
rspec-mocks (3.
|
28
|
+
rspec-support (~> 3.9.0)
|
29
|
+
rspec-mocks (3.9.1)
|
30
30
|
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
-
rspec-support (~> 3.
|
32
|
-
rspec-support (3.
|
33
|
-
rubocop (0.
|
34
|
-
jaro_winkler (~> 1.5.1)
|
31
|
+
rspec-support (~> 3.9.0)
|
32
|
+
rspec-support (3.9.2)
|
33
|
+
rubocop (0.86.0)
|
35
34
|
parallel (~> 1.10)
|
36
|
-
parser (>= 2.
|
37
|
-
psych (>= 3.1.0)
|
35
|
+
parser (>= 2.7.0.1)
|
38
36
|
rainbow (>= 2.2.2, < 4.0)
|
37
|
+
regexp_parser (>= 1.7)
|
38
|
+
rexml
|
39
|
+
rubocop-ast (>= 0.0.3, < 1.0)
|
39
40
|
ruby-progressbar (~> 1.7)
|
40
|
-
unicode-display_width (>= 1.4.0, <
|
41
|
-
|
42
|
-
|
41
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
42
|
+
rubocop-ast (0.0.3)
|
43
|
+
parser (>= 2.7.0.1)
|
44
|
+
ruby-progressbar (1.10.1)
|
45
|
+
unicode-display_width (1.7.0)
|
43
46
|
|
44
47
|
PLATFORMS
|
45
48
|
ruby
|
46
49
|
|
47
50
|
DEPENDENCIES
|
48
51
|
bundler (~> 1.16)
|
49
|
-
rake (~>
|
52
|
+
rake (~> 13.0)
|
50
53
|
rspec (~> 3.0)
|
51
|
-
rubocop (~> 0.
|
54
|
+
rubocop (~> 0.82)
|
52
55
|
seri!
|
53
56
|
|
54
57
|
BUNDLED WITH
|
data/LICENSE.txt
CHANGED
data/lib/serializer/value.rb
CHANGED
@@ -1,58 +1,60 @@
|
|
1
|
-
class
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
class Serializer
|
2
|
+
class Value
|
3
|
+
def initialize(attribute, scope = nil)
|
4
|
+
@attribute = attribute
|
5
|
+
@scope = scope
|
6
|
+
end
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
def extraction_key
|
9
|
+
@attribute.from || @attribute.key
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
def precondition?
|
13
|
+
raise NotImplementedError, 'needs a method called precondition?'
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
16
|
+
def value
|
17
|
+
raise NotImplementedError, 'needs a method called value'
|
18
|
+
end
|
17
19
|
end
|
18
|
-
end
|
19
20
|
|
20
|
-
class StaticValue < Value
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
class StaticValue < Value
|
22
|
+
def precondition?
|
23
|
+
@attribute.options.key?(:static_value)
|
24
|
+
end
|
24
25
|
|
25
|
-
|
26
|
-
|
26
|
+
def value
|
27
|
+
@attribute.options.fetch(:static_value)
|
28
|
+
end
|
27
29
|
end
|
28
|
-
end
|
29
30
|
|
30
|
-
class SerializedValue < Value
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
class SerializedValue < Value
|
32
|
+
def precondition?
|
33
|
+
@scope.respond_to?(extraction_key)
|
34
|
+
end
|
34
35
|
|
35
|
-
|
36
|
-
|
36
|
+
def value
|
37
|
+
@scope.public_send(extraction_key)
|
38
|
+
end
|
37
39
|
end
|
38
|
-
end
|
39
40
|
|
40
|
-
class HashValue < Value
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
class HashValue < Value
|
42
|
+
def precondition?
|
43
|
+
@scope.is_a?(Hash)
|
44
|
+
end
|
44
45
|
|
45
|
-
|
46
|
-
|
46
|
+
def value
|
47
|
+
@scope[extraction_key]
|
48
|
+
end
|
47
49
|
end
|
48
|
-
end
|
49
50
|
|
50
|
-
class ObjectValue < Value
|
51
|
-
|
52
|
-
|
53
|
-
|
51
|
+
class ObjectValue < Value
|
52
|
+
def precondition?
|
53
|
+
@scope.respond_to?(extraction_key)
|
54
|
+
end
|
54
55
|
|
55
|
-
|
56
|
-
|
56
|
+
def value
|
57
|
+
@scope.public_send(extraction_key)
|
58
|
+
end
|
57
59
|
end
|
58
60
|
end
|
@@ -1,59 +1,61 @@
|
|
1
|
-
class
|
2
|
-
class
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
1
|
+
class Serializer
|
2
|
+
class ValueFetcher
|
3
|
+
class SerializerError < StandardError; end
|
4
|
+
|
5
|
+
ARRAYS = %w[
|
6
|
+
Array
|
7
|
+
ActiveRecord_AssociationRelation
|
8
|
+
ActiveRecord_Associations_CollectionProxy
|
9
|
+
].freeze
|
10
|
+
|
11
|
+
def self.fetch(attribute, object, serializer)
|
12
|
+
new(attribute, object, serializer).fetch
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
+
private_class_method :new
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
17
|
+
def initialize(attribute, object, serializer)
|
18
|
+
@attribute = attribute
|
19
|
+
@values = [
|
20
|
+
StaticValue.new(attribute),
|
21
|
+
SerializedValue.new(attribute, serializer),
|
22
|
+
HashValue.new(attribute, object),
|
23
|
+
ObjectValue.new(attribute, object)
|
24
|
+
]
|
25
|
+
end
|
25
26
|
|
26
|
-
|
27
|
-
|
27
|
+
def fetch
|
28
|
+
serializer = @attribute.serializer
|
28
29
|
|
29
|
-
|
30
|
+
return value unless serializer
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
if array?
|
33
|
+
value.map { |item| serializer.new(item).to_h }
|
34
|
+
else
|
35
|
+
serializer.new(value).to_h
|
36
|
+
end
|
35
37
|
end
|
36
|
-
end
|
37
38
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
39
|
+
# Fetches a value from an attribute by checking if there's a ..
|
40
|
+
# .. static value set, or a ..
|
41
|
+
# .. method defined in the serializer, or a ..
|
42
|
+
# .. method/attribute defined in the object or ..
|
43
|
+
# .. it raises an error
|
44
|
+
def value
|
45
|
+
@value ||= begin
|
46
|
+
extracted_value = @values.detect(&:precondition?)
|
47
|
+
|
48
|
+
if extracted_value.nil?
|
49
|
+
raise SerializerError,
|
50
|
+
"unknown attribute '#{@values[0].extraction_key}'"
|
51
|
+
end
|
52
|
+
|
53
|
+
extracted_value.value
|
50
54
|
end
|
51
|
-
|
52
|
-
extracted_value.value
|
53
55
|
end
|
54
|
-
end
|
55
56
|
|
56
|
-
|
57
|
-
|
57
|
+
def array?
|
58
|
+
ARRAYS.any? { |match| value.class.to_s.end_with?(match) }
|
59
|
+
end
|
58
60
|
end
|
59
61
|
end
|
data/lib/serializer/version.rb
CHANGED
data/seri.gemspec
CHANGED
@@ -21,14 +21,13 @@ Gem::Specification.new do |spec|
|
|
21
21
|
f.match(%r{^(test|spec|features)/})
|
22
22
|
end
|
23
23
|
end
|
24
|
-
|
25
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
|
26
25
|
spec.require_paths = ['lib']
|
27
26
|
|
28
27
|
spec.add_dependency 'oj', '~> 3.7'
|
29
28
|
|
30
29
|
spec.add_development_dependency 'bundler', '~> 1.16'
|
31
|
-
spec.add_development_dependency 'rake', '~>
|
30
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
32
31
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
33
|
-
spec.add_development_dependency 'rubocop', '~> 0.
|
32
|
+
spec.add_development_dependency 'rubocop', '~> 0.82'
|
34
33
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seri
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- grdw
|
8
|
-
autorequire:
|
9
|
-
bindir:
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oj
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '13.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '13.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.
|
75
|
+
version: '0.82'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0.
|
82
|
+
version: '0.82'
|
83
83
|
description: A basic serializer
|
84
84
|
email:
|
85
85
|
- gerard@wetransfer.com
|
@@ -98,8 +98,6 @@ files:
|
|
98
98
|
- LICENSE.txt
|
99
99
|
- README.md
|
100
100
|
- Rakefile
|
101
|
-
- bin/console
|
102
|
-
- bin/setup
|
103
101
|
- lib/serializer.rb
|
104
102
|
- lib/serializer/group_serializer.rb
|
105
103
|
- lib/serializer/value.rb
|
@@ -110,7 +108,7 @@ homepage: https://github.com/grdw/seri
|
|
110
108
|
licenses:
|
111
109
|
- MIT
|
112
110
|
metadata: {}
|
113
|
-
post_install_message:
|
111
|
+
post_install_message:
|
114
112
|
rdoc_options: []
|
115
113
|
require_paths:
|
116
114
|
- lib
|
@@ -125,8 +123,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
123
|
- !ruby/object:Gem::Version
|
126
124
|
version: '0'
|
127
125
|
requirements: []
|
128
|
-
rubygems_version: 3.
|
129
|
-
signing_key:
|
126
|
+
rubygems_version: 3.1.2
|
127
|
+
signing_key:
|
130
128
|
specification_version: 4
|
131
129
|
summary: A basic serializer
|
132
130
|
test_files: []
|
data/bin/console
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'bundler/setup'
|
4
|
-
require 'serializer'
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require 'pry'
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require 'irb'
|
14
|
-
IRB.start(__FILE__)
|