cinnamon_serial 2.1.1 → 2.1.2

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: 85e032792b5bfaa51e52499f47b3c43c8367342330a43e4d3995b0c6eeb3437e
4
- data.tar.gz: 7795256430a84d39483ceb14ea8d1c9c35eee2d20d67912076762080d3373ca7
3
+ metadata.gz: d35225e3e4f4abb62cd06761e5c234f6f3cbe2a05ade35e82ae94540c9217e65
4
+ data.tar.gz: 5c7ec11ad1c3fa6fe2ddb11a8b884025d03ba27290b2f0f77367b3d649b36b4f
5
5
  SHA512:
6
- metadata.gz: f847c7f35e95f58b59348c337700ed0a05fa231f5586a384e2613583d8ad0b2ba090b64f74a9dadf76b1f60b3cfa582e2a3403f9ce8956604acc8238d829f14b
7
- data.tar.gz: 001d1ab8ad80bc2eaf7f64bc8702472f8cb0c6f30c2826e1454b131db52319bea44a50b8a9e41e94321a9968b3cd5bc8cef4be7352f410b69c16774a6d483981
6
+ metadata.gz: 98072ebc41f42fd7f7e6c515a4e0a5928fc28219564592e46e6f7b6404b142374b9c85f19cebd0d356dbe1ca2a1536dab9984d0bda4d58ffbba32bf9f59203f3
7
+ data.tar.gz: e5af2239c945aeee36fcfc4f55061ea8df2a1e2e4d619b7624468c3ce38672130b42dfa3275581b613619e5b026d78b58fc074e140cb48a37f3c338617c349cc
@@ -21,7 +21,7 @@ Metrics/BlockLength:
21
21
  # Offense count: 1
22
22
  # Configuration parameters: CountComments.
23
23
  Metrics/ClassLength:
24
- Max: 111
24
+ Max: 112
25
25
 
26
26
  # Offense count: 2
27
27
  Metrics/CyclomaticComplexity:
@@ -1 +1 @@
1
- 2.6.0
1
+ 2.6.3
@@ -7,7 +7,7 @@ rvm:
7
7
  - 2.3.8
8
8
  - 2.4.5
9
9
  - 2.5.3
10
- - 2.6.0
10
+ - 2.6.3
11
11
  cache: bundler
12
12
  before_script:
13
13
  - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
@@ -1,3 +1,10 @@
1
+ # 2.1.2 (May 1st, 2019)
2
+
3
+ Fixes:
4
+
5
+ * The serializer "as" option now supports serializing ActiveRecord::Relations in newer versions of Rails.
6
+ * Support the two parameter version of respond_to_missing? for classes which inherit from CinnamonSerial::Base.
7
+
1
8
  # 2.1.1 (January 30th, 2019)
2
9
 
3
10
  Maintenance Release
