seri 1.1.9 → 1.1.10

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: 3f3d7fa0dae40ce8b0e43a174185c435c048fed3ae38242a735592ce1d5bc1bc
4
- data.tar.gz: b70a1a82b0b75b6396ba5cf78db892b23cd64d60c75a9d7948a7b667af9e9b51
3
+ metadata.gz: 394f107e4e7ca59a2c4951316e4223ed8f9dec2d14d70610be80079a69974cb2
4
+ data.tar.gz: 59e58c2f0802df12dff7f3ec1da988978d95c2c1e427113124b3c488fa4bed0c
5
5
  SHA512:
6
- metadata.gz: 323161f0982a5f25b138b63e929fde6452378efd35023c69761476b653fe6d23d6ddcb5571ff3ee82fe658710f5c9e60bb493dd4c19fe7320632362c49d24558
7
- data.tar.gz: d20c18753f7d19bce1fbe02c0466c4e5ff9d6913568b29f4dc2490a8a156b67c7dd6980e21986192f548f48e84e78f154ba4c5fe299255ac7d90e534392c05a0
6
+ metadata.gz: 004c1bf17667b3da131e4695e9a093d04d4a975ebf4f86644b0bdd4765753b4549120115484ab8285d275b938cc299e31e6270359a9a37a87b5ca055c44f885c
7
+ data.tar.gz: c3870a1ecd13aae4f159fa8b82547c06edb0015bad397822bb209a0d34e85b2d535545bd5d03ddd7defa542b5f316f352f3c57f7208d28c14224153e79ebc173
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.5.3-node-browsers
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,8 @@ 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
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- seri (1.1.9)
4
+ seri (1.1.10)
5
5
  oj (~> 3.7)
6
6
 
7
7
  GEM
@@ -10,13 +10,13 @@ GEM
10
10
  ast (2.4.0)
11
11
  diff-lcs (1.3)
12
12
  jaro_winkler (1.5.4)
13
- oj (3.10.5)
13
+ oj (3.10.6)
14
14
  parallel (1.19.1)
15
- parser (2.7.0.5)
15
+ parser (2.7.1.2)
16
16
  ast (~> 2.4.0)
17
- psych (3.1.0)
18
17
  rainbow (3.0.0)
19
18
  rake (13.0.1)
19
+ rexml (3.2.4)
20
20
  rspec (3.9.0)
21
21
  rspec-core (~> 3.9.0)
22
22
  rspec-expectations (~> 3.9.0)
@@ -30,16 +30,16 @@ GEM
30
30
  diff-lcs (>= 1.2.0, < 2.0)
31
31
  rspec-support (~> 3.9.0)
32
32
  rspec-support (3.9.2)
33
- rubocop (0.67.2)
33
+ rubocop (0.82.0)
34
34
  jaro_winkler (~> 1.5.1)
35
35
  parallel (~> 1.10)
36
- parser (>= 2.5, != 2.5.1.1)
37
- psych (>= 3.1.0)
36
+ parser (>= 2.7.0.1)
38
37
  rainbow (>= 2.2.2, < 4.0)
38
+ rexml
39
39
  ruby-progressbar (~> 1.7)
40
- unicode-display_width (>= 1.4.0, < 1.6)
40
+ unicode-display_width (>= 1.4.0, < 2.0)
41
41
  ruby-progressbar (1.10.1)
42
- unicode-display_width (1.5.0)
42
+ unicode-display_width (1.7.0)
43
43
 
44
44
  PLATFORMS
45
45
  ruby
@@ -48,7 +48,7 @@ DEPENDENCIES
48
48
  bundler (~> 1.16)
49
49
  rake (~> 13.0)
50
50
  rspec (~> 3.0)
51
- rubocop (~> 0.67.2)
51
+ rubocop (~> 0.82)
52
52
  seri!
53
53
 
54
54
  BUNDLED WITH
@@ -1,58 +1,60 @@
1
- class Value
2
- def initialize(attribute, scope = nil)
3
- @attribute = attribute
4
- @scope = scope
5
- end
1
+ class Serializer
2
+ class Value
3
+ def initialize(attribute, scope = nil)
4
+ @attribute = attribute
5
+ @scope = scope
6
+ end
6
7
 
7
- def extraction_key
8
- @attribute.from || @attribute.key
9
- end
8
+ def extraction_key
9
+ @attribute.from || @attribute.key
10
+ end
10
11
 
11
- def precondition?
12
- raise NotImplementedError, 'needs a method called precondition?'
13
- end
12
+ def precondition?
13
+ raise NotImplementedError, 'needs a method called precondition?'
14
+ end
14
15
 
