Skip to content

Commit

Permalink
executors are immutable
Browse files Browse the repository at this point in the history
  • Loading branch information
deecewan committed Jun 24, 2018
1 parent 78120ae commit fc1764c
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 22 deletions.
57 changes: 40 additions & 17 deletions src/executors/docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,55 +16,71 @@ class Image {
this.parent = parent;
}

clone() {
const clone = new this.constructor(this.data.image, this.parent);
clone.data = this.data;
clone.parent = this.parent;

return clone;
}

auth(auth: Auth) {
this.data.auth = auth;
const clone = this.clone();
clone.data.auth = auth;

return this;
return clone;
}

awsAuth(awsAuth: AwsAuth) {
this.data.aws_auth = awsAuth;
const clone = this.clone();
clone.data.aws_auth = awsAuth;

return this;
return clone;
}

command(...command: Array<string>) {
this.data.command = command;
const clone = this.clone();
clone.data.command = command;

return this;
return clone;
}

entrypoint(...entrypoint: Array<string>) {
this.data.entrypoint = entrypoint;
const clone = this.clone();
clone.data.entrypoint = entrypoint;

return this;
return clone;
}

environment(env: { [string]: string }) {
this.data.environment = env;
const clone = this.clone();
clone.data.environment = env;

return this;
return clone;
}

name(name: string) {
this.data.name = name;
const clone = this.clone();
clone.data.name = name;

return this;
return clone;
}

user(user: string) {
this.data.user = user;
const clone = this.clone();
clone.data.user = user;

return this;
return clone;
}

compose() {
return this.data;
}

done() {
this.parent.images.push(this);
return this.parent;
const clone = this.clone();
clone.parent.images.push(clone);
return clone.parent;
}
}

Expand All @@ -77,8 +93,15 @@ export default class Docker implements Executor {
}
}

clone() {
const clone = new this.constructor();
clone.images = [...this.images];
return clone;
}

image(image: string) {
return new Image(image, this);
const clone = this.clone();
return new Image(image, clone);
}

compose(): { docker: Array<ImageData> } {
Expand Down
24 changes: 19 additions & 5 deletions src/executors/machine.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,32 @@ export default class Machine implements Executor {
this.state.enabled = enabled;
}

clone() {
const clone = new this.constructor(this.state.enabled);
clone.state = {
...this.state,
};

return clone;
}

enabled(enabled: boolean) {
this.state.enabled = enabled;
return this;
const clone = this.clone();
clone.state.enabled = enabled;
return clone;
}

image(image: string) {
this.state.image = image;
return this;
const clone = this.clone();
clone.state.image = image;
return clone;
}

dockerLayerCaching(enabled: boolean) {
this.state.docker_layer_caching = enabled;
const clone = this.clone();
clone.state.docker_layer_caching = enabled;

return clone;
}

compose() {
Expand Down

0 comments on commit fc1764c

Please sign in to comment.