@@ -1,13 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cinnamon_serial (2.1.1)
4
+ cinnamon_serial (2.1.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  ansi (1.5.0)
10
10
  ast (2.4.0)
11
+ byebug (11.0.1)
11
12
  coderay (1.1.2)
12
13
  diff-lcs (1.3)
13
14
  docile (1.3.1)
@@ -47,6 +48,9 @@ GEM
47
48
  pry (0.12.2)
48
49
  coderay (~> 1.1.0)
49
50
  method_source (~> 0.9.0)
51
+ pry-byebug (3.7.0)
52
+ byebug (~> 11.0)
53
+ pry (~> 0.10)
50
54
  rainbow (3.0.0)
51
55
  rb-fsevent (0.10.3)
52
56
  rb-inotify (0.10.0)
@@ -93,10 +97,12 @@ PLATFORMS
93
97
  DEPENDENCIES
94
98
  cinnamon_serial!
95
99
  guard-rspec (~> 4.7)
100
+ pry
101
+ pry-byebug (~> 3)
96
102
  rspec (~> 3.8)
97
103
  rubocop (~> 0.63.1)
98
104
  simplecov (~> 0.16.1)
99
105
  simplecov-console (~> 0.4.2)
100
106
 
101
107
  BUNDLED WITH
102
- 1.17.2
108
+ 1.17.3
data/Guardfile CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- guard :rspec, cmd: 'bundle exec rspec' do
3
+ guard :rspec, cmd: 'DISABLE_SIMPLECOV=true bundle exec rspec --format=documentation' do
4
4
  require 'guard/rspec/dsl'
5
5
  dsl = Guard::RSpec::Dsl.new(self)
6
6
 
@@ -22,6 +22,8 @@ Gem::Specification.new do |s|
22
22
  s.required_ruby_version = '>= 2.3.8'
23
23
 
24
24
  s.add_development_dependency('guard-rspec', '~>4.7')
25
+ s.add_development_dependency('pry')
26
+ s.add_development_dependency('pry-byebug', '~> 3')
25
27
  s.add_development_dependency('rspec', '~> 3.8')
26
28
  s.add_development_dependency('rubocop', '~>0.63.1')
27
29
  s.add_development_dependency('simplecov', '~>0.16.1')
@@ -40,7 +40,7 @@ module CinnamonSerial
40
40
  data
41
41
  end
42
42
 
43
- def respond_to_missing?(method_sym)
43
+ def respond_to_missing?(method_sym, include_private = false)
44
44
  data.key?(method_sym.to_s) || super
45
45
  end
46
46
 
@@ -118,12 +118,10 @@ module CinnamonSerial
118
118
  # This will prevent endless cycles / loops.
119
119
  return nil if presenter.klasses.include?(class_constant.to_s)
120
120
 
121
- # We do not want to create a hard dependency on ActiveRecord/Rails in this gem,
122
- # but we can still create a soft dependency in case it was included as a peer.
123
- value = value.to_a if value.class.name == 'ActiveRecord::Relation'
124
-
125
121
  new_klasses = presenter.klasses + Set[class_constant.to_s]
126
122
 
123
+ value = value_to_array_or_scalar(value)
124
+
127
125
  if value.is_a?(Array)
128
126
  value.map { |v| class_constant.new(v, presenter.opts, new_klasses) }
129
127
  else
@@ -131,6 +129,16 @@ module CinnamonSerial
131
129
  end
132
130
  end
133
131
 
132
+ def value_to_array_or_scalar(value)
133
+ # We do not want to create a hard dependency on ActiveRecord/Rails in this gem,
134
+ # but we can still create a soft dependency in case it was included as a peer.
135
+ if Module.const_defined?('ActiveRecord') && value.is_a?(ActiveRecord::Relation)
136
+ value.to_a
137
+ else
138
+ value
139
+ end
140
+ end
141
+
134
142
  def as_class_name
135
143
  return nil unless as
136
144
 
@@ -8,5 +8,5 @@
8
8
  #
9
9
 
10
10
  module CinnamonSerial
11
- VERSION = '2.1.1'
11
+ VERSION = '2.1.2'
12
12
  end
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2018-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
10
+ require './spec/spec_helper'
11
+ require './spec/examples'
12
+
13
+ describe CinnamonSerial::Resolver do
14
+ let(:presented_employee) do
15
+ CinnamonSerial::Base.new(
16
+ OpenStruct.new(
17
+ name: 'employee',
18
+ manager: OpenStruct.new(id: 2, name: 'manager')
19
+ )
20
+ )
21
+ end
22
+
23
+ let(:presented_manager_employees_array) do
24
+ CinnamonSerial::Base.new(
25
+ OpenStruct.new(
26
+ name: 'manager',
27
+ employees: [
28
+ OpenStruct.new(id: 1, name: 'employee 1'),
29
+ OpenStruct.new(id: 2, name: 'employee 2')
30
+ ]
31
+ )
32
+ )
33
+ end
34
+
35
+ let(:presented_manager_employees_active_record_relation) do
36
+ # Stub this out so this gem does not have to depends directly on ActiveRecord:
37
+ module ActiveRecord
38
+ class Relation
39
+ end
40
+ end
41
+
42
+ module CinnamonSerial
43
+ class ResolverSpecFakeRelation < ActiveRecord::Relation
44
+ def initialize(data)
45
+ @data = data
46
+ end
47
+
48
+ def to_a
49
+ @data
50
+ end
51
+ end
52
+ end
53
+
54
+ CinnamonSerial::Base.new(
55
+ OpenStruct.new(
56
+ name: 'manager',
57
+ employees: CinnamonSerial::ResolverSpecFakeRelation.new(
58
+ [
59
+ OpenStruct.new(id: 1, name: 'employee 1'),
60
+ OpenStruct.new(id: 2, name: 'employee 2')
61
+ ]
62
+ )
63
+ )
64
+ )
65
+ end
66
+
67
+ describe '"as" resolving' do
68
+ let(:subject) { described_class.new(as: SimpleEmployeeSerializer) }
69
+
70
+ it 'single instance resolves to an instance of the specified class' do
71
+ value = subject.resolve(presented_employee, 'manager')
72
+
73
+ expect(value).to be_a SimpleEmployeeSerializer
74
+ expect(value.data).to eq('id' => 2, 'name' => 'manager')
75
+ end
76
+
77
+ it 'wraps each element of an array in the presenter as specified' do
78
+ value = subject.resolve(presented_manager_employees_array, :employees)
79
+
80
+ expect(value).to be_a Array
81
+ expect(value.map(&:class).uniq).to eq [SimpleEmployeeSerializer]
82
+
83
+ expect(value[0].data).to eq('id' => 1, 'name' => 'employee 1')
84
+ expect(value[1].data).to eq('id' => 2, 'name' => 'employee 2')
85
+ end
86
+
87
+ it 'wraps each element of an ActiveRecord::Relation in the presenter as specified' do
88
+ value = subject.resolve(presented_manager_employees_active_record_relation, :employees)
89
+
90
+ expect(value).to be_a Array
91
+ expect(value.map(&:class).uniq).to eq [SimpleEmployeeSerializer]
92
+
93
+ expect(value[0].data).to eq('id' => 1, 'name' => 'employee 1')
94
+ expect(value[1].data).to eq('id' => 2, 'name' => 'employee 2')
95
+ end
96
+ end
97
+ end
@@ -9,10 +9,16 @@
9
9
 
10
10
  require 'date'
11
11
  require 'pry'
12
+ require 'pry-byebug'
12
13
 
13
- require 'simplecov'
14
- require 'simplecov-console'
15
- SimpleCov.formatter = SimpleCov::Formatter::Console
16
- SimpleCov.start
14
+ unless ENV['DISABLE_SIMPLECOV'] == 'true'
15
+ require 'simplecov'
16
+ require 'simplecov-console'
17
+
18
+ SimpleCov.formatter = SimpleCov::Formatter::Console
19
+ SimpleCov.start do
20
+ add_filter %r{\A/spec/}
21
+ end
22
+ end
17
23
 
18
24
  require './lib/cinnamon_serial'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cinnamon_serial
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Ruggio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-05 00:00:00.000000000 Z
11
+ date: 2019-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: guard-rspec
@@ -24,6 +24,34 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '4.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry-byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3'
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: rspec
29
57
  requirement: !ruby/object:Gem::Requirement
@@ -112,6 +140,7 @@ files:
112
140
  - lib/cinnamon_serial/version.rb
113
141
  - spec/cinnamon_serial/base_spec.rb
114
142
  - spec/cinnamon_serial/dsl_spec.rb
143
+ - spec/cinnamon_serial/resolver_spec.rb
115
144
  - spec/examples.rb
116
145
  - spec/spec_helper.rb
117
146
  homepage: https://github.com/bluemarblepayroll/cinnamon_serial
@@ -133,12 +162,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
162
  - !ruby/object:Gem::Version
134
163
  version: '0'
135
164
  requirements: []
136
- rubygems_version: 3.0.1
165
+ rubygems_version: 3.0.3
137
166
  signing_key:
138
167
  specification_version: 4
139
168
  summary: Domain-specific language for serialization specification.
140
169
  test_files:
141
170
  - spec/cinnamon_serial/base_spec.rb
142
171
  - spec/cinnamon_serial/dsl_spec.rb
172
+ - spec/cinnamon_serial/resolver_spec.rb
143
173
  - spec/examples.rb
144
174
  - spec/spec_helper.rb