15
- def value
16
- raise NotImplementedError, 'needs a method called value'
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
- def precondition?
22
- @attribute.options.key?(:static_value)
23
- end
21
+ class StaticValue < Value
22
+ def precondition?
23
+ @attribute.options.key?(:static_value)
24
+ end
24
25
 
25
- def value
26
- @attribute.options.fetch(:static_value)
26
+ def value
27
+ @attribute.options.fetch(:static_value)
28
+ end
27
29
  end
28
- end
29
30
 
30
- class SerializedValue < Value
31
- def precondition?
32
- @scope.respond_to?(extraction_key)
33
- end
31
+ class SerializedValue < Value
32
+ def precondition?
33
+ @scope.respond_to?(extraction_key)
34
+ end
34
35
 
35
- def value
36
- @scope.public_send(extraction_key)
36
+ def value
37
+ @scope.public_send(extraction_key)
38
+ end
37
39
  end
38
- end
39
40
 
40
- class HashValue < Value
41
- def precondition?
42
- @scope.is_a?(Hash) && @scope.key?(extraction_key)
43
- end
41
+ class HashValue < Value
42
+ def precondition?
43
+ @scope.is_a?(Hash)
44
+ end
44
45
 
45
- def value
46
- @scope.fetch(extraction_key)
46
+ def value
47
+ @scope[extraction_key]
48
+ end
47
49
  end
48
- end
49
50
 
50
- class ObjectValue < Value
51
- def precondition?
52
- @scope.respond_to?(extraction_key)
53
- end
51
+ class ObjectValue < Value
52
+ def precondition?
53
+ @scope.respond_to?(extraction_key)
54
+ end
54
55
 
55
- def value
56
- @scope.public_send(extraction_key)
56
+ def value
57
+ @scope.public_send(extraction_key)
58
+ end
57
59
  end
58
60
  end
@@ -1,59 +1,61 @@
1
- class ValueFetcher
2
- class SerializerError < StandardError; end
3
-
4
- ARRAYS = %w[
5
- Array
6
- ActiveRecord_AssociationRelation
7
- ActiveRecord_Associations_CollectionProxy
8
- ].freeze
9
-
10
- def self.fetch(attribute, object, serializer)
11
- new(attribute, object, serializer).fetch
12
- end
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
- private_class_method :new
15
+ private_class_method :new
15
16
 
16
- def initialize(attribute, object, serializer)
17
- @attribute = attribute
18
- @values = [
19
- StaticValue.new(attribute),
20
- SerializedValue.new(attribute, serializer),
21
- HashValue.new(attribute, object),
22
- ObjectValue.new(attribute, object)
23
- ]
24
- end
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
- def fetch
27
- serializer = @attribute.serializer
27
+ def fetch
28
+ serializer = @attribute.serializer
28
29
 
29
- return value unless serializer
30
+ return value unless serializer
30
31
 
31
- if array?
32
- value.map { |item| serializer.new(item).to_h }
33
- else
34
- serializer.new(value).to_h
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
- # Fetches a value from an attribute by checking if there's a ..
39
- # .. static value set, or a ..
40
- # .. method defined in the serializer, or a ..
41
- # .. method/attribute defined in the object or ..
42
- # .. it raises an error
43
- def value
44
- @value ||= begin
45
- extracted_value = @values.detect(&:precondition?)
46
-
47
- if extracted_value.nil?
48
- raise SerializerError,
49
- "unknown attribute '#{@values[0].extraction_key}'"
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
- def array?
57
- ARRAYS.any? { |match| value.class.to_s.end_with?(match) }
57
+ def array?
58
+ ARRAYS.any? { |match| value.class.to_s.end_with?(match) }
59
+ end
58
60
  end
59
61
  end
@@ -1,3 +1,3 @@
1
1
  class Serializer
2
- VERSION = '1.1.9'.freeze
2
+ VERSION = '1.1.10'.freeze
3
3
  end
data/seri.gemspec CHANGED
@@ -29,5 +29,5 @@ Gem::Specification.new do |spec|
29
29
  spec.add_development_dependency 'bundler', '~> 1.16'
30
30
  spec.add_development_dependency 'rake', '~> 13.0'
31
31
  spec.add_development_dependency 'rspec', '~> 3.0'
32
- spec.add_development_dependency 'rubocop', '~> 0.67.2'
32
+ spec.add_development_dependency 'rubocop', '~> 0.82'
33
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.9
4
+ version: 1.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - grdw
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-30 00:00:00.000000000 Z
11
+ date: 2020-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 0.67.2
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.67.2
82
+ version: '0.82'
83
83
  description: A basic serializer
84
84
  email:
85
85
  - gerard@wetransfer.com