tweak uuid generators - use last N digits instead of first N
authorTom Clegg <tom@clinicalfuture.com>
Wed, 16 Jan 2013 21:19:56 +0000 (13:19 -0800)
committerTom Clegg <tom@clinicalfuture.com>
Wed, 16 Jan 2013 21:19:56 +0000 (13:19 -0800)
config/application.rb
config/environments/development.rb
config/environments/production.rb
config/environments/test.rb
lib/assign_uuid.rb

index 96e0cde90a67dba34101af5b7c794758651d705a..c5cc10cc04a58f8ccb0d5dc2de068c5025972771 100644 (file)
@@ -50,7 +50,15 @@ module Server
 
     config.force_ssl = true
 
-    config.uuid_prefix = Digest::MD5.hexdigest('CHANGE-ME').to_i(16).to_s(36)[0..4]
+    def config.uuid_prefix(x=nil)
+      if x and @uuid_prefix
+        raise "uuid_prefix was already set to #{@uuid_prefix}"
+      end
+      @uuid_prefix ||= Digest::MD5.hexdigest(x || `hostname`.strip).to_i(16).to_s(36)[-5..-1]
+    end
+    def config.uuid_prefix=(x)
+      @uuid_prefix = x
+    end
   end
 
 end
index 1f469176293f12083e58dfbaf4d086c6fdfe6566..39f7d2935d2bd70afaff9d209a8ee689bc6670eb 100644 (file)
@@ -36,4 +36,6 @@ Server::Application.configure do
 
   # config.compute_node_nameservers = ['1.2.3.4', '1.2.3.5']
   config.compute_node_nameservers = ['192.168.201.3']
+
+  config.uuid_prefix('development@' + `hostname`.strip)
 end
index 4d47ba42070fa177cf869c2c68e9579585989acc..755383103ec39bc8c64409effeaf196e3eaff27c 100644 (file)
@@ -67,4 +67,6 @@ Server::Application.configure do
   config.compute_node_nameservers = ['local', 'public'].collect do |iface|
     Net::HTTP.get(URI("http://169.254.169.254/latest/meta-data/#{iface}-ipv4")).match(/^[\d\.]+$/)[0]
   end << '172.16.0.23'
+
+  config.uuid_prefix = Digest::MD5.hexdigest('cfi-aws-0').to_i(16).to_s(36)[0..4] # '9ujm1'
 end
index 3b1ca5c6fddb60968a4ea331e23b4b063a230371..ca6c44f45cd315c159fb44cc1c0636766f1e102b 100644 (file)
@@ -46,4 +46,6 @@ Server::Application.configure do
   config.compute_node_nameservers = ['local', 'public'].collect do |iface|
     Net::HTTP.get(URI("http://169.254.169.254/latest/meta-data/#{iface}-ipv4")).match(/^[\d\.]+$/)[0]
   end << '172.16.0.23'
+
+  config.uuid_prefix('test@' + `hostname`.strip)
 end
index b470d8ee1cc7c738c7a6f977e86ba90e273daa25..6d8bd294f2c59b8158f64c1c5b01fe106320cb2f 100644 (file)
@@ -9,7 +9,7 @@ module AssignUuid
 
   module ClassMethods
     def uuid_prefix
-      Digest::MD5.hexdigest(self.to_s).to_i(16).to_s(36)[0..4]
+      Digest::MD5.hexdigest(self.to_s).to_i(16).to_s(36)[-5..-1]
     end
   end
 
@@ -23,7 +23,7 @@ module AssignUuid
     return true if !self.respond_to_uuid?
     self.uuid ||= [Server::Application.config.uuid_prefix,
                    self.class.uuid_prefix,
-                   rand(2**256).to_s(36)[0..14]].
+                   rand(2**256).to_s(36)[-15..-1]].
       join '-'
   end
 end