uuid_it 0.0.3 → 0.1.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.
- data/README.md +8 -4
- data/lib/generators/uuid_it_generator.rb +19 -0
- data/lib/uuid_it.rb +1 -1
- metadata +3 -2
data/README.md
CHANGED
@@ -14,9 +14,13 @@ based on ruby-uuid (http://raa.ruby-lang.org/project/ruby-uuid/).
|
|
14
14
|
rake db:migrate
|
15
15
|
|
16
16
|
### As a gem
|
17
|
-
|
17
|
+
gem install uuid_it
|
18
18
|
|
19
|
-
|
19
|
+
Add the following line to your config/environment.rb file:
|
20
|
+
|
21
|
+
config.gem "uuid_it"
|
22
|
+
|
23
|
+
Then
|
20
24
|
|
21
25
|
script/generate uuid_it
|
22
26
|
rake db:migrate
|
@@ -29,8 +33,8 @@ based on ruby-uuid (http://raa.ruby-lang.org/project/ruby-uuid/).
|
|
29
33
|
|
30
34
|
@car.uuid # "9e5edacc-7163-11df-92bb-2d0a2c4dcb1c"
|
31
35
|
|
32
|
-
|
33
|
-
first time.
|
36
|
+
UUIDs will be assigned to new objects when they are created. Already existing objects will get a UUID when it is accessed
|
37
|
+
for the first time.
|
34
38
|
|
35
39
|
## Credits
|
36
40
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/migration'
|
3
|
+
|
4
|
+
class UuidItGenerator < Rails::Generators::Base
|
5
|
+
include Rails::Generators::Migration
|
6
|
+
|
7
|
+
def copy_files(*args)
|
8
|
+
migration_template File.join(File.dirname(__FILE__), "..", "..", "generators", "uuid_it", "templates", "create_uuids.rb"),
|
9
|
+
"db/migrate/create_uuids.rb"
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.next_migration_number dirname
|
13
|
+
if ActiveRecord::Base.timestamped_migrations
|
14
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
15
|
+
else
|
16
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/uuid_it.rb
CHANGED
@@ -21,7 +21,7 @@ module ActiveRecord
|
|
21
21
|
|
22
22
|
def assign_uuid
|
23
23
|
return if Uuid.find_by_uuidable_type_and_uuidable_id(self.class.name, self.id)
|
24
|
-
uuid = Uuid.new(:
|
24
|
+
uuid = Uuid.new(:uuidable => self)
|
25
25
|
uuid.uuid = UUID.create.to_s
|
26
26
|
uuid.save
|
27
27
|
self.reload
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
+
- 1
|
7
8
|
- 0
|
8
|
-
|
9
|
-
version: 0.0.3
|
9
|
+
version: 0.1.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- "Andr\xC3\xA9 Duffeck"
|
@@ -30,6 +30,7 @@ extra_rdoc_files: []
|
|
30
30
|
files:
|
31
31
|
- lib/uuid_it/uuid.rb
|
32
32
|
- lib/ruby-uuid/uuid.rb
|
33
|
+
- lib/generators/uuid_it_generator.rb
|
33
34
|
- lib/uuid_it.rb
|
34
35
|
- README.md
|
35
36
|
- Rakefile
|