Class: Deployments::CreateService
- Inherits:
-
Object
- Object
- Deployments::CreateService
- Defined in:
- app/services/deployments/create_service.rb
Instance Attribute Summary collapse
-
#current_user ⇒ Object
readonly
Returns the value of attribute current_user.
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
- #deployment_attributes ⇒ Object
- #execute ⇒ Object
-
#initialize(environment, current_user, params) ⇒ CreateService
constructor
A new instance of CreateService.
Constructor Details
#initialize(environment, current_user, params) ⇒ CreateService
Returns a new instance of CreateService.
7 8 9 10 11 |
# File 'app/services/deployments/create_service.rb', line 7 def initialize(environment, current_user, params) @environment = environment @current_user = current_user @params = params end |
Instance Attribute Details
#current_user ⇒ Object (readonly)
Returns the value of attribute current_user.
5 6 7 |
# File 'app/services/deployments/create_service.rb', line 5 def current_user @current_user end |
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
5 6 7 |
# File 'app/services/deployments/create_service.rb', line 5 def environment @environment end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
5 6 7 |
# File 'app/services/deployments/create_service.rb', line 5 def params @params end |
Instance Method Details
#deployment_attributes ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/services/deployments/create_service.rb', line 27 def deployment_attributes # We use explicit parameters here so we never by accident allow parameters # to be set that one should not be able to set (e.g. the row ID). { project_id: environment.project_id, environment_id: environment.id, ref: params[:ref], tag: params[:tag], sha: params[:sha], user: current_user, on_stop: params[:on_stop] } end |
#execute ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/services/deployments/create_service.rb', line 13 def execute return last_deployment if last_deployment&.equal_to?(params) environment.deployments.build(deployment_attributes).tap do |deployment| # Deployment#change_status already saves the model, so we only need to # call #save ourselves if no status is provided. if (status = params[:status]) deployment.update_status(status) else deployment.save end end end |