seri 2.0.0 → 2.0.1

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: a280328ee692f5395dd9ff0fe6bde3c684f6131131b69ed059a9ff58403a79ec
4
- data.tar.gz: 4b817c4d1aa442835a5227ab0f88758644378322922884317e087c79f594f88f
3
+ metadata.gz: b195c3ae8c5ec78fa54317184b782970fe1d22d1b19f446d6297b5959a90b06b
4
+ data.tar.gz: df3042fb5c2f291fec12b63ece1036a5e75549503ea6896ac8ac167da0cb2e91
5
5
  SHA512:
6
- metadata.gz: 05fae53fffb74d5fbdf639a855703dba418fb2ce3d82ec81fde010cce67055c0be015f50953c54d7cbe260eb0f148216513ecca21e6c5d3de1b11cf03c954d77
7
- data.tar.gz: 2828f68b71f05e813cd213a96e12c68078a5bdb373a74e8ea9021286d4a0745730ca45ee96573573454f887f191e65f7cc555e146c164fea5dfb2c939e33e2ef
6
+ metadata.gz: 030be24706b3a319c34cf167e4a9f833314235e61fcdb45f41974db8819d4de5d31cd3215d4c3bc5c0bca718bbeb81cf3ce666b0e068347c9ce89db3ed1e07bf
7
+ data.tar.gz: 3d563d73ab5fc270b27ef032a0b2ab8bf2e2fe5069088f541236e04c0150044bb039214dcc0418e81171de19fc43551ac5e7cbae5a788edcd34f7ec76a1edd0a
@@ -1,3 +1,5 @@
1
+ AllCops:
2
+ NewCops: disable
1
3
  Metrics/BlockLength:
2
4
  Exclude:
3
5
  - 'spec/**/*.rb'
@@ -8,31 +10,5 @@ Style/FrozenStringLiteralComment:
8
10
  # This is causing breaking changes:
9
11
  Style/ExpandPathArguments:
10
12
  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:
13
+ Gemspec/RequiredRubyVersion:
38
14
  Enabled: false
@@ -8,14 +8,19 @@ GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
10
  ast (2.4.1)
11
+ coderay (1.1.3)
11
12
  diff-lcs (1.3)
12
- oj (3.10.8)
13
+ method_source (1.0.0)
14
+ oj (3.10.14)
13
15
  parallel (1.19.2)
14
- parser (2.7.1.4)
16
+ parser (2.7.2.0)
15
17
  ast (~> 2.4.1)
18
+ pry (0.13.1)
19
+ coderay (~> 1.1)
20
+ method_source (~> 1.0)
16
21
  rainbow (3.0.0)
17
22
  rake (13.0.1)
18
- regexp_parser (1.7.1)
23
+ regexp_parser (1.8.2)
19
24
  rexml (3.2.4)
20
25
  rspec (3.9.0)
21
26
  rspec-core (~> 3.9.0)
@@ -30,17 +35,17 @@ GEM
30
35
  diff-lcs (>= 1.2.0, < 2.0)
31
36
  rspec-support (~> 3.9.0)
32
37
  rspec-support (3.9.2)
33
- rubocop (0.88.0)
38
+ rubocop (0.93.1)
34
39
  parallel (~> 1.10)
35
- parser (>= 2.7.1.1)
40
+ parser (>= 2.7.1.5)
36
41
  rainbow (>= 2.2.2, < 4.0)
37
- regexp_parser (>= 1.7)
42
+ regexp_parser (>= 1.8)
38
43
  rexml
39
- rubocop-ast (>= 0.1.0, < 1.0)
44
+ rubocop-ast (>= 0.6.0)
40
45
  ruby-progressbar (~> 1.7)
41
46
  unicode-display_width (>= 1.4.0, < 2.0)
42
- rubocop-ast (0.1.0)
43
- parser (>= 2.7.0.1)
47
+ rubocop-ast (0.8.0)
48
+ parser (>= 2.7.1.5)
44
49
  ruby-progressbar (1.10.1)
45
50
  unicode-display_width (1.7.0)
46
51
 
@@ -49,6 +54,7 @@ PLATFORMS
49
54
 
