@@ -5,7 +5,7 @@ pub struct DockerClient {}
5
5
impl DockerClient {
6
6
pub fn build_image (
7
7
ruby_version : & str ,
8
- rails_version : & str ,
8
+ maybe_rails_version : Option < & str > ,
9
9
user_id : Option < u32 > ,
10
10
group_id : Option < u32 > ,
11
11
rebuild : bool ,
@@ -19,7 +19,9 @@ impl DockerClient {
19
19
}
20
20
21
21
Self :: set_build_arg ( & mut command, "RUBY_VERSION" , ruby_version) ;
22
- Self :: set_build_arg ( & mut command, "RAILS_VERSION" , rails_version) ;
22
+ if let Some ( rails_version) = maybe_rails_version {
23
+ Self :: set_build_arg ( & mut command, "RAILS_VERSION" , rails_version) ;
24
+ }
23
25
24
26
if let Some ( id) = user_id {
25
27
Self :: set_build_arg ( & mut command, "USER_ID" , & id. to_string ( ) )
@@ -30,14 +32,18 @@ impl DockerClient {
30
32
31
33
command. arg ( "-t" ) ;
32
34
33
- Self :: set_image_name ( & mut command, ruby_version, rails_version ) ;
35
+ Self :: set_image_name ( & mut command, ruby_version, maybe_rails_version ) ;
34
36
35
37
command. arg ( "-" ) . stdin ( Stdio :: piped ( ) ) ;
36
38
37
39
command
38
40
}
39
41
40
- pub fn run_image ( ruby_version : & str , rails_version : & str , args : Vec < String > ) -> Command {
42
+ pub fn run_image (
43
+ ruby_version : & str ,
44
+ rails_version : Option < & str > ,
45
+ args : Vec < String > ,
46
+ ) -> Command {
41
47
let mut command = Self :: run ( ) ;
42
48
43
49
Self :: set_workdir ( & mut command) ;
@@ -47,7 +53,7 @@ impl DockerClient {
47
53
command
48
54
}
49
55
50
- pub fn get_help ( ruby_version : & str , rails_version : & str ) -> Command {
56
+ pub fn get_help ( ruby_version : & str , rails_version : Option < & str > ) -> Command {
51
57
let mut command = Self :: run ( ) ;
52
58
53
59
Self :: set_image_name ( & mut command, ruby_version, rails_version) ;
@@ -81,8 +87,16 @@ impl DockerClient {
81
87
. args ( [ "-w" , current_dir] ) ;
82
88
}
83
89
84
- fn set_image_name ( command : & mut Command , ruby_version : & str , rails_version : & str ) {
85
- command. arg ( format ! ( "rails-new-{}-{}" , ruby_version, rails_version) ) ;
90
+ fn set_image_name (
91
+ command : & mut Command ,
92
+ ruby_version : & str ,
93
+ maybe_rails_version : Option < & str > ,
94
+ ) {
95
+ if let Some ( rails_version) = maybe_rails_version {
96
+ command. arg ( format ! ( "rails-new-{}-{}" , ruby_version, rails_version) ) ;
97
+ } else {
98
+ command. arg ( format ! ( "rails-new-{}" , ruby_version) ) ;
99
+ }
86
100
}
87
101
88
102
fn set_rails_new ( command : & mut Command , args : Vec < String > ) {
@@ -121,7 +135,7 @@ mod tests {
121
135
122
136
#[ test]
123
137
fn build_image ( ) {
124
- let command = DockerClient :: build_image ( "3.2.3" , "7.1.3" , None , None , false ) ;
138
+ let command = DockerClient :: build_image ( "3.2.3" , Some ( "7.1.3" ) , None , None , false ) ;
125
139
126
140
assert_eq ! ( command. get_program( ) , "docker" ) ;
127
141
@@ -144,7 +158,7 @@ mod tests {
144
158
145
159
#[ test]
146
160
fn build_image_with_user_id ( ) {
147
- let command = DockerClient :: build_image ( "3.2.3" , "7.1.3" , Some ( 1000 ) , None , false ) ;
161
+ let command = DockerClient :: build_image ( "3.2.3" , Some ( "7.1.3" ) , Some ( 1000 ) , None , false ) ;
148
162
149
163
assert_eq ! ( command. get_program( ) , "docker" ) ;
150
164
@@ -169,7 +183,7 @@ mod tests {
169
183
170
184
#[ test]
171
185
fn build_image_with_group_id ( ) {
172
- let command = DockerClient :: build_image ( "3.2.3" , "7.1.3" , None , Some ( 1000 ) , false ) ;
186
+ let command = DockerClient :: build_image ( "3.2.3" , Some ( "7.1.3" ) , None , Some ( 1000 ) , false ) ;
173
187
174
188
assert_eq ! ( command. get_program( ) , "docker" ) ;
175
189
@@ -194,7 +208,7 @@ mod tests {
194
208
195
209
#[ test]
196
210
fn run_image ( ) {
197
- let command = DockerClient :: run_image ( "3.2.3" , "7.1.3" , vec ! [ "my_app" . to_string( ) ] ) ;
211
+ let command = DockerClient :: run_image ( "3.2.3" , Some ( "7.1.3" ) , vec ! [ "my_app" . to_string( ) ] ) ;
198
212
199
213
assert_eq ! ( command. get_program( ) , "docker" ) ;
200
214
@@ -223,7 +237,7 @@ mod tests {
223
237
224
238
#[ test]
225
239
fn get_help ( ) {
226
- let command = DockerClient :: get_help ( "3.2.3" , "7.1.3" ) ;
240
+ let command = DockerClient :: get_help ( "3.2.3" , Some ( "7.1.3" ) ) ;
227
241
228
242
assert_eq ! ( command. get_program( ) , "docker" ) ;
229
243
0 commit comments