has_secure_uuid 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bbf5ec6244c537e9bbc2fcf9354d60b6e3f8682c8925c4b58eced5082951c5dd
4
- data.tar.gz: 7cc9b0b833ec9fdba4172054e3834ccd1a29ed42d10b90add8194bae13d89205
3
+ metadata.gz: 25f9924b4ac24f32e7bcdc90b1bc134e4a64a4e96da4e69a2542eab953b2c13d
4
+ data.tar.gz: 06556e7c8b76a7bb3e84ed28758b3006ab67c1a7c6a279eb1a4bc1e3a0b9b749
5
5
  SHA512:
6
- metadata.gz: 9e4416d7f7f2eb7e5cb73bc54269deffba876475e307291082b3025dcddfdc10ee5b85fce1c182e6a27520f2e5718e80fdd8fc2abbfc9eb130be3f4b75e39723
7
- data.tar.gz: 1be6c18712a3e3c4816f01112d4ad6a2fc371b90dfaddc4c1b24c153de92b1479da5bd672920bdb20d870107c10ec9faeda21acc76e3117ec43eaab415e686c0
6
+ metadata.gz: 4df32ff48ecffb0481019b46119f87965ebc343407e696fd3438c788b443f0e0ef38ef7b2a57785f31f50a995c873c7554e24d448496f72705b3c8b2e1aeda09
7
+ data.tar.gz: c41afe2e74f6bfd06d235d00698ad02fc30f18ed514d37584cc5cd0061dd8bf738f7682d23b501dbdfa89f64a02aedf5b3ec4e719bb3d367628a38ee358febc4
data/README.md CHANGED
@@ -20,41 +20,41 @@ Or install it yourself as:
20
20
 
21
21
  ## Setting your Model
22
22
 
23
- The first step is to generate a migration in order to add the token key field.
23
+ The first step is to generate a migration in order to add the uuid key field.
24
24
 
25
25
  ```ruby
26
- rails g migration AddidentifierToUsers identifier:string
26
+ rails g migration AddidentifierToUsers uuid:string
27
27
  =>
28
28
  invoke active_record
29
- create db/migrate/20150424010931_add_identifier_to_users.rb
29
+ create db/migrate/20150424010931_add_uuid_to_users.rb
30
30
  ```
31
31
 
32
32
  Then run `rake db:migrate` in order to update users table in the database. The next step is to add `has_secure_uuid`
33
33
  to the model:
34
34
  ```ruby
35
- # Schema: User(identifier:string, uuid:string)
35
+ # Schema: User(uuid:string, identifier:string)
36
36
  class User < ActiveRecord::Base
37
37
  has_secure_uuid
38
38
  end
39
39
 
40
40
  user = User.new
41
41
  user.save
42
- user.identifier # => "6c3d256c-aaa7-443a-a16b-75a99ecde277"
43
- user.regenerate_identifier # => true
42
+ user.uuid # => "6c3d256c-aaa7-443a-a16b-75a99ecde277"
43
+ user.regenerate_uuid # => true
44
44
  ```
45
45
 
46
- To use a custom column to store the uuid field you can specify the column_name option. See example above (e.g: uuid):
46
+ To use a custom column to store the uuid field you can specify the column_name option. See example above (e.g: identifier):
47
47
 
48
48
  ```ruby
49
- # Schema: User(identifier:string, uuid:string)
49
+ # Schema: User(uuid:string, identifier:string)
50
50
  class User < ActiveRecord::Base
51
- has_secure_uuid :uuid
51
+ has_secure_uuid :identifier
52
52
  end
53
53
 
54
54
  user = User.new
55
55
  user.save
56
- user.uuid # => "6c3d256c-aaa7-443a-a16b-75a99ecde277"
57
- user.regenerate_uuid # => true
56
+ user.identifier # => "6c3d256c-aaa7-443a-a16b-75a99ecde277"
57
+ user.regenerate_identifier # => true
58
58
  ```
59
59
 
60
60
  ## Running tests
@@ -78,3 +78,6 @@ Should return
78
78
  3. Commit your changes (`git commit -am 'Add some feature'`)
79
79
  4. Push to the branch (`git push origin my-new-feature`)
80
80
  5. Create a new Pull Request
81
+
82
+
83
+ Modified from: https://github.com/robertomiranda/has_secure_token
@@ -9,24 +9,23 @@ module ActiveRecord
9
9
  module ClassMethods
10
10
  # Example using has_secure_uuid
11
11
  #
12
- # # Schema: User(identifier:string, uuid:string)
12
+ # # Schema: User(identifier:string, identifier:string)
13
13
  # class User < ActiveRecord::Base
14
14
  # has_secure_uuid
15
- # has_secure_uuid :uuid
15
+ # has_secure_uuid :identifier
16
16
  # end
17
17
  #
18
18
  # user = User.new
19
19
  # user.save
20
- # user.identifier # => "93712506-fe9e-4ae9-a713-53c67cd9bccc"
21
20
  # user.uuid # => "245f9ae1-9f8d-4a0e-817d-8ba3e4d663c1"
21
+ # user.identifier # => "93712506-fe9e-4ae9-a713-53c67cd9bccc"
22
22
  # user.regenerate_identifier # => true
23
23
  # user.regenerate_uuid # => true
24
24
  #
25
25
  # Note that it's still possible to generate a race condition in the database in the same way that
26
26
  # <tt>validates_uniqueness_of</tt> can. You're encouraged to add a unique index in the database to deal
27
27
  # with this even more unlikely scenario.
28
- def has_secure_uuid(attribute = :identifier)
29
- # Load securerandom only when has_secure_token is used.
28
+ def has_secure_uuid(attribute = :uuid)
30
29
  define_method("regenerate_#{attribute}") do
31
30
  update_attributes attribute => self.class.generate_unique_uuid
32
31
  end
@@ -1,3 +1,3 @@
1
1
  module HasSecureUuid
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
@@ -1,4 +1,4 @@
1
1
  class User < ActiveRecord::Base
2
2
  has_secure_uuid
3
- has_secure_uuid :uuid
3
+ has_secure_uuid :identifier
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_secure_uuid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sander Tuin