Class: Environments::EnvironmentsByDeploymentsFinder
- Inherits:
-
Object
- Object
- Environments::EnvironmentsByDeploymentsFinder
- Defined in:
- app/finders/environments/environments_by_deployments_finder.rb
Instance Attribute Summary collapse
-
#current_user ⇒ Object
readonly
Returns the value of attribute current_user.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
Instance Method Summary collapse
-
#execute ⇒ Object
rubocop: disable CodeReuse/ActiveRecord.
-
#initialize(project, current_user, params = {}) ⇒ EnvironmentsByDeploymentsFinder
constructor
A new instance of EnvironmentsByDeploymentsFinder.
Constructor Details
#initialize(project, current_user, params = {}) ⇒ EnvironmentsByDeploymentsFinder
Returns a new instance of EnvironmentsByDeploymentsFinder.
7 8 9 10 11 |
# File 'app/finders/environments/environments_by_deployments_finder.rb', line 7 def initialize(project, current_user, params = {}) @project = project @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/finders/environments/environments_by_deployments_finder.rb', line 5 def current_user @current_user end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
5 6 7 |
# File 'app/finders/environments/environments_by_deployments_finder.rb', line 5 def params @params end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
5 6 7 |
# File 'app/finders/environments/environments_by_deployments_finder.rb', line 5 def project @project end |
Instance Method Details
#execute ⇒ Object
rubocop: disable CodeReuse/ActiveRecord
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/finders/environments/environments_by_deployments_finder.rb', line 14 def execute deployments = if ref Deployment.where(ref: ref.to_s) elsif sha Deployment.where(sha: sha) else Deployment.none end environments = project.environments.available .where('EXISTS (?)', deployments.where('environment_id = environments.id')) if params[:find_latest] find_one(environments.order_by_last_deployed_at_desc) else find_all(environments.order_by_last_deployed_at.to_a) end end |