ルートファイルの半分以上が制約(およびそのクラス)で占められているため、これにアプローチするためのより良い方法があるかどうか疑問に思っています。他のペットを追加すると、それぞれ同じになります。そのため、ファイルが非常に長くなる可能性があります。
class AkcConstraint
TYPES = %w[sporting-group hound-group working-group terrier-group toy-group non-sporting-group herding-group misc-class]
def self.matches?(request)
TYPES.include? request.path_parameters[:akc_group]
end
end
class AnkcConstraint
TYPES = %w[toy-group terrier-group gundog-group hound-group working-group utility-group non-sporting-group]
def self.matches?(request)
TYPES.include? request.path_parameters[:ankc_group]
end
end
class CkcConstraint
TYPES = %w[sporting-group hound-group working-group terrier-group toy-group non-sporting-group herding-group]
def self.matches?(request)
TYPES.include? request.path_parameters[:ckc_group]
end
end
class FciConstraint
TYPES = %w[group-1 group-2 group-3 group-4 group-5 group-6 group-7 group-8 group-9 group-10]
def self.matches?(request)
TYPES.include? request.path_parameters[:fci_group]
end
end
class IkcConstraint
TYPES = %w[group-1 group-2 group-3 group-4 group-5 group-6 group-7 group-8 group-9 group-10]
def self.matches?(request)
TYPES.include? request.path_parameters[:ikc_group]
end
end
class KcConstraint
TYPES = %w[hound-group working-group gundog-group terrier-group utility-group pastoral-group toy-group]
def self.matches?(request)
TYPES.include? request.path_parameters[:kc_group]
end
end
class KusaConstraint
TYPES = %w[hound-group working-group gundog-group terrier-group utility-group pastoral-group toy-group]
def self.matches?(request)
TYPES.include? request.path_parameters[:kusa_group]
end
end
class NzkcConstraint
TYPES = %w[toy-group terrier-group gundog-group hound-group working-group utility-group non-sporting-group]
def self.matches?(request)
TYPES.include? request.path_parameters[:nzkc_group]
end
end
# For dog groups and types
match 'dogs/akc/:akc_group', :to => "dogs#index", :as => "akc_dogs",
:constraints => AkcConstraint
match 'dogs/ankc/:ankc_group', :to => "dogs#index", :as => "ankc_dogs",
:constraints => AnkcConstraint
match 'dogs/ckc/:ckc_group', :to => "dogs#index", :as => "ckc_dogs",
:constraints => CkcConstraint
match 'dogs/fci/:fci_group', :to => "dogs#index", :as => "fci_dogs",
:constraints => FciConstraint
match 'dogs/ikc/:ikc_group', :to => "dogs#index", :as => "ikc_dogs",
:constraints => IkcConstraint
match 'dogs/kc/:kc_group', :to => "dogs#index", :as => "kc_dogs",
:constraints => KcConstraint
match 'dogs/kusa/:kusa_group', :to => "dogs#index", :as => "kusa_dogs",
:constraints => KusaConstraint
match 'dogs/nzkc/:nzkc_group', :to => "dogs#index", :as => "nzkc_dogs",
:constraints => NzkcConstraint
私は何よりもパフォーマンスに関心があると思います-心配する必要がありますか?もっと良い方法はありますか?