panko_serializer 0.7.0 → 0.7.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/docs.yml +39 -0
  3. data/.github/workflows/ruby.yml +51 -0
  4. data/.gitignore +2 -1
  5. data/Gemfile +2 -2
  6. data/README.md +7 -7
  7. data/benchmarks/bm_panko_json.rb +5 -1
  8. data/benchmarks/setup.rb +3 -1
  9. data/benchmarks/type_casts/bm_panko.rb +2 -2
  10. data/docs/.DS_Store +0 -0
  11. data/docs/README.md +195 -8
  12. data/docs/core/Footer.js +81 -0
  13. data/docs/{associations.md → docs/associations.md} +8 -4
  14. data/docs/{attributes.md → docs/attributes.md} +25 -13
  15. data/docs/{design-choices.md → docs/design-choices.md} +6 -2
  16. data/docs/{getting-started.md → docs/getting-started.md} +19 -2
  17. data/docs/docs/introduction.md +13 -0
  18. data/docs/{performance.md → docs/performance.md} +11 -7
  19. data/docs/{response-bag.md → docs/response-bag.md} +24 -1
  20. data/docs/i18n/en.json +50 -0
  21. data/docs/package-lock.json +9636 -0
  22. data/docs/package.json +14 -0
  23. data/docs/sidebars.json +15 -0
  24. data/docs/siteConfig.js +80 -0
  25. data/docs/static/.DS_Store +0 -0
  26. data/docs/static/css/custom.css +51 -0
  27. data/docs/static/img/favicon.ico +0 -0
  28. data/docs/static/img/oss_logo.png +0 -0
  29. data/docs/static/img/undraw_code_review.svg +1 -0
  30. data/docs/static/img/undraw_monitor.svg +1 -0
  31. data/docs/static/img/undraw_note_list.svg +1 -0
  32. data/docs/static/img/undraw_online.svg +1 -0
  33. data/docs/static/img/undraw_open_source.svg +1 -0
  34. data/docs/static/img/undraw_operating_system.svg +1 -0
  35. data/docs/static/img/undraw_react.svg +1 -0
  36. data/docs/static/img/undraw_tweetstorm.svg +1 -0
  37. data/docs/static/img/undraw_youtube_tutorial.svg +1 -0
  38. data/docs/static/index.html +14 -0
  39. data/ext/panko_serializer/attributes_writer/active_record.c +58 -16
  40. data/ext/panko_serializer/attributes_writer/attributes_writer.c +8 -7
  41. data/ext/panko_serializer/attributes_writer/common.h +1 -1
  42. data/ext/panko_serializer/attributes_writer/hash.c +2 -4
  43. data/ext/panko_serializer/attributes_writer/plain.c +2 -3
  44. data/ext/panko_serializer/attributes_writer/type_cast/type_cast.c +70 -21
  45. data/ext/panko_serializer/attributes_writer/type_cast/type_cast.h +1 -2
  46. data/ext/panko_serializer/panko_serializer.c +23 -8
  47. data/ext/panko_serializer/serialization_descriptor/association.c +1 -0
  48. data/ext/panko_serializer/serialization_descriptor/attribute.c +1 -0
  49. data/ext/panko_serializer/serialization_descriptor/serialization_descriptor.c +7 -10
  50. data/lib/panko/association.rb +1 -1
  51. data/lib/panko/object_writer.rb +8 -0
  52. data/lib/panko/response.rb +5 -4
  53. data/lib/panko/serializer.rb +6 -2
  54. data/lib/panko/serializer_resolver.rb +28 -15
  55. data/lib/panko/version.rb +1 -1
  56. data/panko_serializer.gemspec +8 -7
  57. metadata +59 -23
  58. data/.travis.yml +0 -29
  59. data/docs/docpress.json +0 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c4f169a6a48bba339628ae84995ec2ee3bf66ef059e941be74a89dbe6ec4e983
4
- data.tar.gz: dff287d42fe253ef3647f0555e47be7fea55ecc2cf1025cb6b0e55a734ca7806
3
+ metadata.gz: e0377ad83b60ba60530ba87694837b265bfe3890806afeac84544c336351ff06
4
+ data.tar.gz: adbb80b08811b8b240e4af98214834e8876a11a267db58c8dad9accb90e3bee6
5
5
  SHA512:
