Class: Environments::EnvironmentsByDeploymentsFinder

Inherits:
Object
  • Object
show all
Defined in:
app/finders/environments/environments_by_deployments_finder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_userObject (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

#paramsObject (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

#projectObject (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

#executeObject

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