panko_serializer 0.8.1 → 0.8.3

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 (58) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +6 -0
  3. data/.github/workflows/docs.yml +6 -6
  4. data/.github/workflows/lint.yml +9 -19
  5. data/.github/workflows/ruby.yml +14 -10
  6. data/.gitignore +2 -0
  7. data/.rubocop.yml +29 -21
  8. data/Appraisals +29 -0
  9. data/Gemfile +12 -14
  10. data/README.md +6 -7
  11. data/Rakefile +3 -1
  12. data/benchmarks/allocs.rb +2 -2
  13. data/benchmarks/benchmarking_support.rb +2 -1
  14. data/benchmarks/bm_ams_0_10.rb +3 -7
  15. data/benchmarks/bm_panko_json.rb +2 -6
  16. data/benchmarks/bm_panko_object.rb +2 -6
  17. data/benchmarks/bm_plain_object.rb +1 -4
  18. data/benchmarks/bm_serialization_descriptor.rb +1 -1
  19. data/benchmarks/bm_to_object.rb +2 -6
  20. data/benchmarks/profile.rb +2 -2
  21. data/benchmarks/sanity.rb +2 -6
  22. data/benchmarks/setup.rb +4 -3
  23. data/benchmarks/type_casts/bm_active_record.rb +10 -39
  24. data/benchmarks/type_casts/bm_panko.rb +3 -6
  25. data/benchmarks/type_casts/support.rb +0 -1
  26. data/docs/docs/associations.md +20 -7
  27. data/docs/docs/attributes.md +29 -23
  28. data/docs/docs/design-choices.md +28 -27
  29. data/docs/docs/getting-started.md +9 -3
  30. data/docs/docs/introduction.md +5 -5
  31. data/docs/docs/performance.md +0 -1
  32. data/docs/docs/response-bag.md +8 -1
  33. data/docs/docusaurus.config.js +86 -0
  34. data/docs/package-lock.json +12607 -18674
  35. data/docs/package.json +14 -7
  36. data/docs/src/css/customTheme.css +9 -0
  37. data/docs/static/CNAME +1 -0
  38. data/ext/panko_serializer/attributes_writer/active_record.c +103 -72
  39. data/ext/panko_serializer/attributes_writer/active_record.h +2 -0
  40. data/ext/panko_serializer/attributes_writer/type_cast/type_cast.c +17 -0
  41. data/gemfiles/7.0.0.gemfile +39 -0
  42. data/gemfiles/7.0.0.gemfile.lock +176 -0
  43. data/gemfiles/7.1.0.gemfile +39 -0
  44. data/gemfiles/7.1.0.gemfile.lock +198 -0
  45. data/gemfiles/7.2.0.gemfile +39 -0
  46. data/gemfiles/7.2.0.gemfile.lock +198 -0
  47. data/gemfiles/8.0.0.gemfile +39 -0
  48. data/gemfiles/8.0.0.gemfile.lock +219 -0
  49. data/lib/panko/serializer.rb +1 -1
  50. data/lib/panko/version.rb +1 -1
  51. data/panko_serializer.gemspec +2 -1
  52. metadata +31 -10
  53. data/.standard.yml +0 -4
  54. data/docs/.DS_Store +0 -0
  55. data/docs/README.md +0 -198
  56. data/docs/core/Footer.js +0 -80
  57. data/docs/i18n/en.json +0 -50
  58. data/docs/siteConfig.js +0 -80
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b1f46c78adb3128739cca219e9835e4411c2a9e9ac65f7cf18444c7bddd432a4
4
- data.tar.gz: e30e2ba7abbb08270b00dc9d71ef1fb2b509b6d2778d9971b3d19283e5830369
3
+ metadata.gz: e04b05a5a9a72ce68ad0768dd84b403e4adb6cefa8226f89c30a09d480993481
4
+ data.tar.gz: 1d7ff5f7b035a497e4b7d48e9749bfc13c3861cfb067b53b167b54c2ce5c8822
5
5
  SHA512:
