-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update serialization to use MessagePack (#16)
- Loading branch information
Showing
98 changed files
with
3,722 additions
and
1,026 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
label: "## Table of Contents" | ||
patterns: | ||
- "README.md" | ||
root_dir: "." |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ignore: | ||
- 'lib/**/*': | ||
- Style/ArgumentsForwarding |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
require "pry" | ||
require "benchmark" | ||
require "awesome_print" | ||
|
||
require_relative "../test/rails_kit/setup" | ||
require_relative "../lib/universalid" | ||
|
||
@count = 5_000 | ||
@pad = 98 | ||
|
||
def run(label) | ||
Benchmark.benchmark Benchmark::CAPTION, 52, Benchmark::FORMAT, "Average" do |x| | ||
time = x.report(label) { @count.times { yield } } | ||
[time / @count.to_f] | ||
end | ||
puts "".ljust(@pad, ".") | ||
end | ||
|
||
# seed data .................................................................................................. | ||
campaign = Campaign.create_for_test | ||
campaign.emails = Email.create_for_test(3) do |email| | ||
email.attachments = Attachment.create_for_test(2) | ||
end | ||
hash = campaign.as_json(include: {emails: {include: :attachments}}) | ||
puts "Benchmarking with the following ActiveRecord/Hash data..." | ||
puts "".ljust(@pad, "=") | ||
ap hash | ||
|
||
# pre/setup .................................................................................................. | ||
hash_uid = URI::UID.build(hash) | ||
hash_uid_string = hash_uid.to_s | ||
|
||
active_record_uid = URI::UID.build(campaign, include_descendants: true, descendant_depth: 1) | ||
active_record_uid_string = active_record_uid.to_s | ||
|
||
# benchmarks ................................................................................................. | ||
puts "".ljust(@pad, "=") | ||
puts "Benchmarking #{@count} iterations" | ||
puts "".ljust(@pad, "=") | ||
|
||
# PackableHash ............................................................................................... | ||
run("URI::UID.build Hash") { URI::UID.build hash } | ||
run("URI::UID.build Hash, include_blank: false") { URI::UID.build hash, include_blank: false } | ||
run("URI::UID.parse HASH/UID") { URI::UID.parse hash_uid_string } | ||
run("URI::UID.decode HASH/UID") { hash_uid.decode } | ||
|
||
# ActiveRecord ............................................................................................... | ||
run("URI::UID.build ActiveRecord") { URI::UID.build campaign } | ||
run("URI::UID.build ActiveRecord, exclude_blank") { URI::UID.build campaign, include_blank: false } | ||
run("URI::UID.build ActiveRecord, include_descendants") { URI::UID.build campaign, include_descendants: true, descendant_depth: 2 } | ||
run("URI::UID.parse ActiveRecord/UID") { URI::UID.parse active_record_uid_string } | ||
run("URI::UID.decode HASH/UID") { active_record_uid.decode } | ||
|
||
# Everything ................................................................................................. | ||
run("UID > GID > UID.decode include_descendants") do | ||
URI::UID.from_gid(URI::UID.build(campaign, include_descendants: true, descendant_depth: 2).to_gid_param).decode | ||
end | ||
run("UID > SGID > UID.decode include_descendants") do | ||
URI::UID.from_sgid(URI::UID.build(campaign, include_descendants: true, descendant_depth: 2).to_sgid_param(for: "benchmarks"), for: "benchmarks").decode | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env ruby | ||
|
||
exec File.expand_path("./console", __dir__), *ARGV |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#!/bin/bash | ||
|
||
cloc lib | ||
cloc contrib lib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
bundle exec rake "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env ruby | ||
|
||
exec File.expand_path("./test", __dir__), *ARGV |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env ruby | ||
|
||
globs = if ARGV.size > 1 | ||
ARGV | ||
elsif ARGV.size == 1 | ||
fuzzy = ARGV.first | ||
fuzzy.end_with?("_test.rb") ? | ||
["test/**/*#{fuzzy}"] : | ||
["test/**/*#{fuzzy}**/*_test.rb", "test/**/*#{fuzzy}*_test.rb"] | ||
end | ||
|
||
if globs.nil? | ||
exec "bundle exec rake test" | ||
else | ||
exec "bundle exec rake test GLOBS='#{globs.join(",")}'" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
prepack: | ||
exclude: [] | ||
include: [] | ||
include_blank: true | ||
|
||
database: | ||
include_keys: true | ||
include_timestamps: true | ||
include_unsaved_changes: false | ||
include_descendants: false | ||
descendant_depth: 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
--- | ||
############################################################################################################## | ||
# Prepack options applied before packing with MessagePack | ||
############################################################################################################## | ||
prepack: | ||
# .......................................................................................................... | ||
# A list of attributes to exclude (for objects like Hash, OpenStruct, Struct, etc.) | ||
# Takes prescedence over the`include` list | ||
exclude: [] | ||
|
||
# .......................................................................................................... | ||
# A list of attributes to include (for objects like Hash, OpenStruct, Struct, etc.) | ||
include: [] | ||
|
||
# .......................................................................................................... | ||
# Whether or not to omit blank values when packing (nil, {}, [], "", etc.) | ||
include_blank: true | ||
|
||
# ========================================================================================================== | ||
# Database records | ||
database: | ||
# ...................................................................................................... | ||
# Whether or not to include primary/foreign keys | ||
# Setting this to `false` can be used to make a copy of an existing record | ||
include_keys: true | ||
|
||
# ...................................................................................................... | ||
# Whether or not to include date/time timestamps (created_at, updated_at, etc.) | ||
# Setting this to `false` can be used to make a copy of an existing record | ||
include_timestamps: true | ||
|
||
# ...................................................................................................... | ||
# Whether or not to include unsaved changes | ||
# Assign to `true` when packing new records | ||
include_unsaved_changes: false | ||
|
||
# ...................................................................................................... | ||
# Whether or not to include loaded in-memory descendants (i.e. child associations) | ||
include_descendants: false | ||
|
||
# ...................................................................................................... | ||
# The max depth (number) of loaded in-memory descendants to include when `include_descendants == true` | ||
# For example, a value of (2) would include the following: | ||
# Parent > Child > Grandchild | ||
descendant_depth: 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
if defined?(ActiveRecord) && defined?(ActiveRecord::Base) && defined?(ActiveRecord::Relation) | ||
|
||
require_relative "active_record/base_message_pack_type" | ||
require_relative "active_record/relation_message_pack_type" | ||
|
||
end |
Oops, something went wrong.