Commit 66e4468

mo <mo@mokhan.ca>
2018-10-13 17:28:20
extract constant for URI regex
1 parent 97df325
Changed files (2)
app/models/application_record.rb
@@ -2,6 +2,8 @@
 
 class ApplicationRecord < ActiveRecord::Base
   UUID = /\A\h{8}-\h{4}-\h{4}-\h{4}-\h{12}\z/
+  URI_REGEX = /\A#{URI.regexp(%w[http https])}\z/
+
   include Flippable
   self.abstract_class = true
 end
app/models/client.rb
@@ -7,8 +7,8 @@ class Client < ApplicationRecord
   has_many :authorizations
 
   validates :name, presence: true
-  validates :redirect_uri, presence: true, format: { with: /\A#{URI.regexp(%w[http https])}\z/ }
-  validates :uuid, presence: true, format: { with: ApplicationRecord::UUID }
+  validates :redirect_uri, presence: true, format: { with: URI_REGEX }
+  validates :uuid, presence: true, format: { with: UUID }
 
   after_initialize do
     self.uuid = SecureRandom.uuid unless uuid