6
- metadata.gz: b70dac493132900bf6f9b6490679f399a2dc0e38a54d25f3a50f5bcba9e04da137d7e9b4fc7d87a81747ed8625e486750dda4dca5086a8ce38750c85205e50c9
7
- data.tar.gz: 9f1f330ff1c05694bade23bbaee954c4bfa281a27de8e2c872271b30fb2ea9a893074041af050249073d33ed074e038757c37973c555c053b9e84f86edf8b2ea
6
+ metadata.gz: 9bcb10f0e30eb48277dcdc9eea463dd475e892ed6eca37818d0d21eb9978cabeb1d0c7b1b8989ff69c1dc5c9b958fe8d0d073f0861d4b7207054e33677d615e7
7
+ data.tar.gz: 98846622471bed88140fe737f12144e9221e8a439c181c45d3e4ae1cd95aef265e640dd5bb4fda1d6beb8f4fc1f6eecc016620d31b9ec2a51fec6cc214683830
@@ -0,0 +1,6 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: "github-actions"
4
+ directory: "/"
5
+ schedule:
6
+ interval: "monthly"
@@ -5,7 +5,7 @@ name: Docs Publishing
5
5
 
6
6
  on:
7
7
  push:
8
- branches: [ master ]
8
+ branches: [ master, docup ]
9
9
 
10
10
  jobs:
11
11
  build:
@@ -15,18 +15,18 @@ jobs:
15
15
  working_directory: 'docs/'
16
16
 
17
17
  steps:
18
- - uses: actions/checkout@v2
18
+ - uses: actions/checkout@v4
19
19
  - name: Use Node.js ${{ matrix.node-version }}
20
- uses: actions/setup-node@v1
20
+ uses: actions/setup-node@v4
21
21
  with:
22
- node-version: '16.x'
22
+ node-version: '20.x'
23
23
 
24
24
  - name: Install Dependencies
25
25
  working-directory: ${{ env.working_directory }}
26
26
  run: npm install
27
27
 
28
28
  - name: Install SSH Client 🔑
29
- uses: webfactory/ssh-agent@v0.4.1
29
+ uses: webfactory/ssh-agent@v0.6.0
30
30
  with:
31
31
  ssh-private-key: ${{ secrets.DEPLOY_KEY }}
32
32
 
@@ -35,5 +35,5 @@ jobs:
35
35
  run: |
36
36
  git config --global user.email "action@github.com"
37
37
  git config --global user.name "GitHub Action"
38
- GIT_USER=yosiat CURRENT_BRANCH=master USE_SSH=true npm run publish-gh-pages
38
+ GIT_USER=yosiat CURRENT_BRANCH=master USE_SSH=true npm run deploy
39
39
 
@@ -7,33 +7,23 @@ jobs:
7
7
  runs-on: ubuntu-latest
8
8
 
9
9
  steps:
10
- - uses: actions/checkout@v2
11
- - name: Set up Ruby
12
- uses: ruby/setup-ruby@v1
13
- with:
14
- ruby-version: 3.1.0
10
+ - uses: actions/checkout@v4
15
11
 
16
12
  - name: Install deps
17
13
  run: |
18
14
  sudo apt update -y
19
15
  sudo apt install -y libsqlite3-dev
20
16
 
21
- - name: Install gems
22
- env:
23
- RAILS_VERSION: "7.0"
24
- run: |
25
- gem install bundler
26
- bundle config set path 'vendor/bundle'
27
- bundle check || bundle install --jobs 4 --retry 3
28
-
29
- - name: Lint ruby
30
- env:
31
- RAILS_VERSION: "7.0"
32
- run: |
33
- bundle exec rake standard
17
+ - name: Lint Ruby code
18
+ uses: ruby/setup-ruby@v1
19
+ with:
20
+ ruby-version: 3
21
+ bundler-cache: true
22
+ - run: |
23
+ bundle exec rake rubocop
34
24
 
