userializer 0.1.6 → 0.2.0

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: 2ff7b3083a1f53deccff3139fc8625c9ac17a313f07fd2f0b98ca912a8ef6d46
4
- data.tar.gz: cf90d14d354b5dbcbd6bb1e9021860583b57adf2ff10bc599a8aa15e3c33531d
3
+ metadata.gz: 6ff350c75deb5f250911135a9ea0cd76b0d0edc451186f5a870895818476862d
4
+ data.tar.gz: 6faf6e27adbc666f620235d15ec4d8ceb62b54ef39416c6693c81d0f59cf84ff
5
5
  SHA512:
6
- metadata.gz: 140ffbbe09cd46455c97fcc5e9d36b6adb9f7cca28b21b0c4231f316d887125fd131b0e8046e49c3bea1c1a6719ba3e99c8bb143d5e2d127a5e7ef6843e659c2
7
- data.tar.gz: fc5b3c983c81bedd8807c38a41a0bf323ad5597eaacbfa4c64a618744c092bf9e252f6129dc88fb0c5c2c5f1715bee6271b6e8cbf21f86eb0d8889ca53624aed
6
+ metadata.gz: 55bb0fae587d95804183d68495be2e19da3fe1d3f26acb5604fd0a05a715357a14ac6027af276d42c03f59e12067f54f35b85ee09452c2455987b9bcf4be3b8a
7
+ data.tar.gz: d0219c7986d8bb650d247f1d6e43612f84afc6ee58f7919da08767b760c8a720e1a9d5aef343a03a43c89a8981dfdc936507e2036dfefe81c5fbb72ea3806c1c
data/.circleci/config.yml CHANGED
@@ -2,7 +2,7 @@ version: 2
2
2
  jobs:
3
3
  run_tests:
4
4
  docker:
5
- - image: circleci/ruby:2.4.1
5
+ - image: circleci/ruby:2.7
6
6
 
7
7
  working_directory: ~/userializer
8
8
 
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+ Gemfile.lock
@@ -19,14 +19,18 @@ module USerializer
19
19
  ActiveSupport::Inflector.underscore(obj_class.name).split('/').last
20
20
  ).to_sym if obj_class
21
21
 
22
- @serializer = opts[:each_serializer] || USerializer.infered_serializer_class(
23
- obj_class
24
- )
22
+ serializer = opts[:each_serializer]
23
+
24
+ @serializer = if serializer&.is_a?(Proc)
25
+ serializer
26
+ elsif serializer
27
+ proc { serializer }
28
+ end
25
29
  end
26
30
 
27
31
  def merge_root(res, opts)
28
32
  @objs.each do |obj|
29
- @serializer.new(obj, @opts).merge_root(res, @root_key, false, opts)
33
+ serializer(obj, opts).merge_root(res, @root_key, false, opts)
30
34
  end
31
35
  end
32
36
 
@@ -46,5 +50,14 @@ module USerializer
46
50
  end
47
51
 
48
52
  def scope; @opts[:scope]; end
53
+
54
+ private
55
+
56
+ def serializer(obj, opts)
57
+ return @serializer.call(obj, opts).new(obj, @opts) if @serializer
58
+ return obj.serialize if obj.respond_to?(:serialize)
59
+
60
+ USerializer.infered_serializer_class(obj.class).new(obj, @opts)
61
+ end
49
62
  end
50
63
  end
@@ -6,7 +6,14 @@ module USerializer
6
6
  @id_key = "#{key}_id".to_sym
7
7
  @root_key = opts[:root]&.to_sym
8
8
 
9
- @serializer = opts[:serializer]
9
+ serializer = opts[:serializer]
10
+
11
+ @serializer = if serializer&.is_a?(Proc)
12
+ @serializer = serializer
13
+ elsif serializer
14
+ proc { serializer }
15
+ end
16
+
10
17
  @embed_key = opts[:embed_key] || :id
11
18
  @conditional_block = opts[:if] || proc { true }
12
19
  end
@@ -25,13 +32,13 @@ module USerializer
25
32
 
26
33
  return if obj.nil? || !@conditional_block.call(ser.object, opts)
27
34
 
