primary_key-uuid-rails 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 225f0048db914c1d5a01a9543e9e8451591c5afd
4
- data.tar.gz: b0fba460105d61ff80a804eb3066bc9b2d7cc2b8
3
+ metadata.gz: 4ff7972cb1d8155cfdf0f80af1de8abaec05b11b
4
+ data.tar.gz: 45af93254cfcc33b02aabee44d3b861ef15b977e
5
5
  SHA512:
6
- metadata.gz: 00ccadfd5764f1185236152993c85c5dacc7daa571da0247590e20c9183503a7609375cf115d9daef15a244e997e0d33070529bd4329880f5b3c9d2fb5b18d0b
7
- data.tar.gz: e3994ec432c8b311176836631737588f62e6f33c85afe9d9fb6ca0f7c4d1bfbb97d1c2588e92a98d38b2746a2ca0e6b6ee440f02755a455c6934c759f0979e9d
6
+ metadata.gz: ca0a2d53d7d1fefe8223edb0e0db1c9bc46f2533388f894123bd7325239cc5f59d3ea40b8eac8620434e04eda714b9016708fba47574cab8c175e011df0ff8fd
7
+ data.tar.gz: cc32ce24285fedcfc3182655c0e31d926ebdf4804841e06c36553805ab3883d8f37282e2bb6063c492fb7a0e4f64aff2bd526fcff58c10cd776398c46852ad47
@@ -6,6 +6,14 @@ module PrimaryKey
6
6
  require "primary_key/uuid/rails/patch"
7
7
  end
8
8
  end
9
+ def self.generate
10
+ namespace (DateTime.now.to_i*1000000 + DateTime.now.usec)
11
+ end
12
+ def self.namespace identifier
13
+ @uuid_namespace ||= UUIDTools::UUID.parse "f90fe61d-1778-08a4-308a-3beaa8d3c44c"
14
+ @application_namespace ||= UUIDTools::UUID.sha1_create(@uuid_namespace,::Rails.application.class.parent_name)
15
+ UUIDTools::UUID.sha1_create(@application_namespace,identifier.to_s)
16
+ end
9
17
  end
10
18
  end
11
19
  end
@@ -1,13 +1,13 @@
1
1
  require "uuidtools"
2
2
 
3
3
  class ActiveRecord::Base
4
- before_save :set_primary_key_uuid
4
+ after_initialize :set_primary_key_uuid
5
5
  private
6
6
  def set_primary_key_uuid
7
7
  return unless self.class.primary_key
8
8
  pk = self.class.primary_key
9
9
  return unless self.class.columns_hash[pk].sql_type == "uuid"
10
- id = ::UUIDTools::UUID.random_create
10
+ id = ::PrimaryKey::Uuid::Rails.generate
11
11
  puts self.send(pk)
12
12
  return unless self.send(pk).nil?
13
13
  puts "Set id to #{id}"
@@ -1,7 +1,7 @@
1
1
  module PrimaryKey
2
2
  module Uuid
3
3
  module Rails
4
- VERSION = "0.0.5"
4
+ VERSION = "0.0.6"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: primary_key-uuid-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mathias Kaufmann