35
25
  - name: Lint C
36
- uses: jidicula/clang-format-action@v4.11.0
26
+ uses: jidicula/clang-format-action@v4.13.0
37
27
  with:
38
28
  clang-format-version: "16"
39
29
  check-path: "ext/panko_serializer"
@@ -8,24 +8,28 @@ jobs:
8
8
  strategy:
9
9
  fail-fast: false
10
10
  matrix:
11
- ruby: ["3.0", "3.1", "3.2"]
12
- rails: ["6.1.0", "7.0.0"]
11
+ ruby: ["3.1", "3.2", "3.3"]
12
+ rails: ["7.0.0", "7.1.0", "7.2.0", "8.0.0"]
13
+ exclude:
14
+ - ruby: 3.1
15
+ rails: 8.0.0
13
16
 
14
17
  steps:
15
- - uses: actions/checkout@v2
18
+ - name: Install deps
19
+ run: |
20
+ sudo apt update -y
21
+ sudo apt install -y libsqlite3-dev
22
+
23
+ - uses: actions/checkout@v4
16
24
  - name: Set up Ruby ${{ matrix.ruby }}
17
25
  uses: ruby/setup-ruby@v1
18
26
  with:
19
27
  ruby-version: ${{ matrix.ruby }}
20
28
 
21
- - name: Install deps
22
- run: |
23
- sudo apt update -y
24
- sudo apt install -y libsqlite3-dev
25
29
 
26
30
  - name: Gems Cache
27
31
  id: gem-cache
28
- uses: actions/cache@v1
32
+ uses: actions/cache@v4
29
33
  with:
30
34
  path: vendor/bundle
31
35
  key: ${{ runner.os }}-${{ matrix.ruby }}-${{ matrix.rails }}-gem
@@ -34,7 +38,7 @@ jobs:
34
38
 
35
39
  - name: Install gems
36
40
  env:
37
- RAILS_VERSION: ${{ matrix.rails }}
41
+ BUNDLE_GEMFILE: gemfiles/${{ matrix.rails }}.gemfile
38
42
  run: |
39
43
  gem install bundler
40
44
  bundle config set path 'vendor/bundle'
@@ -42,6 +46,6 @@ jobs:
42
46
 
43
47
  - name: Compile & test
44
48
  env:
45
- RAILS_VERSION: ${{ matrix.rails }}
49
+ BUNDLE_GEMFILE: gemfiles/${{ matrix.rails }}.gemfile
46
50
  run: |
47
51
  bundle exec rake
data/.gitignore CHANGED
@@ -16,3 +16,5 @@
16
16
  node_modules
17
17
 
18
18
  /docs/build/
19
+ .cache/
20
+ .docusaurus/
data/.rubocop.yml CHANGED
@@ -1,29 +1,37 @@
1
- AllCops:
2
- TargetRubyVersion: 2.5
3
- DisplayCopNames: true
4
- StyleGuideCopsOnly: false
1
+ # We want Exclude directives from different
2
+ # config files to get merged, not overwritten
3
+ inherit_mode:
4
+ merge:
5
+ - Exclude
6
+
7
+ require:
8
+ - standard
9
+ - rubocop-performance
10
+ - standard-performance
11
+ - rubocop-rspec
12
+
13
+ inherit_gem:
14
+ standard: config/base.yml
15
+ standard-performance: config/base.yml
5
16
 
6
- Metrics/LineLength:
7
- Max: 120
17
+ AllCops:
18
+ TargetRubyVersion: 3.1
19
+ SuggestExtensions: false
20
+ NewCops: disable
21
+ Exclude:
22
+ - ext/**/*
23
+ - gemfiles/**/*
8
24
 
9
- Style/StringLiterals:
10
- EnforcedStyle: double_quotes
11
25
 
