benchmark/collection.rb in alba-1.6.0 vs benchmark/collection.rb in alba-2.0.0
- old
+ new
@@ -17,11 +17,10 @@
gem "blueprinter"
gem "fast_serializer_ruby"
gem "jbuilder"
gem 'turbostreamer'
gem "jserializer"
- gem "jsonapi-serializer" # successor of fast_jsonapi
gem "multi_json"
gem "panko_serializer"
gem "pg"
gem "primalize"
gem "oj"
@@ -199,71 +198,10 @@
def commenter_names
object.commenters.pluck(:name)
end
end
-# --- JSONAPI:Serializer serializers / (successor of fast_jsonapi) ---
-
-class JsonApiStandardCommentSerializer
- include JSONAPI::Serializer
-
- attribute :id
- attribute :body
-end
-
-class JsonApiStandardPostSerializer
- include JSONAPI::Serializer
-
- # set_type :post # optional
- attribute :id
- attribute :body
- attribute :commenter_names
-
- attribute :comments do |post|
- post.comments.map { |comment| JsonApiSameFormatCommentSerializer.new(comment) }
- end
-end
-
-# --- JSONAPI:Serializer serializers that format the code the same flat way as the other gems here ---
-
-# code to convert from JSON:API output to "flat" JSON, like the other serializers build
-class JsonApiSameFormatSerializer
- include JSONAPI::Serializer
-
- def as_json(*_options)
- hash = serializable_hash
-
- if hash[:data].is_a? Hash
- hash[:data][:attributes]
-
- elsif hash[:data].is_a? Array
- hash[:data].pluck(:attributes)
-
- elsif hash[:data].nil?
- { }
-
- else
- raise "unexpected data type #{hash[:data].class}"
- end
- end
-end
-
-class JsonApiSameFormatCommentSerializer < JsonApiSameFormatSerializer
- attribute :id
- attribute :body
-end
-
-class JsonApiSameFormatPostSerializer < JsonApiSameFormatSerializer
- attribute :id
- attribute :body
- attribute :commenter_names
-
- attribute :comments do |post|
- post.comments.map { |comment| JsonApiSameFormatCommentSerializer.new(comment) }
- end
-end
-
# --- Panko serializers ---
#
require "panko_serializer"
@@ -417,12 +355,10 @@
json.post post.to_builder
end
end.target!
end
jserializer = Proc.new { JserializerPostSerializer.new(posts, is_collection: true).to_json }
-jsonapi = proc { JsonApiStandardPostSerializer.new(posts).to_json }
-jsonapi_same_format = proc { JsonApiSameFormatPostSerializer.new(posts).to_json }
panko = proc { Panko::ArraySerializer.new(posts, each_serializer: PankoPostSerializer).to_json }
primalize = proc { PrimalizePostsResource.new(posts: posts).to_json }
rails = Proc.new do
ActiveSupport::JSON.encode(posts.map{ |post| post.serializable_hash(include: :comments) })
end
@@ -439,12 +375,10 @@
ams: ams,
blueprinter: blueprinter,
fast_serializer: fast_serializer,
jbuilder: jbuilder, # different order
jserializer: jserializer,
- jsonapi: jsonapi, # nested JSON:API format
- jsonapi_same_format: jsonapi_same_format,
panko: panko,
primalize: primalize,
rails: rails,
representable: representable,
simple_ams: simple_ams,
@@ -460,12 +394,10 @@
x.report(:ams, &ams)
x.report(:blueprinter, &blueprinter)
x.report(:fast_serializer, &fast_serializer)
x.report(:jbuilder, &jbuilder)
x.report(:jserializer, &jserializer)
- x.report(:jsonapi, &jsonapi)
- x.report(:jsonapi_same_format, &jsonapi_same_format)
x.report(:panko, &panko)
x.report(:primalize, &primalize)
x.report(:rails, &rails)
x.report(:representable, &representable)
x.report(:simple_ams, &simple_ams)
@@ -482,11 +414,9 @@
x.report(:ams, &ams)
x.report(:blueprinter, &blueprinter)
x.report(:fast_serializer, &fast_serializer)
x.report(:jbuilder, &jbuilder)
x.report(:jserializer, &jserializer)
- x.report(:jsonapi, &jsonapi)
- x.report(:jsonapi_same_format, &jsonapi_same_format)
x.report(:panko, &panko)
x.report(:primalize, &primalize)
x.report(:rails, &rails)
x.report(:representable, &representable)
x.report(:simple_ams, &simple_ams)