fast_serializer_ruby 0.4.1 → 0.6.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.travis.yml +6 -1
- data/CODE_OF_CONDUCT.md +1 -1
- data/Gemfile +18 -1
- data/Gemfile.lock +55 -41
- data/LICENSE.txt +1 -1
- data/README.md +45 -33
- data/fast_serializer.gemspec +6 -13
- data/lib/fast_serializer.rb +2 -1
- data/lib/fast_serializer/configuration.rb +14 -2
- data/lib/fast_serializer/json_model/array.rb +6 -2
- data/lib/fast_serializer/json_model/attribute.rb +105 -20
- data/lib/fast_serializer/json_model/has_many_relationship.rb +5 -3
- data/lib/fast_serializer/json_model/has_one_relationship.rb +4 -1
- data/lib/fast_serializer/json_model/node.rb +10 -2
- data/lib/fast_serializer/json_model/object.rb +16 -6
- data/lib/fast_serializer/json_model/relationship.rb +20 -3
- data/lib/fast_serializer/schema.rb +93 -112
- data/lib/fast_serializer/schema/mixin.rb +70 -0
- data/lib/fast_serializer/utils.rb +17 -0
- data/lib/fast_serializer/version.rb +1 -1
- metadata +11 -134
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac8a1a9a688c7c866eed16ff360db7ce7e898449d01638f0a2e5ad8e25c10ec3
|
4
|
+
data.tar.gz: 537b93afce1348b456bd52e0cfa6e5bad52e68067ff890930c1c7282003d0a2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df1582559bdd4cc6e17d976c1aaf0916d37485f60a792991038224dea46493fdc4815406e64da801b4c00ea34bcde21fbdafd196697e1f3a9ba5e2ff5cc41f75
|
7
|
+
data.tar.gz: 238535794943fd0361027c85d99a5e03758e91db2b363bd9bebfc5fa5eec5197e2f8ed0387871136ec5936cdbbc28d1a0e228c280359a9b191aded5478963670
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -7,6 +7,7 @@ rvm:
|
|
7
7
|
- 2.4
|
8
8
|
- 2.5
|
9
9
|
- 2.6
|
10
|
+
- 2.7
|
10
11
|
- jruby-9.2.0.0
|
11
12
|
- ruby-head
|
12
13
|
- jruby-head
|
@@ -17,6 +18,10 @@ matrix:
|
|
17
18
|
- rvm: ruby-head
|
18
19
|
- rvm: jruby-head
|
19
20
|
|
21
|
+
before_install:
|
22
|
+
- yes | gem update --system --force
|
23
|
+
- gem install bundler
|
24
|
+
|
20
25
|
before_script:
|
21
26
|
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
22
27
|
- chmod +x ./cc-test-reporter
|
@@ -31,5 +36,5 @@ cache: bundler
|
|
31
36
|
|
32
37
|
env:
|
33
38
|
global:
|
34
|
-
CC_TEST_REPORTER_ID=
|
39
|
+
CC_TEST_REPORTER_ID=99325a42b78ef51a9d51574d20dbcd6acdfe75c8568f1433f73b61f17149e05d
|
35
40
|
COVERAGE=1
|
data/CODE_OF_CONDUCT.md
CHANGED
@@ -55,7 +55,7 @@ further defined and clarified by project maintainers.
|
|
55
55
|
## Enforcement
|
56
56
|
|
57
57
|
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
-
reported by contacting the project team at
|
58
|
+
reported by contacting the project team at estepnv@icloud.com. All
|
59
59
|
complaints will be reviewed and investigated and will result in a response that
|
60
60
|
is deemed necessary and appropriate to the circumstances. The project team is
|
61
61
|
obligated to maintain confidentiality with regard to the reporter of an incident.
|
data/Gemfile
CHANGED
@@ -4,5 +4,22 @@ source 'https://rubygems.org'
|
|
4
4
|
|
5
5
|
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
6
6
|
|
7
|
-
# Specify your gem's dependencies in fast_serializer.gemspec
|
8
7
|
gemspec
|
8
|
+
|
9
|
+
group :development, :test do
|
10
|
+
gem 'rake'
|
11
|
+
gem 'pry'
|
12
|
+
end
|
13
|
+
|
14
|
+
group :test do
|
15
|
+
gem 'active_model_serializers', '~> 0.10.0'
|
16
|
+
gem 'factory_bot'
|
17
|
+
gem 'faker'
|
18
|
+
gem 'activesupport', '< 6'
|
19
|
+
gem 'allocation_stats'
|
20
|
+
gem 'simplecov', '~> 0.17.1'
|
21
|
+
gem 'benchmark-memory', '~> 0.1'
|
22
|
+
gem 'rspec', '~> 3.0'
|
23
|
+
gem 'rspec-benchmark'
|
24
|
+
gem 'pry-byebug'
|
25
|
+
end
|
data/Gemfile.lock
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
fast_serializer_ruby (0.4
|
4
|
+
fast_serializer_ruby (0.6.4)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
actionpack (5.2.
|
10
|
-
actionview (= 5.2.
|
11
|
-
activesupport (= 5.2.
|
12
|
-
rack (~> 2.0)
|
9
|
+
actionpack (5.2.4.1)
|
10
|
+
actionview (= 5.2.4.1)
|
11
|
+
activesupport (= 5.2.4.1)
|
12
|
+
rack (~> 2.0, >= 2.0.8)
|
13
13
|
rack-test (>= 0.6.3)
|
14
14
|
rails-dom-testing (~> 2.0)
|
15
15
|
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
16
|
-
actionview (5.2.
|
17
|
-
activesupport (= 5.2.
|
16
|
+
actionview (5.2.4.1)
|
17
|
+
activesupport (= 5.2.4.1)
|
18
18
|
builder (~> 3.1)
|
19
19
|
erubi (~> 1.4)
|
20
20
|
rails-dom-testing (~> 2.0)
|
@@ -24,44 +24,49 @@ GEM
|
|
24
24
|
activemodel (>= 4.1, < 6.1)
|
25
25
|
case_transform (>= 0.2)
|
26
26
|
jsonapi-renderer (>= 0.1.1.beta1, < 0.3)
|
27
|
-
activemodel (5.2.
|
28
|
-
activesupport (= 5.2.
|
29
|
-
activesupport (5.2.
|
27
|
+
activemodel (5.2.4.1)
|
28
|
+
activesupport (= 5.2.4.1)
|
29
|
+
activesupport (5.2.4.1)
|
30
30
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
31
31
|
i18n (>= 0.7, < 2)
|
32
32
|
minitest (~> 5.1)
|
33
33
|
tzinfo (~> 1.1)
|
34
|
-
|
35
|
-
benchmark-
|
36
|
-
benchmark-
|
37
|
-
|
34
|
+
allocation_stats (0.1.5)
|
35
|
+
benchmark-malloc (0.2.0)
|
36
|
+
benchmark-memory (0.1.2)
|
37
|
+
memory_profiler (~> 0.9)
|
38
|
+
benchmark-perf (0.6.0)
|
39
|
+
benchmark-trend (0.4.0)
|
40
|
+
builder (3.2.4)
|
41
|
+
byebug (11.1.3)
|
38
42
|
case_transform (0.2)
|
39
43
|
activesupport
|
40
44
|
coderay (1.1.2)
|
41
|
-
concurrent-ruby (1.1.
|
42
|
-
crass (1.0.
|
45
|
+
concurrent-ruby (1.1.6)
|
46
|
+
crass (1.0.6)
|
43
47
|
diff-lcs (1.3)
|
44
48
|
docile (1.3.2)
|
45
49
|
erubi (1.9.0)
|
46
50
|
factory_bot (5.1.1)
|
47
51
|
activesupport (>= 4.2.0)
|
48
|
-
faker (2.
|
49
|
-
i18n (>= 1.6, <
|
50
|
-
ffi (1.
|
51
|
-
i18n (1.
|
52
|
+
faker (2.10.2)
|
53
|
+
i18n (>= 1.6, < 2)
|
54
|
+
ffi (1.12.2-java)
|
55
|
+
i18n (1.8.2)
|
52
56
|
concurrent-ruby (~> 1.0)
|
53
|
-
json (2.
|
54
|
-
json (2.
|
57
|
+
json (2.3.0)
|
58
|
+
json (2.3.0-java)
|
55
59
|
jsonapi-renderer (0.2.2)
|
56
|
-
loofah (2.
|
60
|
+
loofah (2.4.0)
|
57
61
|
crass (~> 1.0.2)
|
58
62
|
nokogiri (>= 1.5.9)
|
63
|
+
memory_profiler (0.9.14)
|
59
64
|
method_source (0.9.2)
|
60
65
|
mini_portile2 (2.4.0)
|
61
|
-
minitest (5.
|
62
|
-
nokogiri (1.10.
|
66
|
+
minitest (5.14.0)
|
67
|
+
nokogiri (1.10.9)
|
63
68
|
mini_portile2 (~> 2.4.0)
|
64
|
-
nokogiri (1.10.
|
69
|
+
nokogiri (1.10.9-java)
|
65
70
|
pry (0.12.2)
|
66
71
|
coderay (~> 1.1.0)
|
67
72
|
method_source (~> 0.9.0)
|
@@ -69,7 +74,10 @@ GEM
|
|
69
74
|
coderay (~> 1.1.0)
|
70
75
|
method_source (~> 0.9.0)
|
71
76
|
spoon (~> 0.0)
|
72
|
-
|
77
|
+
pry-byebug (3.8.0)
|
78
|
+
byebug (~> 11.0)
|
79
|
+
pry (~> 0.10)
|
80
|
+
rack (2.2.2)
|
73
81
|
rack-test (1.1.0)
|
74
82
|
rack (>= 1.0, < 3)
|
75
83
|
rails-dom-testing (2.0.3)
|
@@ -77,25 +85,25 @@ GEM
|
|
77
85
|
nokogiri (>= 1.6)
|
78
86
|
rails-html-sanitizer (1.3.0)
|
79
87
|
loofah (~> 2.3)
|
80
|
-
rake (
|
88
|
+
rake (13.0.1)
|
81
89
|
rspec (3.9.0)
|
82
90
|
rspec-core (~> 3.9.0)
|
83
91
|
rspec-expectations (~> 3.9.0)
|
84
92
|
rspec-mocks (~> 3.9.0)
|
85
|
-
rspec-benchmark (0.
|
86
|
-
benchmark-malloc (~> 0.
|
87
|
-
benchmark-perf (~> 0.
|
88
|
-
benchmark-trend (~> 0.
|
89
|
-
rspec (>= 3.0
|
90
|
-
rspec-core (3.9.
|
91
|
-
rspec-support (~> 3.9.
|
92
|
-
rspec-expectations (3.9.
|
93
|
+
rspec-benchmark (0.6.0)
|
94
|
+
benchmark-malloc (~> 0.2)
|
95
|
+
benchmark-perf (~> 0.6)
|
96
|
+
benchmark-trend (~> 0.4)
|
97
|
+
rspec (>= 3.0)
|
98
|
+
rspec-core (3.9.1)
|
99
|
+
rspec-support (~> 3.9.1)
|
100
|
+
rspec-expectations (3.9.1)
|
93
101
|
diff-lcs (>= 1.2.0, < 2.0)
|
94
102
|
rspec-support (~> 3.9.0)
|
95
|
-
rspec-mocks (3.9.
|
103
|
+
rspec-mocks (3.9.1)
|
96
104
|
diff-lcs (>= 1.2.0, < 2.0)
|
97
105
|
rspec-support (~> 3.9.0)
|
98
|
-
rspec-support (3.9.
|
106
|
+
rspec-support (3.9.2)
|
99
107
|
simplecov (0.17.1)
|
100
108
|
docile (~> 1.1)
|
101
109
|
json (>= 1.8, < 3)
|
@@ -105,7 +113,7 @@ GEM
|
|
105
113
|
ffi
|
106
114
|
thread_safe (0.3.6)
|
107
115
|
thread_safe (0.3.6-java)
|
108
|
-
tzinfo (1.2.
|
116
|
+
tzinfo (1.2.6)
|
109
117
|
thread_safe (~> 0.1)
|
110
118
|
|
111
119
|
PLATFORMS
|
@@ -115,11 +123,17 @@ PLATFORMS
|
|
115
123
|
DEPENDENCIES
|
116
124
|
active_model_serializers (~> 0.10.0)
|
117
125
|
activesupport (< 6)
|
126
|
+
allocation_stats
|
127
|
+
benchmark-memory (~> 0.1)
|
118
128
|
factory_bot
|
119
129
|
faker
|
120
130
|
fast_serializer_ruby!
|
121
131
|
pry
|
122
|
-
|
132
|
+
pry-byebug
|
133
|
+
rake
|
123
134
|
rspec (~> 3.0)
|
124
135
|
rspec-benchmark
|
125
|
-
simplecov
|
136
|
+
simplecov (~> 0.17.1)
|
137
|
+
|
138
|
+
BUNDLED WITH
|
139
|
+
2.1.4
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,16 +1,25 @@
|
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/fast_serializer_ruby.svg)](https://badge.fury.io/rb/fast_serializer_ruby)
|
1
2
|
[![Build Status](https://travis-ci.org/estepnv/fast_serializer.svg?branch=master)](https://travis-ci.org/estepnv/fast_serializer)
|
2
|
-
[![Maintainability](https://api.codeclimate.com/v1/badges/
|
3
|
-
[![Test Coverage](https://api.codeclimate.com/v1/badges/
|
3
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/df7897bec85d376709bd/maintainability)](https://codeclimate.com/github/estepnv/fast_serializer/maintainability)
|
4
|
+
[![Test Coverage](https://api.codeclimate.com/v1/badges/df7897bec85d376709bd/test_coverage)](https://codeclimate.com/github/estepnv/fast_serializer/test_coverage)
|
4
5
|
|
5
6
|
# fast_serializer
|
6
7
|
|
7
|
-
|
8
|
+
`fast_serializer_ruby` is a lightweight ruby object to hash transformer.
|
9
|
+
This library intends to solve such a typical and on the other hand important problem as efficient ruby object to hash transformation.
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
+
## Performance 🚀
|
12
|
+
- running on ruby 2.7 is **at least 6 times faster** than AMS (benchmarks was borrowed from fast_jsonapi repository)
|
13
|
+
- running on ruby 2.7 it consumes **6 times less RAM**
|
14
|
+
- running on jruby 9.2.7.0 **is at least 4 times faster** than AMS after warming up
|
11
15
|
|
12
|
-
|
13
|
-
|
16
|
+
## Compatibility 👌
|
17
|
+
I tried to keep the API as close as possible to active_model_serializer implementation because we all got used to it.
|
18
|
+
|
19
|
+
## Features
|
20
|
+
- conditional rendering
|
21
|
+
- inheritence
|
22
|
+
- included/excluded associations
|
14
23
|
|
15
24
|
|
16
25
|
## Installation
|
@@ -18,7 +27,7 @@ That's why it's so performant.
|
|
18
27
|
Add this line to your application's Gemfile:
|
19
28
|
|
20
29
|
```ruby
|
21
|
-
gem '
|
30
|
+
gem 'fast_serializer_ruby'
|
22
31
|
```
|
23
32
|
|
24
33
|
And then execute:
|
@@ -27,38 +36,43 @@ And then execute:
|
|
27
36
|
|
28
37
|
Or install it yourself as:
|
29
38
|
|
30
|
-
$ gem install
|
39
|
+
$ gem install fast_serializer_ruby
|
31
40
|
|
32
41
|
## Usage
|
33
42
|
|
34
|
-
fast_serializer supports default schema definition using class methods
|
43
|
+
`fast_serializer` supports default schema definition using class methods
|
35
44
|
|
36
45
|
```ruby
|
37
46
|
class ResourceSerializer
|
38
47
|
include FastSerializer::Schema::Mixin
|
48
|
+
|
39
49
|
root :resource
|
40
|
-
|
50
|
+
|
41
51
|
attributes :id, :email, :phone
|
42
|
-
|
43
|
-
attribute(:string_id, if: ->
|
44
|
-
attribute(:float_id, unless:
|
45
|
-
attribute(:full_name) {
|
46
|
-
|
52
|
+
|
53
|
+
attribute(:string_id, if: -> { params[:stringify] }) { resource.id.to_s }
|
54
|
+
attribute(:float_id, unless: :stringify?) { object.id.to_f }
|
55
|
+
attribute(:full_name) { params[:only_first_name] ? resource.first_name : "#{resource.first_name} #{resource.last_name}" }
|
56
|
+
|
47
57
|
has_one :has_one_relationship, serializer: ResourceSerializer
|
48
58
|
has_many :has_many_relationship, serializer: ResourceSerializer
|
59
|
+
|
60
|
+
def stringify?
|
61
|
+
params[:stringify]
|
62
|
+
end
|
49
63
|
end
|
50
64
|
|
51
|
-
ResourceSerializer.new(resource, meta: {foo: "bar"}, only_first_name: false, stringify: true).serializable_hash
|
65
|
+
ResourceSerializer.new(resource, meta: {foo: "bar"}, only_first_name: false, stringify: true, exclude: [:has_many_relationship]).serializable_hash
|
52
66
|
=> {
|
53
67
|
:resource => {
|
54
|
-
:id => 7873392581,
|
55
|
-
:email => "houston@luettgen.info",
|
56
|
-
:full_name => "Jamar Graham",
|
57
|
-
:phone => "627.051.6039 x1475",
|
68
|
+
:id => 7873392581,
|
69
|
+
:email => "houston@luettgen.info",
|
70
|
+
:full_name => "Jamar Graham",
|
71
|
+
:phone => "627.051.6039 x1475",
|
58
72
|
:has_one_relationship => {
|
59
|
-
:id => 6218322696,
|
60
|
-
:email=>"terrellrobel@pagac.info",
|
61
|
-
:full_name => "Clay Kuphal",
|
73
|
+
:id => 6218322696,
|
74
|
+
:email=>"terrellrobel@pagac.info",
|
75
|
+
:full_name => "Clay Kuphal",
|
62
76
|
:phone => "1-604-682-0732 x882"
|
63
77
|
}
|
64
78
|
},
|
@@ -80,14 +94,14 @@ schema.has_one(:has_one_relationship, schema: schema)
|
|
80
94
|
|
81
95
|
schema.serializable_hash
|
82
96
|
=> {
|
83
|
-
:id => 7873392581,
|
84
|
-
:email => "houston@luettgen.info",
|
85
|
-
:full_name => "Jamar Graham",
|
86
|
-
:phone => "627.051.6039 x1475",
|
97
|
+
:id => 7873392581,
|
98
|
+
:email => "houston@luettgen.info",
|
99
|
+
:full_name => "Jamar Graham",
|
100
|
+
:phone => "627.051.6039 x1475",
|
87
101
|
:has_one_relationship => {
|
88
|
-
:id => 6218322696,
|
89
|
-
:email=>"terrellrobel@pagac.info",
|
90
|
-
:full_name => "Clay Kuphal",
|
102
|
+
:id => 6218322696,
|
103
|
+
:email=>"terrellrobel@pagac.info",
|
104
|
+
:full_name => "Clay Kuphal",
|
91
105
|
:phone => "1-604-682-0732 x882"
|
92
106
|
}
|
93
107
|
}
|
@@ -101,8 +115,6 @@ schema.serializable_hash
|
|
101
115
|
|
102
116
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
103
117
|
|
104
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
105
|
-
|
106
118
|
## Contributing
|
107
119
|
|
108
120
|
Bug reports and pull requests are welcome on GitHub at https://github.com/estepnv/fast_serializer. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
data/fast_serializer.gemspec
CHANGED
@@ -10,10 +10,12 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.authors = ['Evgeny Stepanov']
|
11
11
|
spec.email = ['estepnv@icloud.com']
|
12
12
|
|
13
|
-
spec.summary = '
|
14
|
-
spec.description = '
|
13
|
+
spec.summary = 'fast_serializer is a lightweight ruby objects serializer.'
|
14
|
+
spec.description = 'This library intends to solve such a typical and on the other hand important problem as efficient ruby object to hash transformation.'
|
15
15
|
spec.homepage = 'https://github.com/estepnv/fast_serializer'
|
16
16
|
spec.license = 'MIT'
|
17
|
+
spec.platform = Gem::Platform::RUBY
|
18
|
+
spec.required_ruby_version = '>= 2.3.0'
|
17
19
|
|
18
20
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
19
21
|
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
@@ -31,17 +33,8 @@ Gem::Specification.new do |spec|
|
|
31
33
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
32
34
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{(test|spec|features|git|rspec|travis)/}) }
|
33
35
|
end
|
34
|
-
|
36
|
+
|
37
|
+
spec.bindir = 'bin'
|
35
38
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
36
39
|
spec.require_paths = ['lib']
|
37
|
-
|
38
|
-
spec.add_development_dependency 'active_model_serializers', '~> 0.10.0'
|
39
|
-
spec.add_development_dependency 'activesupport', '<6'
|
40
|
-
spec.add_development_dependency 'factory_bot'
|
41
|
-
spec.add_development_dependency 'faker'
|
42
|
-
spec.add_development_dependency 'pry'
|
43
|
-
spec.add_development_dependency 'rake', '~> 10.0'
|
44
|
-
spec.add_development_dependency 'rspec', '~> 3.0'
|
45
|
-
spec.add_development_dependency 'rspec-benchmark'
|
46
|
-
spec.add_development_dependency 'simplecov'
|
47
40
|
end
|
data/lib/fast_serializer.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'fast_serializer/version'
|
4
|
+
require 'fast_serializer/utils'
|
4
5
|
require 'fast_serializer/configuration'
|
5
6
|
require 'fast_serializer/json_model'
|
6
7
|
require 'fast_serializer/schema'
|
8
|
+
require 'fast_serializer/schema/mixin'
|
7
9
|
|
8
10
|
module FastSerializer
|
9
11
|
class Error < StandardError; end
|
10
|
-
# Your code goes here...
|
11
12
|
end
|
@@ -1,17 +1,29 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'json'
|
4
|
+
|
3
5
|
module FastSerializer
|
4
6
|
class Configuration
|
5
|
-
|
7
|
+
attr_reader :coder
|
8
|
+
attr_accessor :strict
|
6
9
|
|
7
10
|
def initialize
|
8
11
|
@coder = JSON
|
12
|
+
@strict = false
|
13
|
+
end
|
14
|
+
|
15
|
+
def coder=(obj)
|
16
|
+
unless obj.respond_to?(:dump) && obj.respond_to?(:load)
|
17
|
+
raise ArgumentError, 'must respond to #load and #dump methods'
|
18
|
+
end
|
19
|
+
|
20
|
+
@coder = obj
|
9
21
|
end
|
10
22
|
end
|
11
23
|
|
12
24
|
class << self
|
13
25
|
def config
|
14
|
-
@
|
26
|
+
@config ||= Configuration.new
|
15
27
|
end
|
16
28
|
|
17
29
|
def configure(&block)
|