12
26
  Style/FrozenStringLiteralComment:
13
27
  Enabled: true
14
28
  EnforcedStyle: always
29
+ SafeAutoCorrect: true
15
30
 
16
- Layout/TrailingBlankLines:
17
- Enabled: true
18
-
19
- Layout/TrailingWhitespace:
20
- Enabled: true
31
+ # TODO: need to work on specs.
32
+ RSpec:
33
+ Enabled: false
21
34
 
22
- Style/FrozenStringLiteralComment:
23
- Enabled: true
24
-
25
- Style/RedundantFreeze:
26
- Enabled: true
27
-
28
- Performance/UnfreezeString:
29
- Enabled: true
35
+ Lint/ConstantDefinitionInBlock:
36
+ Exclude:
37
+ - spec/**/*
data/Appraisals ADDED
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ appraise "7.0.0" do
4
+ gem "sqlite3", "~> 1.4"
5
+ gem "activesupport", "~> 7.0.0"
6
+ gem "activemodel", "~> 7.0.0"
7
+ gem "activerecord", "~> 7.0.0", group: :test
8
+ end
9
+
10
+ appraise "7.1.0" do
11
+ gem "sqlite3", "~> 1.4"
12
+ gem "activesupport", "~> 7.1.5"
13
+ gem "activemodel", "~> 7.1.5"
14
+ gem "activerecord", "~> 7.1.5", group: :test
15
+ end
16
+
17
+ appraise "7.2.0" do
18
+ gem "sqlite3", "~> 1.4"
19
+ gem "activesupport", "~> 7.2.0"
20
+ gem "activemodel", "~> 7.2.0"
21
+ gem "activerecord", "~> 7.2.0", group: :test
22
+ end
23
+
24
+ appraise "8.0.0" do
25
+ gem "sqlite3", ">= 2.1"
26
+ gem "activesupport", "~> 8.0.0"
27
+ gem "activemodel", "~> 8.0.0"
28
+ gem "activerecord", "~> 8.0.0", group: :test
29
+ end
data/Gemfile CHANGED
@@ -4,24 +4,15 @@ source "https://rubygems.org"
4
4
 
5
5
  gemspec
6
6
 
7
- raw_rails_version = ENV.fetch("RAILS_VERSION", "6.1.0")
8
- rails_version = "~> #{raw_rails_version}"
9
-
10
- gem "activesupport", rails_version
11
- gem "activemodel", rails_version
12
- gem "activerecord", rails_version, group: :test
13
-
14
7
  group :benchmarks do
15
- gem "sqlite3", "~> 1.4"
16
- gem "pg", ">= 0.18", "< 2.0"
17
-
18
- gem "memory_profiler"
19
- gem "ruby-prof", platforms: [:mri]
20
- gem "ruby-prof-flamegraph", platforms: [:mri]
8
+ gem "vernier"
9
+ gem "stackprof"
10
+ gem "pg"
21
11
 
22
12
  gem "benchmark-ips"
23
13
  gem "active_model_serializers", "~> 0.10"
24
14
  gem "terminal-table"
15
+ gem "memory_profiler"
25
16
  end
26
17
 
27
18
  group :test do
@@ -35,4 +26,11 @@ group :development do
35
26
  gem "rake-compiler"
36
27
  end
37
28
 
38
- gem "standard", group: [:development, :test]
29
+ group :development, :test do
30
+ gem "rubocop"
31
+
32
+ gem "standard"
33
+ gem "standard-performance"
34
+ gem "rubocop-performance"
35
+ gem "rubocop-rspec"
36
+ end
data/README.md CHANGED
@@ -2,25 +2,24 @@
2
2
 
