aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/package/complete_package.rs
blob: 2120eecfd433624dceed69d94c5f81522db81c1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
//! ref: composer/src/Composer/Package/CompletePackage.php

use indexmap::IndexMap;
use shirabe_php_shim::PhpMixed;
use crate::package::complete_package_interface::CompletePackageInterface;
use crate::package::package::Package;

#[derive(Debug)]
pub struct CompletePackage {
    pub(crate) inner: Package,
    pub(crate) repositories: Vec<IndexMap<String, PhpMixed>>,
    pub(crate) license: Vec<String>,
    pub(crate) keywords: Vec<String>,
    pub(crate) authors: Vec<IndexMap<String, String>>,
    pub(crate) description: Option<String>,
    pub(crate) homepage: Option<String>,
    pub(crate) scripts: IndexMap<String, Vec<String>>,
    pub(crate) support: IndexMap<String, String>,
    pub(crate) funding: Vec<IndexMap<String, PhpMixed>>,
    pub(crate) abandoned: PhpMixed,
    pub(crate) archive_name: Option<String>,
    pub(crate) archive_excludes: Vec<String>,
}

impl CompletePackageInterface for CompletePackage {
    fn set_scripts(&mut self, scripts: IndexMap<String, Vec<String>>) {
        self.scripts = scripts;
    }

    fn get_scripts(&self) -> IndexMap<String, Vec<String>> {
        self.scripts.clone()
    }

    fn set_repositories(&mut self, repositories: Vec<IndexMap<String, PhpMixed>>) {
        self.repositories = repositories;
    }

    fn get_repositories(&self) -> Vec<IndexMap<String, PhpMixed>> {
        self.repositories.clone()
    }

    fn set_license(&mut self, license: Vec<String>) {
        self.license = license;
    }

    fn get_license(&self) -> Vec<String> {
        self.license.clone()
    }

    fn set_keywords(&mut self, keywords: Vec<String>) {
        self.keywords = keywords;
    }

    fn get_keywords(&self) -> Vec<String> {
        self.keywords.clone()
    }

    fn set_authors(&mut self, authors: Vec<IndexMap<String, String>>) {
        self.authors = authors;
    }

    fn get_authors(&self) -> Vec<IndexMap<String, String>> {
        self.authors.clone()
    }

    fn set_description(&mut self, description: String) {
        self.description = Some(description);
    }

    fn get_description(&self) -> Option<&str> {
        self.description.as_deref()
    }

    fn set_homepage(&mut self, homepage: String) {
        self.homepage = Some(homepage);
    }

    fn get_homepage(&self) -> Option<&str> {
        self.homepage.as_deref()
    }

    fn set_support(&mut self, support: IndexMap<String, String>) {
        self.support = support;
    }

    fn get_support(&self) -> IndexMap<String, String> {
        self.support.clone()
    }

    fn set_funding(&mut self, funding: Vec<IndexMap<String, PhpMixed>>) {
        self.funding = funding;
    }

    fn get_funding(&self) -> Vec<IndexMap<String, PhpMixed>> {
        self.funding.clone()
    }

    fn is_abandoned(&self) -> bool {
        match &self.abandoned {
            PhpMixed::Bool(b) => *b,
            PhpMixed::String(s) => !s.is_empty(),
            _ => false,
        }
    }

    fn set_abandoned(&mut self, abandoned: PhpMixed) {
        self.abandoned = abandoned;
    }

    fn get_replacement_package(&self) -> Option<&str> {
        match &self.abandoned {
            PhpMixed::String(s) => Some(s.as_str()),
            _ => None,
        }
    }

    fn set_archive_name(&mut self, name: String) {
        self.archive_name = Some(name);
    }

    fn get_archive_name(&self) -> Option<&str> {
        self.archive_name.as_deref()
    }

    fn set_archive_excludes(&mut self, excludes: Vec<String>) {
        self.archive_excludes = excludes;
    }

    fn get_archive_excludes(&self) -> Vec<String> {
        self.archive_excludes.clone()
    }
}