6
- metadata.gz: 6e7507ee84bf00be48b9a5e35c9f06aacf083216242925889e2f1f0dfb24d87ba1a3ddbdd77bbf580f3000c5671873344dd32e98eea77f84bf175b4cf7c746be
7
- data.tar.gz: 0cb0515ccd98c7f260f81d7e1ecb1f684d70d03609b849fd2141d4a4630946622cbc34a6ae1666f6ca5a226066f959280b08bde5ad81f6c02e7d59cf9da6f466
6
+ metadata.gz: e55156ac125c66c98f9099ddf2d37427e3dc81048bd0d94d97b98055ff2df0272ba65196b41d0410bcea271879593d6ad37c7ea39d6ecea48629438af75e55d1
7
+ data.tar.gz: a2a71b526addc0593bd6f33edf07cda15dfd46fe11f00342fe5b8bfbc13e0648c78da598d010e741c9fc03cd4543bcafea6d0c3a3fc8c35cd68a2188848860be
@@ -0,0 +1,39 @@
1
+ # This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
2
+ # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3
+
4
+ name: Docs Publishing
5
+
6
+ on:
7
+ push:
8
+ branches: [ master ]
9
+
10
+ jobs:
11
+ build:
12
+
13
+ runs-on: ubuntu-latest
14
+ env:
15
+ working_directory: 'docs/'
16
+
17
+ steps:
18
+ - uses: actions/checkout@v2
19
+ - name: Use Node.js ${{ matrix.node-version }}
20
+ uses: actions/setup-node@v1
21
+ with:
22
+ node-version: '12.x'
23
+
24
+ - name: Install Dependencies
25
+ working-directory: ${{ env.working_directory }}
26
+ run: npm install
27
+
28
+ - name: Install SSH Client 🔑
29
+ uses: webfactory/ssh-agent@v0.4.1
30
+ with:
31
+ ssh-private-key: ${{ secrets.DEPLOY_KEY }}
32
+
33
+ - name: Publish
34
+ working-directory: ${{ env.working_directory }}
35
+ run: |
36
+ git config --global user.email "action@github.com"
37
+ git config --global user.name "GitHub Action"
38
+ GIT_USER=panko-serializer CURRENT_BRANCH=master USE_SSH=true npm run publish-gh-pages
39
+
@@ -0,0 +1,51 @@
1
+ name: Panko Serializer CI
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ build:
7
+
8
+ runs-on: ubuntu-latest
9
+ strategy:
10
+ fail-fast: false
11
+ matrix:
12
+ ruby: [ '2.5', '2.6', '2.7', '3.0']
13
+ rails: ['5.2.0', '6.0.0', '6.1.0']
14
+ exclude:
15
+ - ruby: '3.0'
16
+ rails: '5.2.0'
17
+
18
+ steps:
19
+ - uses: actions/checkout@v2
20
+ - name: Set up Ruby ${{ matrix.ruby }}
21
+ uses: actions/setup-ruby@v1
22
+ with:
23
+ ruby-version: ${{ matrix.ruby }}
24
+
25
+ - name: Install deps
26
+ run: |
27
+ sudo apt update -y
28
+ sudo apt install -y libsqlite3-dev
29
+
30
+ - name: Gems Cache
31
+ id: gem-cache
32
+ uses: actions/cache@v1
33
+ with:
34
+ path: vendor/bundle
35
+ key: ${{ runner.os }}-${{ matrix.ruby }}-${{ matrix.rails }}-gem
36
+ restore-keys: |
37
+ ${{ runner.os }}-${{ matrix.ruby }}-${{ matrix.rails }}-gem
38
+
39
+ - name: Install gems
40
+ env:
41
+ RAILS_VERSION: ${{ matrix.rails }}
42
+ run: |
43
+ gem install bundler
44
+ bundle config set path 'vendor/bundle'
45
+ bundle check || bundle install --jobs 4 --retry 3
46
+
47
+ - name: Compile & test
48
+ env:
49
+ RAILS_VERSION: ${{ matrix.rails }}
50
+ run: |
51
+ bundle exec rake
data/.gitignore CHANGED
@@ -13,5 +13,6 @@
13
13
 
14
14
  # rspec failure tracking
15
15
  .rspec_status
16
- _docpress
17
16
  node_modules
17
+
18
+ /docs/build/
data/Gemfile CHANGED
@@ -25,8 +25,8 @@ group :benchmarks do
25
25
  end
26
26
 
27
27
  gem "memory_profiler"
28
- gem "ruby-prof"
29
- gem "ruby-prof-flamegraph"
28
+ gem "ruby-prof", platforms: [:mri]
29
+ gem "ruby-prof-flamegraph", platforms: [:mri]
30
30
 
31
31
  gem "benchmark-ips"
32
32
  gem "active_model_serializers"
data/README.md CHANGED
@@ -1,23 +1,23 @@
1
1
  # Panko
2
2
 
3
- [![Build Status](https://api.travis-ci.com/yosiat/panko_serializer.svg?branch=master)](https://travis-ci.com/yosiat/panko_serializer)
3
+ ![Build Status](https://github.com/panko-serializer/panko_serializer/workflows/Panko%20Serializer%20CI/badge.svg?branch=github-actions)
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://yosiat.github.io/panko_serializer/performance.html):
7
+ To achieve it's [performance](https://panko.dev/docs/performance.html):
8
8
 
9
- * Oj - Panko relies Oj since it's fast and allow to to serialize incrementally using `Oj::StringWriter`
9
+ * Oj - Panko relies Oj since it's fast and allow 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
- * Type casting — Panko does type casting by it's self, instead of relying ActiveRecord.
11
+ * Type casting — Panko does type casting by it's self, instead of relying on ActiveRecord.
12
12
 
13
- To dig deeper about the performance choices, read [Design Choices](https://yosiat.github.io/panko_serializer/design-choices.html).
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://yosiat.github.io/panko_serializer)
20
- - [Getting Started](https://yosiat.github.io/panko_serializer/getting-started.html)
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
@@ -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
- * [Panko](../README.md)
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/).
@@ -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/panko-serializer/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="/panko-serializer/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;