aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin H. Johnson <robbat2@gentoo.org>2017-05-16 09:23:06 -0700
committerRobin H. Johnson <robbat2@gentoo.org>2017-05-16 09:23:06 -0700
commit1afd560d60ea63093de851acc6daeb2723a34fef (patch)
tree2bbef3ee5c88b569d0bb7cce44fb805fe98fc942
parentAdd slot support to GLSAMaker (diff)
downloadglsamaker-1afd560d60ea63093de851acc6daeb2723a34fef.tar.gz
glsamaker-1afd560d60ea63093de851acc6daeb2723a34fef.tar.bz2
glsamaker-1afd560d60ea63093de851acc6daeb2723a34fef.zip
packages: refactor validations.
Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
-rw-r--r--app/models/package.rb12
1 files changed, 10 insertions, 2 deletions
diff --git a/app/models/package.rb b/app/models/package.rb
index b3eb189..8f2547d 100644
--- a/app/models/package.rb
+++ b/app/models/package.rb
@@ -1,6 +1,7 @@
# ===GLSAMaker v2
# Copyright (C) 2009-2011 Alex Legler <a3li@gentoo.org>
# Copyright (C) 2009 Pierre-Yves Rofes <py@gentoo.org>
+# Copyright (C) 2017 Robin H. Johnson <robbat2@gentoo.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
@@ -12,8 +13,8 @@
# Package model
class Package < ActiveRecord::Base
belongs_to :revision
- validates :comp, :inclusion => { :in => %w[>= > = <= < *< *<= *> *>=] }
- validates :arch, :format => { :with => /\A(\*|((alpha|amd64|arm|hppa|ia64|m68k|mips|ppc|ppc64|s390|sh|sparc|x86) )*(alpha|amd64|arm|hppa|ia64|m68k|mips|ppc|ppc64|s390|sh|sparc|x86))\z/ }
+ validates :comp, :inclusion => { :in => COMP_MAP.keys }
+ validates :arch, :format => { :with => /\A(\*|(#{ARCHLIST_REGEX} )*#{ARCHLIST_REGEX})\z/ }
# Mapping XML comparators to internally used ones
COMP_MAP = {
@@ -28,6 +29,13 @@ class Package < ActiveRecord::Base
'*>=' => 'rge'
}.freeze
+ # Arches (from $PORTDIR/profiles/arch.list)
+ ARCHLIST_BASE = %w{alpha amd64 arm arm64 hppa ia64 m68k mips nios2 ppc ppc64 riscv s390 sh sparc x86}.freeze
+ ARCHLIST_FBSD = %w{amd64-fbsd sparc-fbsd x86-fbsd}.freeze
+ ARCHLIST_PREFIX = %w{ppc-aix amd64-linux arm-linux arm64-linux ppc64-linux x86-linux ppc-macos x86-macos x64-macos m68k-mint sparc-solaris sparc64-solaris x64-solaris x86-solaris x86-winnt x64-cygwin x86-cygwin}.freeze
+ ARCHLIST = (ARCHLIST_BASE+ARCHLIST_FBSD+ARCHLIST_PREFIX).freeze
+ ARCHLIST_REGEX = %r{(?:#{ARCHLIST.join('|')})}.freeze
+
# Returns the comparator in the format needed for the XML
def xml_comp
COMP_MAP[self.comp]