50
55
  DEPENDENCIES
51
56
  bundler (~> 1.16)
57
+ pry (~> 0.13)
52
58
  rake (~> 13.0)
53
59
  rspec (~> 3.0)
54
60
  rubocop (~> 0.82)
data/README.md CHANGED
@@ -33,13 +33,15 @@ Or install it yourself as:
33
33
  A serializer can be used as such:
34
34
 
35
35
  ```ruby
36
+ require 'seri'
37
+
36
38
  # example class:
37
39
  class Car
38
40
  attr_accessor :mileage
39
41
  end
40
42
 
41
43
  # example serializer:
42
- class CarSerializer < Serializer
44
+ class CarSerializer < Seri::Serializer
43
45
  attribute :mileage
44
46
  attribute :brand
45
47
  attribute :mileage_alias, from: :mileage
@@ -94,14 +96,14 @@ Result from `#to_json`:
94
96
  }
95
97
  ```
96
98
 
97
- In turn there's also a `GroupSerializer` available which can take a group of
99
+ In turn there's also a `Seri::GroupSerializer` available which can take a group of
98
100
  cars and turn them into a serialized Array. If we extend the example from
99
101
  earlier we can do:
100
102
 
101
103
  ```ruby
102
104
  # example:
103
105
  cars = [car, car]
104
- group_serializer = GroupSerializer.new(cars, serializer: CarSerializer)
106
+ group_serializer = Seri::GroupSerializer.new(cars, serializer: CarSerializer)
105
107
 
106
108
  group_serializer.to_json
107
109
  ```
@@ -148,11 +150,11 @@ class B
148
150
  end
149
151
  end
150
152
 
151
- class ASerializer < Serializer
153
+ class ASerializer < Seri::Serializer
152
154
  attribute :some_amazing_attribute
153
155
  end
154
156
 
155
- class BSerializer < Serializer
157
+ class BSerializer < Seri::Serializer
156
158
  attribute :lots_of_a, from: :aaa, serializer: ASerializer
157
159
  end
158
160
  ```
@@ -3,12 +3,6 @@ module Seri
3
3
  class ValueFetcher
4
4
  class SerializerError < StandardError; end
5
5
 
6
- ARRAYS = %w[
7
- Array
8
- ActiveRecord_AssociationRelation
9
- ActiveRecord_Associations_CollectionProxy
10
- ].freeze
11
-
12
6
  def self.fetch(attribute, object, serializer)
13
7
  new(attribute, object, serializer).fetch
14
8
  end
@@ -30,7 +24,7 @@ module Seri
30
24
 
31
25
  return value unless serializer
32
26
 
33
- if array?
27
+ if value.is_a?(Enumerable) && !value.is_a?(Hash)
34
28
  value.map { |item| serializer.new(item).to_h }
35
29
  else
36
30
  serializer.new(value).to_h
@@ -54,10 +48,6 @@ module Seri
54
48
  extracted_value.value
55
49
  end
56
50
  end
57
-
58
- def array?
59
- ARRAYS.any? { |match| value.class.to_s.end_with?(match) }
60
- end
61
51
  end
62
52
  end
63
53
  end
@@ -1,5 +1,5 @@
1
1
  module Seri
2
2
  class Serializer
3
- VERSION = '2.0.0'.freeze
3
+ VERSION = '2.0.1'.freeze
4
4
  end
5
5
  end
@@ -27,6 +27,7 @@ Gem::Specification.new do |spec|
27
27
  spec.add_dependency 'oj', '~> 3.7'
28
28
 
29
29
  spec.add_development_dependency 'bundler', '~> 1.16'
30
+ spec.add_development_dependency 'pry', '~> 0.13'
30
31
  spec.add_development_dependency 'rake', '~> 13.0'
31
32
  spec.add_development_dependency 'rspec', '~> 3.0'
32
33
  spec.add_development_dependency 'rubocop', '~> 0.82'
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: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - grdw
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-04 00:00:00.000000000 Z
11
+ date: 2020-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.13'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.13'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rake
43
57
  requirement: !ruby/object:Gem::Requirement