3
3
  ![Build Status](https://github.com/yosiat/panko_serializer/workflows/Panko%20Serializer%20CI/badge.svg?branch=master)
4
4
 
5
- Panko is library which is inspired by ActiveModelSerializers 0.9 for serializing ActiveRecord/Ruby objects to JSON strings, fast.
5
+ Panko is a 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://panko.dev/docs/performance.html):
7
+ To achieve its [performance](https://panko.dev/docs/performance/):
8
8
 
9
- * Oj - Panko relies Oj since it's fast and allow to serialize incrementally using `Oj::StringWriter`
9
+ * Oj - Panko relies on Oj since it's fast and allows for incremental serialization 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 on ActiveRecord.
11
+ * Type casting — Panko does type casting by itself, instead of relying on ActiveRecord.
12
12
 
13
- To dig deeper about the performance choices, read [Design Choices](https://panko.dev/docs/design-choices.html).
13
+ To dig deeper about the performance choices, read [Design Choices](https://panko.dev/docs/design-choices/).
14
14
 
15
15
 
16
16
  Support
17
17
  -------
18
18
 
19
19
  - [Documentation](https://panko.dev/docs)
20
- - [Getting Started](https://panko.dev/docs/getting-started.html)
20
+ - [Getting Started](https://panko.dev/docs/getting-started/)
21
21
 
22
22
  License
23
23
  -------
24
24
 
25
25
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
26
-
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ require "json"
6
6
  require "terminal-table"
7
7
  require "rake/extensiontask"
8
8
  require "pty"
9
- require "standard/rake"
9
+ require "rubocop/rake_task"
10
10
 
11
11
  gem = Gem::Specification.load(File.dirname(__FILE__) + "/panko_serializer.gemspec")
12
12
 
@@ -24,6 +24,8 @@ Rake::Task[:compile].prerequisites << :clean
24
24
 
25
25
  task default: :spec
26
26
 
27
+ RuboCop::RakeTask.new
28
+
27
29
  def print_and_flush(str)
28
30
  print str
29
31
  $stdout.flush
data/benchmarks/allocs.rb CHANGED
@@ -10,8 +10,8 @@ class PostFastSerializer < Panko::Serializer
10
10
  attributes :id, :body, :title, :author_id
11
11
  end
12
12
 
13
- def count_allocs(&block)
14
- memory_report = MemoryProfiler.report(&block)
13
+ def count_allocs(&)
14
+ memory_report = MemoryProfiler.report(&)
15
15
  puts memory_report.pretty_print
16
16
  end
17
17
 
@@ -9,7 +9,8 @@ module Benchmark
9
9
  def data
10
10
  posts = Post.all.includes(:author).to_a
11
11
  posts_50 = posts.first(50).to_a
12
- {all: posts, small: posts_50}
12
+ posts_single = posts.first(1).to_a
13
+ {all: posts, small: posts_50, single: posts_single}
13
14
  end
14
15
 
15
16
  def run(label = nil, time: 10, disable_gc: true, warmup: 3, &block)
@@ -5,7 +5,7 @@ require_relative "app"
5
5
  require_relative "setup"
6
6
 
7
7
  # disable logging for benchmarks
8
- ActiveModelSerializers.logger = ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new("/dev/null"))
8
+ ActiveModelSerializers.logger = ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(File::NULL))
9
9
 
10
10
  class AmsAuthorFastSerializer < ActiveModel::Serializer
11
11
  attributes :id, :name
@@ -24,17 +24,13 @@ end
24
24
  def benchmark_ams(prefix, serializer, options = {})
25
25
  merged_options = options.merge(each_serializer: serializer)
26
26
 
27
- data = Benchmark.data
28
- posts = data[:all]
29
- posts_50 = data[:small]
27
+ posts = Benchmark.data[:all]
30
28
 
31
29
  Benchmark.run("AMS_#{prefix}_Posts_#{posts.count}") do
32
30
  ActiveModelSerializers::SerializableResource.new(posts, merged_options).to_json
33
31
  end
34
32
 
35
- data = Benchmark.data
36
- posts = data[:all]
37
- posts_50 = data[:small]
33
+ posts_50 = Benchmark.data[:small]
38
34
 
39
35
  Benchmark.run("AMS_#{prefix}_Posts_50") do
40
36
  ActiveModelSerializers::SerializableResource.new(posts_50, merged_options).to_json
@@ -37,9 +37,7 @@ class AuthorWithHasManyFastSerializer < Panko::Serializer
37
37
  end
38
38
 
39
39
  def benchmark(prefix, serializer, options = {})
40
- data = Benchmark.data
41
- posts = data[:all]
42
- posts_50 = data[:small]
40
+ posts = Benchmark.data[:all]
43
41
 
44
42
  merged_options = options.merge(each_serializer: serializer)
45
43
 
@@ -47,9 +45,7 @@ def benchmark(prefix, serializer, options = {})
47
45
  Panko::ArraySerializer.new(posts, merged_options).to_json
48
46
  end
49
47
 
50
- data = Benchmark.data
51
- posts = data[:all]
52
- posts_50 = data[:small]
48
+ posts_50 = Benchmark.data[:small]
53
49
 
54
50
  Benchmark.run("Panko_ActiveRecord_#{prefix}_Posts_50") do
55
51
  Panko::ArraySerializer.new(posts_50, merged_options).to_json
@@ -25,9 +25,7 @@ class AuthorWithHasManyFastSerializer < Panko::Serializer
25
25
  end
26
26
 
27
27
  def benchmark(prefix, serializer, options = {})
28
- data = Benchmark.data
29
- posts = data[:all]
30
- posts_50 = data[:small]
28
+ posts = Benchmark.data[:all]
31
29
 
32
30
  merged_options = options.merge(each_serializer: serializer)
33
31
 
@@ -35,9 +33,7 @@ def benchmark(prefix, serializer, options = {})
35
33
  Panko::ArraySerializer.new(posts, merged_options).to_a
36
34
  end
37
35
 
38
- data = Benchmark.data
39
- posts = data[:all]
40
- posts_50 = data[:small]
36
+ posts_50 = Benchmark.data[:small]
41
37
 
42
38
  Benchmark.run("Panko_ActiveRecord_#{prefix}_Posts_50") do
43
39
  Panko::ArraySerializer.new(posts_50, merged_options).to_a
@@ -78,7 +78,6 @@ end
78
78
  def benchmark(prefix, serializer, options = {})
79
79
  data = benchmark_data
80
80
  posts = data[:all]
81
- posts_50 = data[:small]
82
81
 
83
82
  merged_options = options.merge(each_serializer: serializer)
84
83
 
@@ -86,9 +85,7 @@ def benchmark(prefix, serializer, options = {})
86
85
  Panko::ArraySerializer.new(posts, merged_options).to_json
87
86
  end
88
87
 
89
- data = benchmark_data
90
- posts = data[:all]
91
- posts_50 = data[:small]
88
+ posts_50 = benchmark_data[:small]
92
89
 
93
90
  Benchmark.run("Panko_Plain_#{prefix}_Posts_50") do
94
91
  Panko::ArraySerializer.new(posts_50, merged_options).to_json
@@ -6,7 +6,7 @@ require "active_support"
6
6
  require "panko_serializer"
7
7
 
8
8
  def generate_attributes(count)
9
- (1..count).map { |i| "attr_#{i}".to_sym }
9
+ (1..count).map { |i| :"attr_#{i}" }
10
10
  end
11
11
 
12
12
  class LeafASerializer < Panko::Serializer
@@ -62,9 +62,7 @@ class AuthorWithHasManyFastSerializer < Panko::Serializer
62
62
  end
63
63
 
64
64
  def benchmark(prefix, serializer, options = {})
65
- data = Benchmark.data
66
- posts = data[:all]
67
- posts_50 = data[:small]
65
+ posts = Benchmark.data[:all]
68
66
 
69
67
  merged_options = options.merge(each_serializer: serializer)
70
68
 
@@ -72,9 +70,7 @@ def benchmark(prefix, serializer, options = {})
72
70
  Panko::ArraySerializer.new(posts, merged_options).to_a
73
71
  end
74
72
 
75
- data = Benchmark.data
76
- posts = data[:all]
77
- posts_50 = data[:small]
73
+ posts_50 = Benchmark.data[:small]
78
74
 
79
75
  Benchmark.run("Panko_#{prefix}_Posts_50") do
80
76
  Panko::ArraySerializer.new(posts_50, merged_options).to_a
@@ -78,8 +78,8 @@ def request(method, path)
78
78
  response
79
79
  end
80
80
 
81
- def memory(&block)
82
- mem = MemoryProfiler.report(&block)
81
+ def memory(&)
82
+ mem = MemoryProfiler.report(&)
83
83
  mem.pretty_print
84
84
  end
85
85
 
data/benchmarks/sanity.rb CHANGED
@@ -62,9 +62,7 @@ class AuthorWithHasManyFastSerializer < Panko::Serializer
62
62
  end
63
63
 
64
64
  def benchmark(prefix, serializer, options = {})
65
- data = Benchmark.data
66
- posts = data[:all]
67
- posts_50 = data[:small]
65
+ posts = Benchmark.data[:all]
68
66
 
69
67
  merged_options = options.merge(each_serializer: serializer)
70
68
 
@@ -72,9 +70,7 @@ def benchmark(prefix, serializer, options = {})
72
70
  Panko::ArraySerializer.new(posts, merged_options).to_json
73
71
  end
74
72
 
75
- data = Benchmark.data
76
- posts = data[:all]
77
- posts_50 = data[:small]
73
+ posts_50 = Benchmark.data[:small]
78
74
 
79
75
  Benchmark.run("Panko_#{prefix}_Posts_50") do
80
76
  Panko::ArraySerializer.new(posts_50, merged_options).to_json
data/benchmarks/setup.rb CHANGED
@@ -5,6 +5,7 @@
5
5
  ##########################################
6
6
  require "active_record"
7
7
  require "sqlite3"
8
+ require "securerandom"
8
9
 
9
10
  # Change the following to reflect your database settings
10
11
  ActiveRecord::Base.establish_connection(
@@ -46,9 +47,9 @@ Author.destroy_all
46
47
  Post.transaction do
47
48
  ENV.fetch("ITEMS_COUNT", "2300").to_i.times do
48
49
  Post.create(
49
- body: "something about how password restrictions are evil, and less secure, and with the math to prove it.",
50
- title: "Your bank is does not know how to do security",
51
- author: Author.create(name: "Preston Sego"),
50
+ body: SecureRandom.hex(30),
51
+ title: SecureRandom.hex(20),
52
+ author: Author.create(name: SecureRandom.alphanumeric),
52
53
  data: {a: 1, b: 2, c: 3}
53
54
  )
54
55
  end
@@ -5,26 +5,14 @@ require_relative "support"
5
5
  def ar_type_convert(type_klass, from, to)
6
6
  converter = type_klass.new
7
7
 
8
- if ENV["RAILS_VERSION"].start_with? "4.2"
9
- assert type_klass.name, converter.type_cast_from_database(from), to
8
+ assert type_klass.name, converter.deserialize(from), to
10
9
 
11
- Benchmark.run("#{type_klass.name}_TypeCast") do
12
- converter.type_cast_from_database(from)
13
- end
14
-
15
- Benchmark.run("#{type_klass.name}_NoTypeCast") do
16
- converter.type_cast_from_database(to)
17
- end
18
- else
19
- assert type_klass.name, converter.deserialize(from), to
20
-
21
- Benchmark.run("#{type_klass.name}_TypeCast") do
22
- converter.deserialize(from)
23
- end
10
+ Benchmark.run("#{type_klass.name}_TypeCast") do
11
+ converter.deserialize(from)
12
+ end
24
13
 
25
- Benchmark.run("#{type_klass.name}_NoTypeCast") do
26
- converter.deserialize(to)
27
- end
14
+ Benchmark.run("#{type_klass.name}_NoTypeCast") do
15
+ converter.deserialize(to)
28
16
  end
29
17
  end
30
18
 
@@ -36,14 +24,8 @@ def utc_ar_time
36
24
  type = ActiveRecord::ConnectionAdapters::PostgreSQL::OID::DateTime.new
37
25
  converter = ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter.new(type)
38
26
 
39
- if ENV["RAILS_VERSION"].start_with? "4.2"
40
- Benchmark.run("#{tz}_#{type.class.name}_TypeCast") do
41
- converter.type_cast_from_database(from).iso8601
42
- end
43
- else
44
- Benchmark.run("#{tz}_#{type.class.name}_TypeCast") do
45
- converter.deserialize(from).iso8601
46
- end
27
+ Benchmark.run("#{tz}_#{type.class.name}_TypeCast") do
28
+ converter.deserialize(from).iso8601
47
29
  end
48
30
  end
49
31
 
@@ -53,14 +35,8 @@ def db_ar_time
53
35
 
54
36
  from = "2017-07-10 09:26:40.937392"
55
37
 
56
- if ENV["RAILS_VERSION"].start_with? "4.2"
57
- Benchmark.run("ActiveRecord_Time_TypeCast_WithISO8601") do
58
- converter.type_cast_from_database(from).iso8601
59
- end
60
- else
61
- Benchmark.run("ActiveRecord_Time_TypeCast_WithISO8601") do
62
- converter.deserialize(from).iso8601
63
- end
38
+ Benchmark.run("ActiveRecord_Time_TypeCast_WithISO8601") do
39
+ converter.deserialize(from).iso8601
64
40
  end
65
41
  end
66
42
 
@@ -71,11 +47,6 @@ ar_type_convert ActiveRecord::Type::Float, "1.23", 1.23
71
47
  ar_type_convert ActiveRecord::Type::Boolean, "true", true
72
48
  ar_type_convert ActiveRecord::Type::Boolean, "t", true
73
49
 
74
- if ENV["RAILS_VERSION"].start_with? "4.2"
75
- ar_type_convert ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Integer, "1", 1
76
- ar_type_convert ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Float, "1.23", 1.23
77
- ar_type_convert ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Float, "Infinity", ::Float::INFINITY
78
- end
79
50
  if check_if_exists "ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Json"
80
51
  ar_type_convert ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Json, '{"a":1}', {a: 1}
81
52
  end
@@ -52,15 +52,12 @@ panko_type_convert ActiveRecord::Type::Float, "1.23", 1.23
52
52
  panko_type_convert ActiveRecord::Type::Boolean, "true", true
53
53
  panko_type_convert ActiveRecord::Type::Boolean, "t", true
54
54
 
55
- if ENV["RAILS_VERSION"].start_with? "4.2"
56
- panko_type_convert ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Integer, "1", 1
57
- panko_type_convert ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Float, "1.23", 1.23
58
- panko_type_convert ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Float, "Infinity", ::Float::INFINITY
59
- end
60
-
61
55
  if check_if_exists "ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Json"
62
56
  panko_type_convert ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Json, '{"a":1}', '{"a":1}'
63
57
  end
58
+ if check_if_exists "ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Jsonb"
59
+ panko_type_convert ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Jsonb, '{"a":1}', '{"a":1}'
60
+ end
64
61
  if check_if_exists "ActiveRecord::Type::Json"
65
62
  panko_type_convert ActiveRecord::Type::Json, '{"a":1}', '{"a":1}'
66
63
  end
@@ -25,4 +25,3 @@ def check_if_exists(module_name)
25
25
  end
26
26
 
27
27
  Time.zone = "UTC"
28
- ActiveSupport::Deprecation.behavior = :stderr