uuidable 0.0.1 → 0.0.2

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Y2JlMDY1NzVjMWM4YTkwYzdhMWNjMjk0N2E5ZTVlMWZiNGQ2NTVlMA==
4
+ MzY0NDY3Y2Q4NDNjNWI4MTA0OTA3NTFiYWVlNWQxY2E2NzlhMWNkYg==
5
5
  data.tar.gz: !binary |-
6
- ZWQ3MGIxNmZiNDA4YWQxNDIxMmRmOWZjYmRiNDg4ZGFkM2U5Y2QyYw==
6
+ MzFkYmQwOWE2YmZjN2VlNmJlNGI5NWI2MjYyYzBjNTNjNDc1YmZhNg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MWFjOTQ0ZDhkZjc1YWI0NGFhYTg1YzM5MGVkNWQxMzVkNzYwZjhmNWEwMTlk
10
- YWRhZGE5NjAwZjcxMjYxMmUyZWE1NDAyNjUwZjgxMjkyMzdiYjllZTNhYjg4
11
- MjJmZDkyMTc4YTY5MjgxMzc2NjY0NGJjZDVjNjllY2Y1NGY1YmI=
9
+ Yjg5NGU5ZjkzMTg3NGVlZGVjMDg3MzM4YzE4ZGVjMTA5NGYyM2U1NWFjZDZm
10
+ ZDlmY2YxMzIxYWZkNGQxZjQ0ZjBiNTgxMGRmOGI1NWMxZjZjOGE4OWI4NGZl
11
+ ZWZjY2Y4NTQ1ODBlZTdiOTI5ZTc1NTYzYTI5OWZlNzg5Zjk1ODM=
12
12
  data.tar.gz: !binary |-
13
- ZWZjM2JhZDFmYmIzYjdkMjI4YzY4ZTU0OGFmNDI3MTE0Mjk4NjFlMzRiYzkx
14
- NTA1ZmE5NWY1Mzc3Y2UxMzk4MDM1ZWI3NTEzN2Q2ZjkyY2UwODQ3MWNkOWQy
15
- YzljMzRkYWU5NzEwNTU1NDMzMTMyMzRhOWMyOGIyMDJiYzUwNTM=
13
+ OTcwMzgwMjdlZGZhNGYxN2JhZmZhODdjYzJiNDFhZDkwNjk3M2Y5ZWJjYmNi
14
+ ZjY0Yzk3ZGUxZTA2YWQ1MWFmMzMwZjUyZmEyNjVlZmU4OTBiOTFmM2FhMmE3
15
+ ZWRhOWE3YTdlNTMzMTc5YmZkY2MyYzhkYWRjM2MxNGRkZTVjNWQ=
data/README.md CHANGED
@@ -30,6 +30,20 @@ class Project < ActiveRecord::Base
30
30
  end
31
31
  ```
32
32
 
33
+ You can use special methods in migrations:
34
+ ```ruby
35
+ class CreateProjects < ActiveRecord::Migration
36
+ def change
37
+ create_table :projects do |t|
38
+ t.uuid
39
+ #...
40
+ end
41
+ # Or
42
+ add_uuid_column :projects
43
+ end
44
+ end
45
+ ```
46
+
33
47
  ## Development
34
48
 
35
49
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -0,0 +1,34 @@
1
+ module Uuidable
2
+ # ActiveRecord mixin
3
+ module ActiveRecord
4
+ extend ActiveSupport::Concern
5
+
6
+ class UuidChangeError < Exception; end
7
+
8
+ # ClassMethods
9
+ module ClassMethods
10
+ def uuidable
11
+ after_initialize { self.uuid = Uuidable.generate_uuid if uuid.blank? }
12
+ validates :uuid, presence: true, uniqueness: true
13
+
14
+ define_method :to_param do
15
+ uuid
16
+ end
17
+
18
+ define_method :uuid= do |val|
19
+ raise UuidChangeError, 'Uuid changing is bad idea!' unless new_record? || uuid.blank? || uuid == val
20
+
21
+ super(val)
22
+ end
23
+ end
24
+ end
25
+
26
+ def short_uuid
27
+ UUIDTools::UUID.parse(uuid).hexdigest
28
+ end
29
+ end
30
+ end
31
+
32
+ ActiveSupport.on_load(:active_record) do
33
+ ActiveRecord::Base.send(:include, Uuidable::ActiveRecord)
34
+ end
@@ -1,3 +1,3 @@
1
1
  module Uuidable
2
- VERSION = '0.0.1'.freeze
2
+ VERSION = '0.0.2'.freeze
3
3
  end
data/lib/uuidable.rb CHANGED
@@ -1,41 +1,14 @@
1
1
  require 'uuidable/version'
2
- require 'uuidable/migration'
3
-
4
2
  require 'active_support'
5
3
 
6
4
  # Main module
7
5
  module Uuidable
8
- extend ActiveSupport::Concern
9
-
10
- class UuidChangeError < Exception; end
11
-
12
- # ClassMethods
13
- module ClassMethods
14
- def uuidable
15
- after_initialize { self.uuid = self.class.generate_uuid if uuid.blank? }
16
- validates :uuid, presence: true, uniqueness: true
17
-
18
- define_method :to_param do
19
- uuid
20
- end
21
-
22
- define_method :uuid= do |val|
23
- raise UuidChangeError, 'Uuid changing is bad idea!' unless new_record? || uuid.blank? || uuid == val
6
+ module_function
24
7
 
25
- super(val)
26
- end
27
- end
28
- end
29
-
30
- def short_uuid
31
- UUIDTools::UUID.parse(uuid).hexdigest
32
- end
33
-
34
- def self.generate_uuid
8
+ def generate_uuid
35
9
  SecureRandom.uuid
36
10
  end
37
11
  end
38
12
 
39
- ActiveSupport.on_load(:active_record) do
40
- ActiveRecord::Base.send(:include, Uuidable)
41
- end
13
+ require 'uuidable/migration'
14
+ require 'uuidable/active_record'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uuidable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Gnuskov
@@ -111,6 +111,7 @@ files:
111
111
  - bin/console
112
112
  - bin/setup
113
113
  - lib/uuidable.rb
114
+ - lib/uuidable/active_record.rb
114
115
  - lib/uuidable/migration.rb
115
116
  - lib/uuidable/version.rb
116
117
  - uuidable.gemspec