panko_serializer 0.7.2 → 0.7.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/.travis.yml +3 -3
- data/README.md +4 -4
- data/benchmarks/bm_panko_json.rb +5 -1
- data/benchmarks/setup.rb +3 -1
- data/benchmarks/type_casts/bm_panko.rb +2 -2
- data/docs/.DS_Store +0 -0
- data/docs/README.md +195 -8
- data/docs/core/Footer.js +81 -0
- data/docs/{associations.md → docs/associations.md} +5 -1
- data/docs/{attributes.md → docs/attributes.md} +6 -2
- data/docs/{design-choices.md → docs/design-choices.md} +5 -1
- data/docs/{getting-started.md → docs/getting-started.md} +5 -1
- data/docs/docs/introduction.md +13 -0
- data/docs/{docpress.json → docs/panko/docpress.json} +0 -0
- data/docs/{performance.md → docs/performance.md} +11 -7
- data/docs/{response-bag.md → docs/response-bag.md} +5 -1
- data/docs/i18n/en.json +50 -0
- data/docs/package-lock.json +9636 -0
- data/docs/package.json +14 -0
- data/docs/sidebars.json +15 -0
- data/docs/siteConfig.js +79 -0
- data/docs/static/.DS_Store +0 -0
- data/docs/static/css/custom.css +51 -0
- data/docs/static/img/favicon.ico +0 -0
- data/docs/static/img/oss_logo.png +0 -0
- data/docs/static/img/undraw_code_review.svg +1 -0
- data/docs/static/img/undraw_monitor.svg +1 -0
- data/docs/static/img/undraw_note_list.svg +1 -0
- data/docs/static/img/undraw_online.svg +1 -0
- data/docs/static/img/undraw_open_source.svg +1 -0
- data/docs/static/img/undraw_operating_system.svg +1 -0
- data/docs/static/img/undraw_react.svg +1 -0
- data/docs/static/img/undraw_tweetstorm.svg +1 -0
- data/docs/static/img/undraw_youtube_tutorial.svg +1 -0
- data/docs/static/index.html +14 -0
- data/ext/panko_serializer/attributes_writer/active_record.c +6 -5
- data/ext/panko_serializer/attributes_writer/common.h +1 -1
- data/ext/panko_serializer/attributes_writer/hash.c +2 -4
- data/ext/panko_serializer/attributes_writer/plain.c +2 -3
- data/ext/panko_serializer/attributes_writer/type_cast/type_cast.c +54 -21
- data/ext/panko_serializer/attributes_writer/type_cast/type_cast.h +1 -2
- data/ext/panko_serializer/panko_serializer.c +15 -7
- data/lib/panko/object_writer.rb +8 -0
- data/lib/panko/version.rb +1 -1
- metadata +31 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d5d2ed524b5e6de2f16281cb90c8d6aca2ade9f6ad87429bce588755fb34ed7e
|
4
|
+
data.tar.gz: 4c7f3cab3e5822242c7afabdd3622cfb9db2fde3c51674ed2a2f6545cf4042c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3f217bfdf440f325d981bab44854d0ee9715907127982f6aa023acbbd0a65286c977115c89b03f1f0c4ebd4dae61497bec06dd25cd530b5884396cd3c0db7ec
|
7
|
+
data.tar.gz: a167d0e32b1fe3287208525cee3291ec13a142dc39c484fdb2542dc4f2999a2d1c72cfacf49eaf98def980576361811279e183a1fbae462542baadbf7981d562
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -21,11 +21,11 @@ install: bundle install --path=vendor/bundle --retry=3
|
|
21
21
|
|
22
22
|
before_install:
|
23
23
|
- gem install bundler
|
24
|
-
- nvm install
|
24
|
+
- nvm install 12
|
25
25
|
|
26
26
|
after_success:
|
27
|
-
-
|
28
|
-
- if [ -n "$TRAVIS_TAG" -a "$TRAVIS_PULL_REQUEST" = "false" ]; then npm install
|
27
|
+
- cd docs/ && npm install
|
28
|
+
- if [ -n "$TRAVIS_TAG" -a "$TRAVIS_PULL_REQUEST" = "false" ]; then cd docs/ && npm install && GIT_USER=yosiat CURRENT_BRANCH=news-docs USE_SSH=true npm run publish-gh-pages; fi
|
29
29
|
- bundle exec rake benchmarks
|
30
30
|
|
31
31
|
matrix:
|
data/README.md
CHANGED
@@ -4,20 +4,20 @@
|
|
4
4
|
|
5
5
|
Panko is library which is inspired by ActiveModelSerializers 0.9 for serializing ActiveRecord/Ruby objects to JSON strings, fast.
|
6
6
|
|
7
|
-
To achieve it's [performance](https://
|
7
|
+
To achieve it's [performance](https://panko.dev/docs/performance.html):
|
8
8
|
|
9
9
|
* Oj - Panko relies Oj since it's fast and allow to to serialize incrementally using `Oj::StringWriter`
|
10
10
|
* Serialization Descriptor - Panko computes most of the metadata ahead of time, to save time later in serialization.
|
11
11
|
* Type casting — Panko does type casting by it's self, instead of relying ActiveRecord.
|
12
12
|
|
13
|
-
To dig deeper about the performance choices, read [Design Choices](https://
|
13
|
+
To dig deeper about the performance choices, read [Design Choices](https://panko.dev/docs/design-choices.html).
|
14
14
|
|
15
15
|
|
16
16
|
Support
|
17
17
|
-------
|
18
18
|
|
19
|
-
- [Documentation](https://
|
20
|
-
- [Getting Started](https://
|
19
|
+
- [Documentation](https://panko.dev/docs)
|
20
|
+
- [Getting Started](https://panko.dev/docs/getting-started.html)
|
21
21
|
- Join our [slack community](https://pankoserializer.herokuapp.com/)
|
22
22
|
|
23
23
|
License
|
data/benchmarks/bm_panko_json.rb
CHANGED
@@ -12,6 +12,10 @@ class PostFastSerializer < Panko::Serializer
|
|
12
12
|
attributes :id, :body, :title, :author_id, :created_at
|
13
13
|
end
|
14
14
|
|
15
|
+
class PostFastWithJsonSerializer < Panko::Serializer
|
16
|
+
attributes :id, :body, :title, :author_id, :created_at, :data
|
17
|
+
end
|
18
|
+
|
15
19
|
class PostFastWithMethodCallSerializer < Panko::Serializer
|
16
20
|
attributes :id, :body, :title, :author_id, :method_call
|
17
21
|
|
@@ -32,7 +36,6 @@ class AuthorWithHasManyFastSerializer < Panko::Serializer
|
|
32
36
|
has_many :posts, serializer: PostFastSerializer
|
33
37
|
end
|
34
38
|
|
35
|
-
|
36
39
|
def benchmark(prefix, serializer, options = {})
|
37
40
|
data = Benchmark.data
|
38
41
|
posts = data[:all]
|
@@ -54,6 +57,7 @@ def benchmark(prefix, serializer, options = {})
|
|
54
57
|
end
|
55
58
|
|
56
59
|
benchmark "Simple", PostFastSerializer
|
60
|
+
benchmark "SimpleWithJson", PostFastWithJsonSerializer
|
57
61
|
benchmark "HasOne", PostWithHasOneFastSerializer
|
58
62
|
benchmark "SimpleWithMethodCall", PostFastWithMethodCallSerializer
|
59
63
|
benchmark "Except", PostWithHasOneFastSerializer, except: [:title]
|
data/benchmarks/setup.rb
CHANGED
@@ -25,6 +25,7 @@ ActiveRecord::Schema.define do
|
|
25
25
|
t.text :body
|
26
26
|
t.string :title
|
27
27
|
t.references :author
|
28
|
+
t.json :data
|
28
29
|
t.timestamps(null: false)
|
29
30
|
end
|
30
31
|
end
|
@@ -47,7 +48,8 @@ Post.transaction do
|
|
47
48
|
Post.create(
|
48
49
|
body: "something about how password restrictions are evil, and less secure, and with the math to prove it.",
|
49
50
|
title: "Your bank is does not know how to do security",
|
50
|
-
author: Author.create(name: "Preston Sego")
|
51
|
+
author: Author.create(name: "Preston Sego"),
|
52
|
+
data: { a: 1, b: 2, c: 3 }
|
51
53
|
)
|
52
54
|
end
|
53
55
|
end
|
@@ -59,10 +59,10 @@ if ENV["RAILS_VERSION"].start_with? "4.2"
|
|
59
59
|
end
|
60
60
|
|
61
61
|
if check_if_exists "ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Json"
|
62
|
-
panko_type_convert ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Json, '{"a":1}', {a:1}
|
62
|
+
panko_type_convert ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Json, '{"a":1}', '{"a":1}'
|
63
63
|
end
|
64
64
|
if check_if_exists "ActiveRecord::Type::Json"
|
65
|
-
panko_type_convert ActiveRecord::Type::Json, '{"a":1}', {a:1}
|
65
|
+
panko_type_convert ActiveRecord::Type::Json, '{"a":1}', '{"a":1}'
|
66
66
|
end
|
67
67
|
db_panko_time
|
68
68
|
utc_panko_time
|
data/docs/.DS_Store
ADDED
Binary file
|
data/docs/README.md
CHANGED
@@ -1,11 +1,198 @@
|
|
1
|
-
|
2
|
-
* [Getting Started](getting-started.md)
|
3
|
-
* Reference
|
4
|
-
* [Attributes](attributes.md)
|
5
|
-
* [Associations](associations.md)
|
6
|
-
* [Response bag](response-bag.md)
|
7
|
-
* [Performance](performance.md)
|
8
|
-
* [Design Choices](design-choices.md)
|
1
|
+
This website was created with [Docusaurus](https://docusaurus.io/).
|
9
2
|
|
3
|
+
# What's In This Document
|
10
4
|
|
5
|
+
- [Get Started in 5 Minutes](#get-started-in-5-minutes)
|
6
|
+
- [Directory Structure](#directory-structure)
|
7
|
+
- [Editing Content](#editing-content)
|
8
|
+
- [Adding Content](#adding-content)
|
9
|
+
- [Full Documentation](#full-documentation)
|
11
10
|
|
11
|
+
# Get Started in 5 Minutes
|
12
|
+
|
13
|
+
1. Make sure all the dependencies for the website are installed:
|
14
|
+
|
15
|
+
```sh
|
16
|
+
# Install dependencies
|
17
|
+
$ yarn
|
18
|
+
```
|
19
|
+
|
20
|
+
2. Run your dev server:
|
21
|
+
|
22
|
+
```sh
|
23
|
+
# Start the site
|
24
|
+
$ yarn start
|
25
|
+
```
|
26
|
+
|
27
|
+
## Directory Structure
|
28
|
+
|
29
|
+
Your project file structure should look something like this
|
30
|
+
|
31
|
+
```
|
32
|
+
my-docusaurus/
|
33
|
+
docs/
|
34
|
+
doc-1.md
|
35
|
+
doc-2.md
|
36
|
+
doc-3.md
|
37
|
+
website/
|
38
|
+
blog/
|
39
|
+
2016-3-11-oldest-post.md
|
40
|
+
2017-10-24-newest-post.md
|
41
|
+
core/
|
42
|
+
node_modules/
|
43
|
+
pages/
|
44
|
+
static/
|
45
|
+
css/
|
46
|
+
img/
|
47
|
+
package.json
|
48
|
+
sidebars.json
|
49
|
+
siteConfig.js
|
50
|
+
```
|
51
|
+
|
52
|
+
# Editing Content
|
53
|
+
|
54
|
+
## Editing an existing docs page
|
55
|
+
|
56
|
+
Edit docs by navigating to `docs/` and editing the corresponding document:
|
57
|
+
|
58
|
+
`docs/doc-to-be-edited.md`
|
59
|
+
|
60
|
+
```markdown
|
61
|
+
---
|
62
|
+
id: page-needs-edit
|
63
|
+
title: This Doc Needs To Be Edited
|
64
|
+
---
|
65
|
+
|
66
|
+
Edit me...
|
67
|
+
```
|
68
|
+
|
69
|
+
For more information about docs, click [here](https://docusaurus.io/docs/en/navigation)
|
70
|
+
|
71
|
+
## Editing an existing blog post
|
72
|
+
|
73
|
+
Edit blog posts by navigating to `website/blog` and editing the corresponding post:
|
74
|
+
|
75
|
+
`website/blog/post-to-be-edited.md`
|
76
|
+
|
77
|
+
```markdown
|
78
|
+
---
|
79
|
+
id: post-needs-edit
|
80
|
+
title: This Blog Post Needs To Be Edited
|
81
|
+
---
|
82
|
+
|
83
|
+
Edit me...
|
84
|
+
```
|
85
|
+
|
86
|
+
For more information about blog posts, click [here](https://docusaurus.io/docs/en/adding-blog)
|
87
|
+
|
88
|
+
# Adding Content
|
89
|
+
|
90
|
+
## Adding a new docs page to an existing sidebar
|
91
|
+
|
92
|
+
1. Create the doc as a new markdown file in `/docs`, example `docs/newly-created-doc.md`:
|
93
|
+
|
94
|
+
```md
|
95
|
+
---
|
96
|
+
id: newly-created-doc
|
97
|
+
title: This Doc Needs To Be Edited
|
98
|
+
---
|
99
|
+
|
100
|
+
My new content here..
|
101
|
+
```
|
102
|
+
|
103
|
+
1. Refer to that doc's ID in an existing sidebar in `website/sidebars.json`:
|
104
|
+
|
105
|
+
```javascript
|
106
|
+
// Add newly-created-doc to the Getting Started category of docs
|
107
|
+
{
|
108
|
+
"docs": {
|
109
|
+
"Getting Started": [
|
110
|
+
"quick-start",
|
111
|
+
"newly-created-doc" // new doc here
|
112
|
+
],
|
113
|
+
...
|
114
|
+
},
|
115
|
+
...
|
116
|
+
}
|
117
|
+
```
|
118
|
+
|
119
|
+
For more information about adding new docs, click [here](https://docusaurus.io/docs/en/navigation)
|
120
|
+
|
121
|
+
## Adding a new blog post
|
122
|
+
|
123
|
+
1. Make sure there is a header link to your blog in `website/siteConfig.js`:
|
124
|
+
|
125
|
+
`website/siteConfig.js`
|
126
|
+
|
127
|
+
```javascript
|
128
|
+
headerLinks: [
|
129
|
+
...
|
130
|
+
{ blog: true, label: 'Blog' },
|
131
|
+
...
|
132
|
+
]
|
133
|
+
```
|
134
|
+
|
135
|
+
2. Create the blog post with the format `YYYY-MM-DD-My-Blog-Post-Title.md` in `website/blog`:
|
136
|
+
|
137
|
+
`website/blog/2018-05-21-New-Blog-Post.md`
|
138
|
+
|
139
|
+
```markdown
|
140
|
+
---
|
141
|
+
author: Frank Li
|
142
|
+
authorURL: https://twitter.com/foobarbaz
|
143
|
+
authorFBID: 503283835
|
144
|
+
title: New Blog Post
|
145
|
+
---
|
146
|
+
|
147
|
+
Lorem Ipsum...
|
148
|
+
```
|
149
|
+
|
150
|
+
For more information about blog posts, click [here](https://docusaurus.io/docs/en/adding-blog)
|
151
|
+
|
152
|
+
## Adding items to your site's top navigation bar
|
153
|
+
|
154
|
+
1. Add links to docs, custom pages or external links by editing the headerLinks field of `website/siteConfig.js`:
|
155
|
+
|
156
|
+
`website/siteConfig.js`
|
157
|
+
|
158
|
+
```javascript
|
159
|
+
{
|
160
|
+
headerLinks: [
|
161
|
+
...
|
162
|
+
/* you can add docs */
|
163
|
+
{ doc: 'my-examples', label: 'Examples' },
|
164
|
+
/* you can add custom pages */
|
165
|
+
{ page: 'help', label: 'Help' },
|
166
|
+
/* you can add external links */
|
167
|
+
{ href: 'https://github.com/facebook/docusaurus', label: 'GitHub' },
|
168
|
+
...
|
169
|
+
],
|
170
|
+
...
|
171
|
+
}
|
172
|
+
```
|
173
|
+
|
174
|
+
For more information about the navigation bar, click [here](https://docusaurus.io/docs/en/navigation)
|
175
|
+
|
176
|
+
## Adding custom pages
|
177
|
+
|
178
|
+
1. Docusaurus uses React components to build pages. The components are saved as .js files in `website/pages/en`:
|
179
|
+
1. If you want your page to show up in your navigation header, you will need to update `website/siteConfig.js` to add to the `headerLinks` element:
|
180
|
+
|
181
|
+
`website/siteConfig.js`
|
182
|
+
|
183
|
+
```javascript
|
184
|
+
{
|
185
|
+
headerLinks: [
|
186
|
+
...
|
187
|
+
{ page: 'my-new-custom-page', label: 'My New Custom Page' },
|
188
|
+
...
|
189
|
+
],
|
190
|
+
...
|
191
|
+
}
|
192
|
+
```
|
193
|
+
|
194
|
+
For more information about custom pages, click [here](https://docusaurus.io/docs/en/custom-pages).
|
195
|
+
|
196
|
+
# Full Documentation
|
197
|
+
|
198
|
+
Full documentation can be found on the [website](https://docusaurus.io/).
|
data/docs/core/Footer.js
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) 2017-present, Facebook, Inc.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*/
|
7
|
+
|
8
|
+
const React = require('react');
|
9
|
+
|
10
|
+
class Footer extends React.Component {
|
11
|
+
docUrl(doc, language) {
|
12
|
+
const baseUrl = this.props.config.baseUrl;
|
13
|
+
const docsUrl = this.props.config.docsUrl;
|
14
|
+
const docsPart = `${docsUrl ? `${docsUrl}/` : ''}`;
|
15
|
+
return `${baseUrl}${docsPart}${doc}`;
|
16
|
+
}
|
17
|
+
|
18
|
+
pageUrl(doc, language) {
|
19
|
+
const baseUrl = this.props.config.baseUrl;
|
20
|
+
return baseUrl + (language ? `${language}/` : '') + doc;
|
21
|
+
}
|
22
|
+
|
23
|
+
render() {
|
24
|
+
return (
|
25
|
+
<footer className="nav-footer" id="footer">
|
26
|
+
<section className="sitemap">
|
27
|
+
<a href={this.props.config.baseUrl} className="nav-home">
|
28
|
+
{this.props.config.footerIcon && (
|
29
|
+
<img
|
30
|
+
src={this.props.config.baseUrl + this.props.config.footerIcon}
|
31
|
+
alt={this.props.config.title}
|
32
|
+
width="66"
|
33
|
+
height="58"
|
34
|
+
/>
|
35
|
+
)}
|
36
|
+
</a>
|
37
|
+
<div>
|
38
|
+
<h5>Docs</h5>
|
39
|
+
<a href={this.docUrl('getting-started.html', this.props.language)}>
|
40
|
+
Getting Started
|
41
|
+
</a>
|
42
|
+
<a href={this.docUrl('attributes.html', this.props.language)}>
|
43
|
+
Guides
|
44
|
+
</a>
|
45
|
+
<a href={this.docUrl('performance.html', this.props.language)}>
|
46
|
+
Performance
|
47
|
+
</a>
|
48
|
+
</div>
|
49
|
+
<div>
|
50
|
+
<h5>More</h5>
|
51
|
+
<a href="https://github.com/yosiat/panko_serializer">GitHub</a>
|
52
|
+
<a href="https://pankoserializer.herokuapp.com/">Slack</a>
|
53
|
+
<a
|
54
|
+
className="github-button"
|
55
|
+
href={this.props.config.repoUrl}
|
56
|
+
data-icon="octicon-star"
|
57
|
+
data-count-href="/yosiat/panko_serializer/stargazers"
|
58
|
+
data-show-count="true"
|
59
|
+
data-count-aria-label="# stargazers on GitHub"
|
60
|
+
aria-label="Star this project on GitHub">
|
61
|
+
Star
|
62
|
+
</a>
|
63
|
+
{this.props.config.twitterUsername && (
|
64
|
+
<div className="social">
|
65
|
+
<a
|
66
|
+
href={`https://twitter.com/${this.props.config.twitterUsername}`}
|
67
|
+
className="twitter-follow-button">
|
68
|
+
Follow @{this.props.config.twitterUsername}
|
69
|
+
</a>
|
70
|
+
</div>
|
71
|
+
)}
|
72
|
+
</div>
|
73
|
+
</section>
|
74
|
+
|
75
|
+
<section className="copyright">{this.props.config.copyright}</section>
|
76
|
+
</footer>
|
77
|
+
);
|
78
|
+
}
|
79
|
+
}
|
80
|
+
|
81
|
+
module.exports = Footer;
|
@@ -1,4 +1,8 @@
|
|
1
|
-
|
1
|
+
---
|
2
|
+
id: attributes
|
3
|
+
title: Attributes
|
4
|
+
sidebar_label: Attributes
|
5
|
+
---
|
2
6
|
|
3
7
|
Attributes allow you to specify which record attributes you want to serialize,
|
4
8
|
There are two types of attributes:
|
@@ -42,7 +46,7 @@ end
|
|
42
46
|
|
43
47
|
Another useful, thing you can pass your serializer is `context`, a `context` is a bag of data whom your serializer may need.
|
44
48
|
|
45
|
-
For example, here we will pass
|
49
|
+
For example, here we will pass feature flags:
|
46
50
|
```ruby
|
47
51
|
class UserSerializer < Panko::Serializer
|
48
52
|
attributes :id, :email
|
@@ -1,4 +1,8 @@
|
|
1
|
-
|
1
|
+
---
|
2
|
+
id: design-choices
|
3
|
+
title: Design Choices
|
4
|
+
sidebar_label: Design Choices
|
5
|
+
---
|
2
6
|
|
3
7
|
In short, Panko, is a serializer for ActiveRecord objects (it can't serialize any other object), which strives for high performance & simple API (which is inspired by ActiveModelSerializers).
|
4
8
|
|