28
- serializer(obj).merge_root(res, root_key(obj), false, opts)
35
+ serializer(obj, opts).merge_root(res, root_key(obj), false, opts)
29
36
  end
30
37
 
31
38
  private
32
39
 
33
- def serializer(obj)
34
- return @serializer.new(obj, @opts) if @serializer
40
+ def serializer(obj, opts)
41
+ return @serializer.call(obj, opts).new(obj, @opts) if @serializer
35
42
  return obj.serialize if obj.respond_to?(:serialize)
36
43
 
37
44
  USerializer.infered_serializer_class(obj.class).new(obj, @opts)
@@ -1,3 +1,3 @@
1
1
  module USerializer
2
- VERSION = "0.1.6"
2
+ VERSION = "0.2.0"
3
3
  end
data/userializer.gemspec CHANGED
@@ -20,8 +20,8 @@ Gem::Specification.new do |spec|
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
21
  spec.require_paths = ["lib"]
22
22
 
23
- spec.add_development_dependency "bundler", "~> 1.16"
24
- spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "bundler", "~> 2.0"
24
+ spec.add_development_dependency "rake", "~> 13.0"
25
25
  spec.add_development_dependency "rspec", "~> 3.0"
26
26
  spec.add_dependency "oj"
27
27
  spec.add_dependency "activesupport"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: userializer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexis Montagne
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-07-31 00:00:00.000000000 Z
11
+ date: 2021-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.16'
19
+ version: '2.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.16'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '13.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '13.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -92,7 +92,6 @@ files:
92
92
  - ".rspec"
93
93
  - ".travis.yml"
94
94
  - Gemfile
95
- - Gemfile.lock
96
95
  - README.md
97
96
  - Rakefile
98
97
  - bin/console
@@ -108,7 +107,7 @@ files:
108
107
  homepage: https://github.com/upfluence/userializer
109
108
  licenses: []
110
109
  metadata: {}
111
- post_install_message:
110
+ post_install_message:
112
111
  rdoc_options: []
113
112
  require_paths:
114
113
  - lib
@@ -123,9 +122,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
122
  - !ruby/object:Gem::Version
124
123
  version: '0'
125
124
  requirements: []
126
- rubyforge_project:
127
- rubygems_version: 3.0.0.beta3
128
- signing_key:
125
+ rubygems_version: 3.0.3
126
+ signing_key:
129
127
  specification_version: 4
130
128
  summary: Write a short summary, because RubyGems requires one.
131
129
  test_files: []
data/Gemfile.lock DELETED
@@ -1,50 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- userializer (0.1.6)
5
- activesupport
6
- oj
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- activesupport (5.2.3)
12
- concurrent-ruby (~> 1.0, >= 1.0.2)
13
- i18n (>= 0.7, < 2)
14
- minitest (~> 5.1)
15
- tzinfo (~> 1.1)
16
- concurrent-ruby (1.1.5)
17
- diff-lcs (1.3)
18
- i18n (1.6.0)
19
- concurrent-ruby (~> 1.0)
20
- minitest (5.11.3)
21
- oj (3.7.12)
22
- rake (10.4.2)
23
- rspec (3.8.0)
24
- rspec-core (~> 3.8.0)
25
- rspec-expectations (~> 3.8.0)
26
- rspec-mocks (~> 3.8.0)
27
- rspec-core (3.8.0)
28
- rspec-support (~> 3.8.0)
29
- rspec-expectations (3.8.3)
30
- diff-lcs (>= 1.2.0, < 2.0)
31
- rspec-support (~> 3.8.0)
32
- rspec-mocks (3.8.0)
33
- diff-lcs (>= 1.2.0, < 2.0)
34
- rspec-support (~> 3.8.0)
35
- rspec-support (3.8.0)
36
- thread_safe (0.3.6)
37
- tzinfo (1.2.5)
38
- thread_safe (~> 0.1)
39
-
40
- PLATFORMS
41
- ruby
42
-
43
- DEPENDENCIES
44
- bundler (~> 1.16)
45
- rake (~> 10.0)
46
- rspec (~> 3.0)
47
- userializer!
48
-
49
- BUNDLED WITH
50
- 1.16.2