trogdir_models 0.5.2 → 0.6.0

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: d4b7ea581103941e7641eac1f66e83d54b2a451f
4
- data.tar.gz: 1d3f9a0fc88472593254c766d63a904894c8a6f9
3
+ metadata.gz: 0489e683f1f95925dcae757caa701997e97ab6dc
4
+ data.tar.gz: dc62802db6c28ef53c0433166a55678282c33202
5
5
  SHA512:
6
- metadata.gz: e22b3815ba67e36eb0652c4b6a52255a2922f84f18049aaceb3846d4917d4b3a68f8971a209c98d79768ecdb56a28c6ac6d37a5f7b96d5f878c75260d3b8d057
7
- data.tar.gz: 9fc8a64d0c32084e4e94ec971e20e87b7d264576e7dd3fe1cf35af0acdb73d861ca78bd9117e0eded45bc18ddf2e593986787184ed5f65fc87ffb870f480a8a0
6
+ metadata.gz: c174badc157db9867487c84f5f054fe0d4674200ce3b72ee7ce1f67eb19d56c4a5ac534df726e8798b734d0cc35f801458ff7523afaee523605cadfb82a439b2
7
+ data.tar.gz: 7ba6448327742707af1d9897d070f07a63e6e66d077c4f740211dcdaaed4d1c07d79eaa97d4fba9c5737198bdb486cd5b33011198e4461b77b44880e2a7e1fae
@@ -1,3 +1,5 @@
1
+ require 'securerandom'
2
+
1
3
  class Person
2
4
  include Mongoid::Document
3
5
  include Mongoid::History::Trackable
@@ -13,6 +15,9 @@ class Person
13
15
  embeds_many :addresses
14
16
  has_many :changesets, as: :changeable
15
17
 
18
+ # ID
19
+ field :uuid, type: String
20
+
16
21
  # Names
17
22
  field :first_name, type: String
18
23
  field :preferred_name, type: String
@@ -32,14 +37,23 @@ class Person
32
37
  # Options
33
38
  field :enabled, type: Boolean # TODO: figure out if tihs is necessary
34
39
 
35
- validates :first_name, :last_name, presence: true
40
+ validates :uuid, :first_name, :last_name, presence: true
41
+ validates :uuid, uniqueness: true
36
42
  validates :gender, inclusion: { in: Person::GENDERS, allow_nil: true }
37
43
 
38
44
  track_history track_create: true
39
45
 
46
+ before_validation :set_uuid, on: :create
47
+
40
48
  def email
41
49
  emails.where(primary: true).first
42
50
  end
43
51
 
44
52
  delegate :address, to: :email, prefix: true, allow_nil: true
53
+
54
+ private
55
+
56
+ def set_uuid
57
+ self.uuid = SecureRandom.uuid
58
+ end
45
59
  end
@@ -1,3 +1,3 @@
1
1
  module TrogdirModels
2
- VERSION = '0.5.2'
2
+ VERSION = '0.6.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trogdir_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Crownoble
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-31 00:00:00.000000000 Z
11
+ date: 2014-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: api-auth