-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
87 additions
and
54 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
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,28 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'active_support/notifications' | ||
|
||
module BrightSerializer | ||
module Extensions | ||
module Instrumentation | ||
SERIALIZABLE_HASH_NOTIFICATION = 'render.bright_serializer.serializable_hash' | ||
SERIALIZED_JSON_NOTIFICATION = 'render.bright_serializer.serialized_json' | ||
|
||
def to_hash | ||
def serializable_hash | ||
ActiveSupport::Notifications.instrument(SERIALIZABLE_HASH_NOTIFICATION, name: self.class.name) do | ||
super | ||
end | ||
end | ||
|
||
alias serialize_hash to_hash | ||
alias to_hash serializable_hash | ||
|
||
def to_json(*_args) | ||
def serialized_json(*_args) | ||
ActiveSupport::Notifications.instrument(SERIALIZED_JSON_NOTIFICATION, name: self.class.name) do | ||
super | ||
end | ||
end | ||
|
||
alias serialize_json to_json | ||
alias to_json serialized_json | ||
end | ||
end | ||
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
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
26 changes: 26 additions & 0 deletions
26
spec/lib/bright_serializer/extensions/instrumentation_spec.rb
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,26 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'bright_serializer/extensions/instrumentation' | ||
|
||
RSpec.describe BrightSerializer::Extensions::Instrumentation do | ||
let(:instance) { described_class.new } | ||
|
||
describe 'using extension' do | ||
context 'when Rails is defined' do | ||
let(:rails_class) do | ||
stub_const 'ActiveSupport', Class.new | ||
end | ||
|
||
let(:serializer_class) do | ||
rails_class | ||
Class.new do | ||
include BrightSerializer::Serializer | ||
end | ||
end | ||
|
||
it 'have Extension::Instrumentation in ancestors' do | ||
expect(serializer_class.ancestors).to include described_class | ||
end | ||
end | ||
end | ||
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
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
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