Skip to content

Commit

Permalink
Make RequestContext serializable
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Dolski committed Jan 5, 2024
1 parent a3fe7f8 commit 860003c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
28 changes: 28 additions & 0 deletions app/models/request_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,34 @@
#
class RequestContext

##
# N.B.: we've told ActiveJob this class exists using
# `config/initializers/active_job.rb`.
#
class RequestContextSerializer < ActiveJob::Serializers::ObjectSerializer
def serialize?(argument)
argument.kind_of?(RequestContext)
end

def serialize(request_context)
super(
client_hostname: request_context.client_hostname,
client_ip: request_context.client_ip,
institution: request_context.institution,
user: request_context.user,
role_limit: request_context.role_limit
)
end

def deserialize(hash)
RequestContext.new(client_hostname: hash["client_hostname"],
client_ip: hash["client_ip"],
user: hash['user'],
institution: hash['institution'],
role_limit: hash['role_limit'])
end
end

##
# Client hostname.
#
Expand Down
2 changes: 2 additions & 0 deletions config/initializers/active_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require "request_context"
Rails.application.config.active_job.custom_serializers << ::RequestContext::RequestContextSerializer

0 comments on commit 860003c

Please sign in to comment.