cinnamon_serial 2.0.0 → 2.1.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
  SHA1:
3
- metadata.gz: cc99c26bd3ac755f7bc43b101f399f62ee21162f
4
- data.tar.gz: 8cbf16165c228458d3acf6793d648ceb361a658b
3
+ metadata.gz: b4b1f1e130c735d90a575a5526bb4ff4b8d1b8e7
4
+ data.tar.gz: b021efb4fd143f8deb4ed52392b2227c0873e643
5
5
  SHA512:
6
- metadata.gz: 292175294b5a88a7d56d4f30ebf3854a69c4662c32f5d78d2acf5f4e0e534f2361a486f54dff4ca16258066e83b549805e25504175ece222e4dc9bfae92a9296
7
- data.tar.gz: 7788ac0567c1cfbfb097f103785ae7b492ea728ba170c819fa81877fd56c0d27d9eab1bf5418534a758a40084b35c0b968afe68dde7cad59d3b5835cd4b32168
6
+ metadata.gz: 48a8172d0abc8757bd2ffaa53e3aed4b02b9f982edf0ec9d7c6be8a4f2dfde9d83c46ccb900a31d55efb7c9938385b298192bff0dfbbd7a8175e673a26b9569e
7
+ data.tar.gz: a6c314e747ad984603bcbe3975e0254f481f12fdd7aed6f5aff5b9c34852027d09471d5029bba6691392a187ed951fbb6468d47fef31d2ddad8c463eaa037744
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cinnamon_serial (2.0.0)
4
+ cinnamon_serial (2.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -48,8 +48,8 @@ PLATFORMS
48
48
 
49
49
  DEPENDENCIES
50
50
  cinnamon_serial!
51
- pry
52
- rspec
51
+ pry (~> 0.11)
52
+ rspec (~> 3.8)
53
53
  rubocop (~> 0.59.2)
54
54
 
55
55
  BUNDLED WITH
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
21
21
 
22
22
  s.required_ruby_version = '>= 2.3.1'
23
23
 
24
- s.add_development_dependency('pry')
25
- s.add_development_dependency('rspec')
24
+ s.add_development_dependency('pry', '~> 0.11')
25
+ s.add_development_dependency('rspec', '~> 3.8')
26
26
  s.add_development_dependency('rubocop', '~> 0.59.2')
27
27
  end
@@ -24,7 +24,7 @@ module CinnamonSerial
24
24
  :klasses
25
25
 
26
26
  def initialize(obj, opts = {}, klasses = Set.new)
27
- @obj = obj
27
+ @obj = normalize_object(obj)
28
28
  @opts = opts || {}
29
29
  @klasses = klasses
30
30
 
@@ -91,5 +91,12 @@ module CinnamonSerial
91
91
 
92
92
  nil
93
93
  end
94
+
95
+ # We would like to support hashes, but would rather stay object-based. So what we
96
+ # can do is just simply convert hashes to OpenStruct objects so they behave more like
97
+ # objects.
98
+ def normalize_object(obj)
99
+ obj.is_a?(Hash) ? OpenStruct.new(obj) : obj
100
+ end
94
101
  end
95
102
  end
@@ -8,6 +8,7 @@
8
8
  #
9
9
 
10
10
  require 'set'
11
+ require 'ostruct'
11
12
 
12
13
  require_relative 'formatting'
13
14
  require_relative 'resolver'
@@ -8,5 +8,5 @@
8
8
  #
9
9
 
10
10
  module CinnamonSerial
11
- VERSION = '2.0.0'
11
+ VERSION = '2.1.0'
12
12
  end
data/spec/base_spec.rb CHANGED
@@ -116,4 +116,16 @@ describe CinnamonSerial::Base do
116
116
  it 'should not create cycles when flattening out presenters' do
117
117
  expect(data['manager'].employees).to be nil
118
118
  end
119
+
120
+ it 'should treat hashes like objects' do
121
+ employee = {
122
+ id: 1,
123
+ name: 'Mittens the cat'
124
+ }
125
+
126
+ serializer = SimpleEmployeeSerializer.new(employee)
127
+
128
+ expect(serializer.data['id']).to eq(employee[:id])
129
+ expect(serializer.data['name']).to eq(employee[:name])
130
+ end
119
131
  end
data/spec/examples.rb CHANGED
@@ -167,3 +167,7 @@ class EmployeeSerializer < EmployeeListSerializer
167
167
  set_owner(obj.id == 1)
168
168
  end
169
169
  end
170
+
171
+ class SimpleEmployeeSerializer < CinnamonSerial::Base
172
+ serialize :id, :name
173
+ end
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cinnamon_serial
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Ruggio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-05 00:00:00.000000000 Z
11
+ date: 2018-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '0.11'
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: '0'
26
+ version: '0.11'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '3.8'
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: '0'
40
+ version: '3.8'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rubocop
43
43
  requirement: !ruby/object:Gem::Requirement