mirror of
https://github.com/LukeHagar/plexruby.git
synced 2025-12-09 20:57:43 +00:00
ci: regenerated with OpenAPI Doc , Speakeasy CLI 1.529.1
This commit is contained in:
@@ -13,25 +13,20 @@ module Crystalline
|
||||
end
|
||||
|
||||
sig { params(complex: Object).returns(Object) }
|
||||
def self.marshal_dict_complex(complex)
|
||||
def self.to_dict(complex)
|
||||
if complex.is_a? Array
|
||||
complex.map { |v| Crystalline.marshal_dict_complex(v) }
|
||||
complex.map { |v| Crystalline.to_dict(v) }
|
||||
elsif complex.is_a? Hash
|
||||
complex.transform_values { |v| Crystalline.marshal_dict_complex(v) }
|
||||
complex.transform_values { |v| Crystalline.to_dict(v) }
|
||||
elsif complex.is_a? Crystalline::FieldAugmented
|
||||
complex.to_dict
|
||||
else
|
||||
complex
|
||||
val_to_string complex, primitives: false
|
||||
end
|
||||
end
|
||||
|
||||
def self.marshal_json_complex(complex)
|
||||
JSON.dump(marshal_dict_complex(complex))
|
||||
end
|
||||
|
||||
sig { params(data: Object, type: Object).returns(Object) }
|
||||
def self.unmarshal_complex(data, type)
|
||||
unmarshal_json(data, type)
|
||||
def self.to_json(complex)
|
||||
JSON.dump(to_dict(complex))
|
||||
end
|
||||
|
||||
sig { params(data: Object, type: Object).returns(Object) }
|
||||
@@ -42,9 +37,9 @@ module Crystalline
|
||||
if type.instance_of?(Class) && type < ::Crystalline::FieldAugmented
|
||||
type.from_dict(data)
|
||||
elsif T.arr? type
|
||||
data.map { |v| Crystalline.unmarshal_complex(v, T.arr_of(type)) }
|
||||
data.map { |v| Crystalline.unmarshal_json(v, T.arr_of(type)) }
|
||||
elsif T.hash? type
|
||||
data.transform_values { |v| Crystalline.unmarshal_complex(v, T.hash_of(type)) }
|
||||
data.transform_values { |v| Crystalline.unmarshal_json(v, T.hash_of(type)) }
|
||||
else
|
||||
data
|
||||
end
|
||||
@@ -62,4 +57,25 @@ module Crystalline
|
||||
val
|
||||
end
|
||||
end
|
||||
|
||||
sig { params(klass: T.any(Class, T::Types::TypedArray, T::Types::TypedHash)).returns(Integer) }
|
||||
def self.non_nilable_attr_count(klass)
|
||||
# somewhat sane sort ordering for Union deserialization.
|
||||
# All Crystalline objects return the number of non-nilable fields
|
||||
# All non-string primitives return 2
|
||||
# All arrays and hashes return 1
|
||||
# Strings return 0 (since any data can deserialize to a string, it should be our last attempt)
|
||||
if klass.respond_to? :fields
|
||||
return -1 * klass.fields.count do |field|
|
||||
!T.nilable? field.type
|
||||
end
|
||||
else
|
||||
if klass == String
|
||||
return 0
|
||||
elsif klass.is_a?(T::Types::TypedArray) || klass.is_a?(T::Types::TypedHash)
|
||||
return 1
|
||||
end
|
||||
return 2
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user