Skip to content

Commit

Permalink
Improve documentation of serializer plugin
Browse files Browse the repository at this point in the history
* clarify `format` parameter

* change example more clearly indicate serialization vs deserialization
  • Loading branch information
davetron5000 authored and jeremyevans committed Dec 12, 2024
1 parent b779cb4 commit 0b9547d
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/sequel/plugins/serialization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ module Plugins
#
# # Register custom serializer/deserializer pair, if desired
# require 'sequel/plugins/serialization'
# Sequel::Plugins::Serialization.register_format(:reverse, :reverse.to_proc, :reverse.to_proc)
# require 'base64'
# Sequel::Plugins::Serialization.register_format(:base64, Base64.method(:encode64), Base64.method(:decode64))
#
# class User < Sequel::Model
# # Built-in format support when loading the plugin
Expand All @@ -48,10 +49,10 @@ module Plugins
# serialize_attributes :marshal, :permissions
#
# # Use custom registered serialization format just like built-in format
# serialize_attributes :reverse, :password
# serialize_attributes :base64, :password
#
# # Use a custom serializer/deserializer pair without registering
# serialize_attributes [:reverse.to_proc, :reverse.to_proc], :password
# serialize_attributes [ Base64.method(:encode64), Base64.method(:decode64)], :password
# end
# user = User.create
# user.permissions = {global: 'read-only'}
Expand Down Expand Up @@ -123,7 +124,12 @@ def freeze
end

# Create instance level reader that deserializes column values on request,
# and instance level writer that stores new deserialized values.
# and instance level writer that stores new deserialized values. If +format+
# is a symbol, it should correspond to a previously-registered format using +register_format+.
# Otherwise, +format+ ois expected to be a 2-element array of callables,
# with the first element being the serializer, used to store the column
# to the database, and the second element beig the deserialized,
# used to read the column from the database
def serialize_attributes(format, *columns)
if format.is_a?(Symbol)
unless format = Sequel.synchronize{REGISTERED_FORMATS[format]}
Expand Down

0 comments on commit 0b9547d

Please sign in to comment.