Skip to content

Commit

Permalink
[frontend] Update staging project initializer
Browse files Browse the repository at this point in the history
Changes the initializer to accept hashed values instead of an ordered
parameter list.
This also allows us to use the ActiveModel initializer instead of a
self written one.
  • Loading branch information
bgeuken committed Jun 26, 2018
1 parent 1ea5aeb commit 069056a
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/api/app/models/obs_factory/staging_project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,14 @@ class StagingProject
NAME_PREFIX = ":Staging:"
ADI_NAME_PREFIX = ":Staging:adi:"

def initialize(project, distribution)
self.project = project
self.distribution = distribution
end

# Find all staging projects for a given distribution
#
# @param [Boolean] only_letter only letter stagings, otherwise all stagings
# @return [Array] array of StagingProject objects
def self.for(distribution, only_letter=true)
wildcard = only_letter ? "_" : "%"
::Project.where(["name like ?", "#{distribution.root_project_name}#{NAME_PREFIX}#{wildcard}"]).map { |p| StagingProject.new(p, distribution) }
::Project.where(["name like ?", "#{distribution.root_project_name}#{NAME_PREFIX}#{wildcard}"]).
map { |project| StagingProject.new(project: project, distribution: distribution) }
end

# Find a staging project by distribution and id
Expand All @@ -34,7 +30,7 @@ def self.for(distribution, only_letter=true)
def self.find(distribution, id)
project = ::Project.find_by_name("#{distribution.root_project_name}#{NAME_PREFIX}#{id}")
if project
StagingProject.new(project, distribution)
StagingProject.new(project: project, distribution: distribution)
else
nil
end
Expand Down Expand Up @@ -108,8 +104,8 @@ def obsolete_requests
def subproject
return @subprojects[0] unless @subprojects.nil?
@subprojects = []
::Project.where(["name like ?", "#{name}:%"]).map do |p|
p = StagingProject.new(p, distribution)
::Project.where(["name like ?", "#{name}:%"]).map do |project|
p = StagingProject.new(project: project, distribution: distribution)
p.parent = self
@subprojects << p
end
Expand Down

0 comments on commit 069056a

Please sign in to comment.