<commit_before>"
I represent a Cargo package ready to be serialized.
I factorize some fields declaration and some utilty methods.

Do not use me directly but use one of my subclasses!
"
Class {
	#name : #CGOVcsSerializedPackage,
	#superclass : #Object,
	#instVars : [
		'dict'
	],
	#category : #'CargoPackageManager-Minimal-Model-Serialization'
}

{ #category : #'instance creation' }
CGOVcsSerializedPackage class >> fromDictionary: aDictionary [ 
	^ self basicNew 
		initializeWithDictionary: aDictionary;
		yourself.
]

{ #category : #utility }
CGOVcsSerializedPackage >> addPropertyNamed: aString ifNotEmptyOrNil: aCollection [ 
	aCollection ifNil: [ ^ self ]. "NOOP"
	^ aCollection
		ifNotEmpty: [ dict at: aString  put: aCollection asArray ]
]

{ #category : #serialization }
CGOVcsSerializedPackage >> asString [
	^ CGOPackageVersionWriterV1 toStringPretty: dict
]

{ #category : #serialization }
CGOVcsSerializedPackage >> dependencyConstraintsMapping: aDependency [
	^ (aDependency constraints collect: #asString)
			ifEmpty: [ #() ]
]

{ #category : #deserialization }
CGOVcsSerializedPackage >> deserializedDependencies: aListOfSerializedDependencies [
	^ aListOfSerializedDependencies 
		ifNil: [ OrderedCollection empty ]
		ifNotNil: [ aListOfSerializedDependencies collect:
				[ :associationOrString | | association |
					association := associationOrString isString 
						ifTrue: [ associationOrString -> #() ]
						ifFalse: [ associationOrString ].
					CGOPackageDependency newFrom: association ] ]
]

{ #category : #utility }
CGOVcsSerializedPackage >> dictionaryOrNilIfEmpty: aDictionary [
	aDictionary ifNil: [ ^ nil ].
	^ aDictionary ifEmpty: [ nil ]
]

{ #category : #initialization }
CGOVcsSerializedPackage >> initializeWithDictionary: aDictionary [ 
	dict := aDictionary
]

{ #category : #initialization }
CGOVcsSerializedPackage >> initializeWithOngoing: aCGOOngoingPackageUnit [
	dict := OrderedDictionary new.
	dict at: #name put: aCGOOngoingPackageUnit name.
	dict at: #description put: aCGOOngoingPackageUnit description.
]

{ #category : #serialization }
CGOVcsSerializedPackage >> serializedDependenciesOf: aPackageDependencyList [
	^ self toArray:
		(aPackageDependencyList
			collect: [ :dependency |	| constraints |
				constraints := self dependencyConstraintsMapping: dependency.
				constraints
					ifEmpty: [ dependency dependencyName ]
					ifNotEmpty: [ Association key: dependency dependencyName value: constraints ] ])
]<commit_msg>Do not serialize description if nil<commit_after>"
I represent a Cargo package ready to be serialized.
I factorize some fields declaration and some utilty methods.

Do not use me directly but use one of my subclasses!
"
Class {
	#name : #CGOVcsSerializedPackage,
	#superclass : #Object,
	#instVars : [
		'dict'
	],
	#category : #'CargoPackageManager-Minimal-Model-Serialization'
}

{ #category : #'instance creation' }
CGOVcsSerializedPackage class >> fromDictionary: aDictionary [ 
	^ self basicNew 
		initializeWithDictionary: aDictionary;
		yourself.
]

{ #category : #utility }
CGOVcsSerializedPackage >> addPropertyNamed: aString ifNotEmptyOrNil: aCollection [ 
	aCollection ifNil: [ ^ self ]. "NOOP"
	^ aCollection
		ifNotEmpty: [ dict at: aString  put: aCollection asArray ]
]

{ #category : #serialization }
CGOVcsSerializedPackage >> asString [
	^ CGOPackageVersionWriterV1 toStringPretty: dict
]

{ #category : #serialization }
CGOVcsSerializedPackage >> dependencyConstraintsMapping: aDependency [
	^ (aDependency constraints collect: #asString)
			ifEmpty: [ #() ]
]

{ #category : #deserialization }
CGOVcsSerializedPackage >> deserializedDependencies: aListOfSerializedDependencies [
	^ aListOfSerializedDependencies 
		ifNil: [ OrderedCollection empty ]
		ifNotNil: [ aListOfSerializedDependencies collect:
				[ :associationOrString | | association |
					association := associationOrString isString 
						ifTrue: [ associationOrString -> #() ]
						ifFalse: [ associationOrString ].
					CGOPackageDependency newFrom: association ] ]
]

{ #category : #utility }
CGOVcsSerializedPackage >> dictionaryOrNilIfEmpty: aDictionary [
	aDictionary ifNil: [ ^ nil ].
	^ aDictionary ifEmpty: [ nil ]
]

{ #category : #initialization }
CGOVcsSerializedPackage >> initializeWithDictionary: aDictionary [ 
	dict := aDictionary
]

{ #category : #initialization }
CGOVcsSerializedPackage >> initializeWithOngoing: aCGOOngoingPackageUnit [
	dict := OrderedDictionary new.
	dict at: #name put: aCGOOngoingPackageUnit name.
	aCGOOngoingPackageUnit description 
		ifNotNil: [ dict at: #description put: aCGOOngoingPackageUnit description ].
	
]

{ #category : #serialization }
CGOVcsSerializedPackage >> serializedDependenciesOf: aPackageDependencyList [
	^ self toArray:
		(aPackageDependencyList
			collect: [ :dependency |	| constraints |
				constraints := self dependencyConstraintsMapping: dependency.
				constraints
					ifEmpty: [ dependency dependencyName ]
					ifNotEmpty: [ Association key: dependency dependencyName value: constraints ] ])
]
{'fraction_non_alphanumeric': 0.09157727453317441, 'fraction_numerical': 0.0003972983710766786, 'mean_word_length': 5.2007389162561575, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5326951', 'n_tokens_mistral': 1610, 'n_tokens_neox': 1463, 'n_words': 358}