Class: ActiveModelSerializers::Test::Serializer::AssertSerializer
- Inherits:
-
Object
- Object
- ActiveModelSerializers::Test::Serializer::AssertSerializer
- Defined in:
- lib/active_model_serializers/test/serializer.rb
Instance Attribute Summary collapse
-
#expectation ⇒ Object
Returns the value of attribute expectation.
-
#message ⇒ Object
Returns the value of attribute message.
-
#response ⇒ Object
Returns the value of attribute response.
-
#serializers ⇒ Object
readonly
Returns the value of attribute serializers.
Instance Method Summary collapse
-
#initialize ⇒ AssertSerializer
constructor
A new instance of AssertSerializer.
- #matches? ⇒ Boolean
- #subscribe ⇒ Object
- #unsubscribe ⇒ Object
Constructor Details
#initialize ⇒ AssertSerializer
Returns a new instance of AssertSerializer.
45 46 47 48 |
# File 'lib/active_model_serializers/test/serializer.rb', line 45 def initialize @serializers = Set.new @_subscribers = [] end |
Instance Attribute Details
#expectation ⇒ Object
Returns the value of attribute expectation.
43 44 45 |
# File 'lib/active_model_serializers/test/serializer.rb', line 43 def expectation @expectation end |
#message ⇒ Object
Returns the value of attribute message.
42 43 44 |
# File 'lib/active_model_serializers/test/serializer.rb', line 42 def @message end |
#response ⇒ Object
Returns the value of attribute response.
43 44 45 |
# File 'lib/active_model_serializers/test/serializer.rb', line 43 def response @response end |
#serializers ⇒ Object (readonly)
Returns the value of attribute serializers.
42 43 44 |
# File 'lib/active_model_serializers/test/serializer.rb', line 42 def serializers @serializers end |
Instance Method Details
#matches? ⇒ Boolean
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/active_model_serializers/test/serializer.rb', line 54 def matches? # Force body to be read in case the template is being streamed. response.body case expectation when a_serializer? then matches_class? when Symbol then matches_symbol? when String then matches_string? when Regexp then matches_regexp? when NilClass then matches_nil? else fail ArgumentError, 'assert_serializer only accepts a String, Symbol, Regexp, ActiveModel::Serializer, or nil' end end |
#subscribe ⇒ Object
68 69 70 71 72 73 |
# File 'lib/active_model_serializers/test/serializer.rb', line 68 def subscribe @_subscribers << ActiveSupport::Notifications.subscribe(event_name) do |_name, _start, _finish, _id, payload| serializer = payload[:serializer].name serializers << serializer end end |
#unsubscribe ⇒ Object
75 76 77 78 79 |
# File 'lib/active_model_serializers/test/serializer.rb', line 75 def unsubscribe @_subscribers.each do |subscriber| ActiveSupport::Notifications.unsubscribe(subscriber) end end |