Class: Transmutation::Serialization::Lookup Private
- Inherits:
-
Object
- Object
- Transmutation::Serialization::Lookup
- Defined in:
- lib/transmutation/serialization/lookup.rb,
lib/transmutation/serialization/lookup/serializer_not_found.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Defined Under Namespace
Classes: SerializerNotFound
Instance Method Summary collapse
-
#initialize(caller, namespace: nil) ⇒ Lookup
constructor
private
A new instance of Lookup.
-
#serializer_for(object, serializer: nil) ⇒ Object
private
Bubbles up the namespace until we find a matching serializer.
-
#serializer_name_for(object, serializer: nil) ⇒ String
private
Returns the highest specificity serializer name for the given object.
Constructor Details
#initialize(caller, namespace: nil) ⇒ Lookup
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Lookup.
7 8 9 10 |
# File 'lib/transmutation/serialization/lookup.rb', line 7 def initialize(caller, namespace: nil) @caller = caller @namespace = namespace end |
Instance Method Details
#serializer_for(object, serializer: nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This never bubbles up the object’s namespace, only the caller’s namespace.
Bubbles up the namespace until we find a matching serializer.
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/transmutation/serialization/lookup.rb', line 28 def serializer_for(object, serializer: nil) serializer_name = serializer_name_for(object, serializer:) return constantize_serializer!(Object, serializer_name, object:) if serializer_name.start_with?("::") potential_namespaces.each do |potential_namespace| return potential_namespace.const_get(serializer_name) if potential_namespace.const_defined?(serializer_name) end Transmutation::ObjectSerializer end |
#serializer_name_for(object, serializer: nil) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the highest specificity serializer name for the given object.
45 46 47 |
# File 'lib/transmutation/serialization/lookup.rb', line 45 def serializer_name_for(object, serializer: nil) "#{serializer&.delete_suffix("Serializer") || object.class.name}Serializer" end |