Skip to content

Instantly share code, notes, and snippets.

@mdeniz
Forked from hennevogel/omg.rb
Last active November 25, 2015 16:54
Show Gist options
  • Save mdeniz/e1e127dcdad969a2e8d5 to your computer and use it in GitHub Desktop.
Save mdeniz/e1e127dcdad969a2e8d5 to your computer and use it in GitHub Desktop.
def get_build_flags(flag_type)
the_flags = {}
all_repositories = [nil].concat(main_object.repositories.map{|repo| repo.name})
all_architecture = [nil].concat(main_object.architectures)
all_repositories.each do |repository|
the_flags[repository] = []
all_architectures.each do |architecture|
architecture_id = architecture ? architecture.id : nil
flag = main_object.flags.with_repositories(repository).with_architectures(architecture_id).first
unless flag
status = (repository.nil? && architecture.nil?) ? Flag.default_state('build') : the_flags[nil].first.status
flag = main_object.flags.new( flag: flag_type, repo: repository, architecture: architecture, status: status )
end
the_flags[repository] << flag
end
end
the_flags['all'] = the_flags.delete(nil)
the_flags
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment