active_record_uuid 0.1.0 → 0.2.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 +45 -51
- data/lib/active_record_uuid.rb +13 -1
- data/lib/active_record_uuid/config.rb +23 -8
- data/lib/active_record_uuid/{association_methods.rb → extensions/association_methods.rb} +0 -0
- data/lib/active_record_uuid/extensions/quoting_extension.rb +1 -1
- data/lib/active_record_uuid/hooks.rb +10 -0
- data/lib/active_record_uuid/model.rb +31 -17
- data/lib/active_record_uuid/rails/generators/config_generator.rb +16 -0
- data/lib/active_record_uuid/rails/generators/templates/active_record_uuid_config.rb +8 -0
- data/lib/active_record_uuid/rails/railtie.rb +5 -7
- data/lib/active_record_uuid/uuid_base.rb +2 -2
- data/lib/active_record_uuid/uuid_base_helper.rb +1 -1
- data/lib/active_record_uuid/version.rb +1 -1
- data/spec/lib/config_spec.rb +16 -0
- data/spec/lib/has_uuid_spec.rb +59 -0
- data/spec/spec_helper.rb +3 -5
- data/spec/support/models.rb +5 -0
- data/spec/support/schema.rb +6 -0
- metadata +8 -3
data/README.md
CHANGED
@@ -2,6 +2,18 @@
|
|
2
2
|
|
3
3
|
`active_record_uuid` is a nice gem that add uuid supports to your `activerecord` models (MySQL). It allows you to store uuid in various formats: binary (16 bytes), base64 (24 bytes), hexdigest (32 bytes), or string (36 bytes), and query back with uuid string.
|
4
4
|
|
5
|
+
The performance issues arises when you store primary key in large data size. You have two options:
|
6
|
+
- use `auto-increment` primary key along with uuid column
|
7
|
+
- use `uuid` primary key, but store in binary format
|
8
|
+
|
9
|
+
You have various choices when storing uuid:
|
10
|
+
- binary format, 16 bytes
|
11
|
+
- base64 format, 24 bytes (encode uuid into base64)
|
12
|
+
- hexdigest, 32 bytes string (compact uuid format, without dash)
|
13
|
+
- string, 36 bytes string (full length uuid)
|
14
|
+
|
15
|
+
Check this out for more detail, [http://www.mysqlperformanceblog.com/2007/03/13/to-uuid-or-not-to-uuid/](http://www.mysqlperformanceblog.com/2007/03/13/to-uuid-or-not-to-uuid/).
|
16
|
+
|
5
17
|
## Installation
|
6
18
|
|
7
19
|
Add this line to your application's Gemfile:
|
@@ -18,7 +30,11 @@ Or install it yourself as:
|
|
18
30
|
|
19
31
|
## Upgrade from version 0.0.1
|
20
32
|
|
21
|
-
`ActiveRecordBase::UuidBase` and `UuidBaseHelper` are depreciated. Right now, you can configure your model by using `
|
33
|
+
`ActiveRecordBase::UuidBase` and `UuidBaseHelper` are depreciated. Right now, you can configure your model by using `has_uuid` and inherit from `ActiveRecord::Base`. Check out the usage below.
|
34
|
+
|
35
|
+
## Upgrade from version 0.1.0
|
36
|
+
|
37
|
+
`uuid_config` is fine, but I like to use `has_uuid` and passing in options instead.
|
22
38
|
|
23
39
|
## Usage
|
24
40
|
|
@@ -33,46 +49,42 @@ If you need to use `uuid` column as primary key, don't add any `:primary_key` in
|
|
33
49
|
$ rake db:add_primary_keys # Add primary keys to all models
|
34
50
|
$ rake db:add_primary_key[model_name] # Add primary key to a model
|
35
51
|
|
36
|
-
The performance issues arises when you store primary key in large data size. You have two options:
|
37
|
-
- use `auto-increment` primary key along with uuid column
|
38
|
-
- use `uuid` primary key, but store in binary format
|
39
|
-
|
40
|
-
You have various choices when storing uuid:
|
41
|
-
- binary format, 16 bytes
|
42
|
-
- base64 format, 24 bytes (encode uuid into base64)
|
43
|
-
- hexdigest, 32 bytes string (compact uuid format, without dash)
|
44
|
-
- string, 36 bytes string (full length uuid)
|
45
|
-
|
46
52
|
### Migration
|
47
53
|
|
48
|
-
In order for the gem to work well, you need to specify the column `type` and `limit` correctly according to your `
|
54
|
+
In order for the gem to work well, you need to specify the column `type` and `limit` correctly according to your `has_uuid` (`store_as` option).
|
49
55
|
|
50
56
|
create_table :posts, :force => true, :id => false do |t|
|
51
|
-
t.binary :uuid, :limit => 16 # must set to the correct value
|
57
|
+
t.binary :uuid, :limit => 16 # `must set to the correct value`
|
52
58
|
t.string :text
|
53
59
|
t.timestamps
|
54
60
|
end
|
55
61
|
|
56
62
|
class Post < ActiveRecord::Base
|
57
|
-
|
58
|
-
primary_key true
|
59
|
-
store_as :binary
|
60
|
-
end
|
63
|
+
has_uuid :primary_key => true, :store_as => :binary
|
61
64
|
end
|
65
|
+
|
66
|
+
### General configuration options
|
62
67
|
|
63
|
-
|
68
|
+
You can configure using `ActiveRecordUuid.configure`, and it will apply to any models which use `has_uuid`. Each model can overwrite the general options by passing options into `has_uuid`. The following are default values:
|
69
|
+
|
70
|
+
column :uuid # :uuid is default
|
71
|
+
primary_key true # false is default
|
72
|
+
association false # false is default
|
73
|
+
generator :timestamp # :timestamp is default
|
74
|
+
store_as :string # :string is default
|
75
|
+
hook :before_create # :before_validation is default
|
76
|
+
|
77
|
+
There's a config generator that generates the default configuration file into config/initializers directory.
|
78
|
+
Run the following generator command, then edit the generated file.
|
64
79
|
|
65
|
-
|
80
|
+
$ rails g active_record_uuid:config
|
81
|
+
|
82
|
+
### Model configuration
|
83
|
+
|
84
|
+
To use uuid in your model, call `has_uuid` in your model.
|
66
85
|
|
67
86
|
class Post < ActiveRecord::Base
|
68
|
-
|
69
|
-
column :uuid # :uuid is default
|
70
|
-
primary_key true # false is default
|
71
|
-
association false # false is default
|
72
|
-
generator :timestamp # :timestamp is default
|
73
|
-
store_as :string # :string is default
|
74
|
-
hook :before_create # :before_validation is default
|
75
|
-
end
|
87
|
+
has_uuid :primary_key => true, :hook => :before_create
|
76
88
|
end
|
77
89
|
|
78
90
|
# create a post with auto-generated uuid
|
@@ -100,10 +112,7 @@ To use uuid in your model, call `uuid_config` in your model.
|
|
100
112
|
### Binary uuid model (example)
|
101
113
|
|
102
114
|
class PostBinary < ActiveRecord::Base
|
103
|
-
|
104
|
-
primary_key true
|
105
|
-
store_as :binary
|
106
|
-
end
|
115
|
+
has_uuid :primary_key => true, :store_as => :binary
|
107
116
|
end
|
108
117
|
|
109
118
|
post = PostBinary.create(:text => "Binary uuid1")
|
@@ -123,7 +132,7 @@ To use uuid in your model, call `uuid_config` in your model.
|
|
123
132
|
post.reload
|
124
133
|
post.attributes_before_type_cast["uuid"]["value"]
|
125
134
|
|
126
|
-
### Avaliable options inside `
|
135
|
+
### Avaliable options inside `has_uuid`
|
127
136
|
#### `column` option
|
128
137
|
|
129
138
|
Set the column name to store uuid value.
|
@@ -149,42 +158,27 @@ Specify the activerecord hook `[:after_initialize, :before_validation, :before_c
|
|
149
158
|
When you set this option to `true`, it expects you have foreign_keys with `_uuid`. Therefore, you don't have to pass `:foreign_key` option inside association methods
|
150
159
|
|
151
160
|
class Author < ActiveRecord::Base
|
152
|
-
|
153
|
-
primary_key true
|
154
|
-
association true
|
155
|
-
end
|
161
|
+
has_uuid :primary_key => true, :association => true
|
156
162
|
has_and_belongs_to_many :posts
|
157
163
|
end
|
158
164
|
|
159
165
|
class Post < ActiveRecord::Base
|
160
|
-
|
161
|
-
primary_key true
|
162
|
-
association true
|
163
|
-
end
|
166
|
+
has_uuid :primary_key => true, :association => true
|
164
167
|
has_many :comments
|
165
168
|
has_one :comment
|
166
169
|
has_and_belongs_to_many :authors
|
167
170
|
end
|
168
171
|
|
169
172
|
class Comment < ActiveRecord::Base
|
170
|
-
|
171
|
-
primary_key true
|
172
|
-
association true
|
173
|
-
end
|
173
|
+
has_uuid :primary_key => true, :association => true
|
174
174
|
belongs_to :post
|
175
175
|
end
|
176
176
|
|
177
177
|
# overwrite :foreign_key option and add additional option
|
178
178
|
class Post < ActiveRecord::Base
|
179
|
-
|
180
|
-
primary_key true
|
181
|
-
association true
|
182
|
-
end
|
179
|
+
has_uuid :primary_key => true, :association => true
|
183
180
|
has_many :comments, :foreign_key => "comment_id", :inverse_of => :post
|
184
181
|
end
|
185
182
|
|
186
183
|
## Testing
|
187
184
|
This gem will set the format for dumping the database schema to `:sql`. This means that it is no longer dump the schema to ruby code but database-independent version, `db/structure.sql`. Therefore, you would not have any problems when running the tests.
|
188
|
-
|
189
|
-
## References
|
190
|
-
- [http://www.mysqlperformanceblog.com/2007/03/13/to-uuid-or-not-to-uuid/](http://www.mysqlperformanceblog.com/2007/03/13/to-uuid-or-not-to-uuid/)
|
data/lib/active_record_uuid.rb
CHANGED
@@ -7,8 +7,20 @@ module ActiveRecordUuid
|
|
7
7
|
autoload :VERSION, 'active_record_uuid/version'
|
8
8
|
autoload :Config, 'active_record_uuid/config'
|
9
9
|
autoload :Serializer, 'active_record_uuid/serializer'
|
10
|
-
autoload :AssociationMethods, 'active_record_uuid/association_methods'
|
10
|
+
autoload :AssociationMethods, 'active_record_uuid/extensions/association_methods'
|
11
|
+
autoload :QuotingExtension, 'active_record_uuid/extensions/quoting_extension'
|
11
12
|
autoload :Model, 'active_record_uuid/model'
|
13
|
+
autoload :Hooks, 'active_record_uuid/hooks'
|
14
|
+
|
15
|
+
def self.configure(&block)
|
16
|
+
@config = ActiveRecordUuid::Config.new
|
17
|
+
@config.instance_eval(&block)
|
18
|
+
@config.validate_options!
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.config
|
22
|
+
@config || ActiveRecordUuid::Config.new
|
23
|
+
end
|
12
24
|
end
|
13
25
|
|
14
26
|
require 'active_record_uuid/uuid_base'
|
@@ -1,22 +1,37 @@
|
|
1
1
|
module ActiveRecordUuid
|
2
2
|
class Config
|
3
|
-
def initialize
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
3
|
+
def initialize(options = {})
|
4
|
+
default_options = {
|
5
|
+
:column => :uuid,
|
6
|
+
:primary_key => false,
|
7
|
+
:association => false,
|
8
|
+
:generator => :timestamp,
|
9
|
+
:store_as => :string,
|
10
|
+
:hook => :before_validation
|
11
|
+
}
|
12
|
+
options = default_options.merge(options)
|
13
|
+
|
14
|
+
options.each_pair do |key, value|
|
15
|
+
send(key.to_sym, value)
|
16
|
+
end
|
10
17
|
end
|
11
18
|
|
12
19
|
METHODS = [:column, :primary_key, :association, :generator, :store_as, :hook]
|
13
20
|
METHODS.each do |meth|
|
14
21
|
define_method(meth.to_sym) do |value=nil|
|
15
|
-
instance_variable_set("@#{meth}".to_sym, value) if value
|
22
|
+
instance_variable_set("@#{meth}".to_sym, value) if value.to_s.present?
|
16
23
|
instance_variable_get("@#{meth}")
|
17
24
|
end
|
18
25
|
end
|
19
26
|
|
27
|
+
def to_hash
|
28
|
+
METHODS.inject({}) do |result, key|
|
29
|
+
result[key] = send(key)
|
30
|
+
|
31
|
+
result
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
20
35
|
def validate_options!
|
21
36
|
default_generators = [:timestamp, :random]
|
22
37
|
raise ArgumentError,
|
File without changes
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module ActiveRecordUuid
|
2
|
+
class Hooks
|
3
|
+
def self.init
|
4
|
+
ActiveSupport.on_load(:active_record) do |app|
|
5
|
+
::ActiveRecord::Base.connection.class.send :include, ActiveRecordUuid::QuotingExtension
|
6
|
+
::ActiveRecord::Base.send(:include, ActiveRecordUuid::Model)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -27,12 +27,16 @@ module ActiveRecordUuid::Model
|
|
27
27
|
end
|
28
28
|
|
29
29
|
private
|
30
|
+
def uuid_config
|
31
|
+
self.class.uuid_config
|
32
|
+
end
|
33
|
+
|
30
34
|
def assign_uuid_when_blank
|
31
35
|
assign_uuid if uuid_value.blank?
|
32
36
|
end
|
33
37
|
|
34
38
|
def uuid_column
|
35
|
-
|
39
|
+
uuid_config.column
|
36
40
|
end
|
37
41
|
|
38
42
|
def validates_uuid
|
@@ -40,27 +44,37 @@ module ActiveRecordUuid::Model
|
|
40
44
|
end
|
41
45
|
end
|
42
46
|
|
43
|
-
module ClassMethods
|
47
|
+
module ClassMethods
|
48
|
+
def generate_uuid
|
49
|
+
UUIDTools::UUID.send("#{uuid_config.generator}_create").to_s
|
50
|
+
end
|
51
|
+
|
44
52
|
def uuid_config(&block)
|
45
|
-
return @
|
53
|
+
return @uuid_config if @uuid_config.present?
|
46
54
|
|
47
|
-
@
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
self.primary_key = column_name if @config.primary_key
|
53
|
-
self.serialize column_name, ActiveRecordUuid::Serializer.new(@config.store_as)
|
54
|
-
self.send(@config.hook, :assign_uuid_when_blank)
|
55
|
-
self.validates_uniqueness_of column_name, :if => Proc.new { |r| r.uuid_value.present? }
|
56
|
-
self.validate :validates_uuid , :if => Proc.new { |r| r.uuid_value.present? }
|
57
|
-
self.send(:extend, ActiveRecordUuid::AssociationMethods) if @config.association
|
55
|
+
@uuid_config = ActiveRecordUuid::Config.new
|
56
|
+
if block_given?
|
57
|
+
@uuid_config.instance_eval(&block)
|
58
|
+
@uuid_config.validate_options!
|
59
|
+
end
|
58
60
|
|
59
|
-
|
61
|
+
# apply uuid based on config
|
62
|
+
has_uuid(@uuid_config.to_hash)
|
63
|
+
|
64
|
+
@uuid_config
|
60
65
|
end
|
61
66
|
|
62
|
-
def
|
63
|
-
|
67
|
+
def has_uuid(options = {})
|
68
|
+
options = ActiveRecordUuid.config.to_hash.merge(options)
|
69
|
+
@uuid_config = ActiveRecordUuid::Config.new(options)
|
70
|
+
|
71
|
+
column_name = uuid_config.column.to_sym
|
72
|
+
self.primary_key = column_name if uuid_config.primary_key
|
73
|
+
self.serialize column_name, ActiveRecordUuid::Serializer.new(uuid_config.store_as)
|
74
|
+
self.send(uuid_config.hook, :assign_uuid_when_blank)
|
75
|
+
self.validates_uniqueness_of column_name, :if => Proc.new { |r| r.uuid_value.present? }
|
76
|
+
self.validate :validates_uuid, :if => Proc.new { |r| r.uuid_value.present? }
|
77
|
+
self.send(:extend, ActiveRecordUuid::AssociationMethods) if uuid_config.association
|
64
78
|
end
|
65
79
|
end
|
66
80
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module ActiveRecordUuid
|
2
|
+
module Generators
|
3
|
+
class ConfigGenerator < Rails::Generators::Base
|
4
|
+
source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
|
5
|
+
|
6
|
+
desc <<DESC
|
7
|
+
Description:
|
8
|
+
Copies ActiveRecordUuid configuration file to your application's initializer directory.
|
9
|
+
DESC
|
10
|
+
|
11
|
+
def copy_config_file
|
12
|
+
template 'active_record_uuid_config.rb', 'config/initializers/active_record_uuid_config.rb'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -3,17 +3,15 @@ module ActiveRecordUuid
|
|
3
3
|
config.active_record.schema_format = :sql
|
4
4
|
|
5
5
|
initializer :after => 'active_record.initialize_database' do
|
6
|
-
|
7
|
-
ActiveSupport.on_load(:active_record) do |app|
|
8
|
-
require 'active_record_uuid/extensions/quoting_extension'
|
9
|
-
|
10
|
-
::ActiveRecord::Base.connection.class.send :include, ActiveRecordUuid::QuotingExtension
|
11
|
-
::ActiveRecord::Base.send(:include, ActiveRecordUuid::Model)
|
12
|
-
end
|
6
|
+
ActiveRecordUuid::Hooks.init
|
13
7
|
end
|
14
8
|
|
15
9
|
rake_tasks do
|
16
10
|
load "active_record_uuid/rails/db.rake"
|
17
11
|
end
|
12
|
+
|
13
|
+
generators do
|
14
|
+
require 'active_record_uuid/rails/generators/config_generator'
|
15
|
+
end
|
18
16
|
end
|
19
17
|
end
|
@@ -4,7 +4,7 @@ class ActiveRecord::UuidBase < ::ActiveRecord::Base
|
|
4
4
|
class << self
|
5
5
|
def inherited_with_uuid(kls)
|
6
6
|
inherited_without_uuid kls
|
7
|
-
warn "[DEPRECATION] `UuidBaseHelper` and `ActiveRecord::UuidBase` are deprecated. Please inherit from `ActiveRecord::Base` and use `
|
7
|
+
warn "[DEPRECATION] `UuidBaseHelper` and `ActiveRecord::UuidBase` are deprecated. Please inherit from `ActiveRecord::Base` and use `has_uuid` instead."
|
8
8
|
kls.uuid_config do
|
9
9
|
primary_key true
|
10
10
|
association true
|
@@ -15,7 +15,7 @@ class ActiveRecord::UuidBase < ::ActiveRecord::Base
|
|
15
15
|
end
|
16
16
|
|
17
17
|
self.descendants.each do |kls|
|
18
|
-
warn "[DEPRECATION] `UuidBaseHelper` and `ActiveRecord::UuidBase` are deprecated. Please inherit from `ActiveRecord::Base` and use `
|
18
|
+
warn "[DEPRECATION] `UuidBaseHelper` and `ActiveRecord::UuidBase` are deprecated. Please inherit from `ActiveRecord::Base` and use `has_uuid` instead."
|
19
19
|
kls.uuid_config do
|
20
20
|
primary_key true
|
21
21
|
association true
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module UuidBaseHelper
|
2
2
|
def self.included(base)
|
3
|
-
warn "[DEPRECATION] `UuidBaseHelper` and `ActiveRecord::UuidBase` are deprecated. Please inherit from `ActiveRecord::Base` and use `
|
3
|
+
warn "[DEPRECATION] `UuidBaseHelper` and `ActiveRecord::UuidBase` are deprecated. Please inherit from `ActiveRecord::Base` and use `has_uuid` instead."
|
4
4
|
|
5
5
|
base.send(:include, ActiveRecordUuid::Model)
|
6
6
|
base.uuid_config do
|
data/spec/lib/config_spec.rb
CHANGED
@@ -12,6 +12,13 @@ describe "Uuid Config" do
|
|
12
12
|
@config.hook.should eq(:before_validation)
|
13
13
|
end
|
14
14
|
|
15
|
+
it "should initialize with provided values" do
|
16
|
+
@config = ActiveRecordUuid::Config.new(:primary_key => true, :column => :my_uuid)
|
17
|
+
|
18
|
+
@config.primary_key.should eq(true)
|
19
|
+
@config.column.should eq(:my_uuid)
|
20
|
+
end
|
21
|
+
|
15
22
|
it "should validate options: generator" do
|
16
23
|
@config = ActiveRecordUuid::Config.new
|
17
24
|
|
@@ -38,4 +45,13 @@ describe "Uuid Config" do
|
|
38
45
|
@config.validate_options!
|
39
46
|
}.should raise_error ArgumentError, /^Expected :before_validation/
|
40
47
|
end
|
48
|
+
|
49
|
+
it "should return as a hash with appropriate value" do
|
50
|
+
@config = ActiveRecordUuid::Config.new(:primary_key => true, :column => :my_uuid)
|
51
|
+
|
52
|
+
hash = @config.to_hash
|
53
|
+
hash.should be_instance_of(Hash)
|
54
|
+
hash[:primary_key].should eq(@config.primary_key)
|
55
|
+
hash[:column].should eq(@config.column)
|
56
|
+
end
|
41
57
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "has_uuid spec" do
|
4
|
+
context "per model" do
|
5
|
+
it "should have uuid as primary key based config" do
|
6
|
+
People.primary_key.should eq('uuid')
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should store uuid as binary" do
|
10
|
+
person = People.create(:name => "Binary name1")
|
11
|
+
person.reload
|
12
|
+
|
13
|
+
person.attributes_before_type_cast["uuid"]["value"].bytesize.should eq(16)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should find by uuid column" do
|
17
|
+
person = People.create(:name => "Binary name2")
|
18
|
+
|
19
|
+
People.find_by_uuid(person.uuid).should eq(person)
|
20
|
+
People.where(:uuid => person.uuid).should eq([person])
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "global" do
|
25
|
+
before(:all) do
|
26
|
+
ActiveRecordUuid.configure do
|
27
|
+
column :uuid
|
28
|
+
primary_key true
|
29
|
+
association false
|
30
|
+
store_as :binary
|
31
|
+
end
|
32
|
+
|
33
|
+
class PeopleBinary < ActiveRecord::Base
|
34
|
+
self.table_name = "people"
|
35
|
+
has_uuid :association => true
|
36
|
+
has_many :comments
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should use global configuration" do
|
41
|
+
PeopleBinary.uuid_config.store_as.should eq(:binary)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should use overwrite global configuration" do
|
45
|
+
PeopleBinary.uuid_config.association.should eq(true)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should apply based on configuration" do
|
49
|
+
PeopleBinary.reflections[:comments].options[:foreign_key].should eq("people_binary_uuid")
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should store uuid as binary" do
|
53
|
+
person = PeopleBinary.create!(:name => "Binary name1")
|
54
|
+
person.reload
|
55
|
+
|
56
|
+
person.attributes_before_type_cast["uuid"]["value"].bytesize.should eq(16)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -4,7 +4,7 @@ db_config = {
|
|
4
4
|
:adapter => "mysql2",
|
5
5
|
:database => "active_record_uuid",
|
6
6
|
:user => "root",
|
7
|
-
:password => "
|
7
|
+
:password => ""
|
8
8
|
}
|
9
9
|
|
10
10
|
ActiveRecord::Base.establish_connection(db_config) rescue nil
|
@@ -13,10 +13,8 @@ ActiveRecord::Base.establish_connection(db_config.merge(:database => nil))
|
|
13
13
|
ActiveRecord::Base.connection.create_database(db_config[:database], { :charset => 'utf8', :collation => 'utf8_unicode_ci' })
|
14
14
|
ActiveRecord::Base.establish_connection(db_config)
|
15
15
|
|
16
|
-
# load
|
17
|
-
|
18
|
-
::ActiveRecord::Base.connection.class.send :include, ActiveRecordUuid::QuotingExtension
|
19
|
-
::ActiveRecord::Base.send(:include, ActiveRecordUuid::Model)
|
16
|
+
# load hooks
|
17
|
+
ActiveRecordUuid::Hooks.init
|
20
18
|
|
21
19
|
# load support
|
22
20
|
load File.dirname(__FILE__) + '/support/schema.rb'
|
data/spec/support/models.rb
CHANGED
@@ -30,6 +30,11 @@ class PostBinary < ActiveRecord::Base
|
|
30
30
|
has_many :comments
|
31
31
|
end
|
32
32
|
|
33
|
+
class People < ActiveRecord::Base
|
34
|
+
self.table_name = "people"
|
35
|
+
has_uuid :column => :uuid, :primary_key => true, :store_as => :binary
|
36
|
+
end
|
37
|
+
|
33
38
|
class PostBase64 < ActiveRecord::Base
|
34
39
|
uuid_config do
|
35
40
|
primary_key true
|
data/spec/support/schema.rb
CHANGED
@@ -19,6 +19,12 @@ ActiveRecord::Schema.define do
|
|
19
19
|
t.timestamps
|
20
20
|
end
|
21
21
|
|
22
|
+
create_table :people, :force => true, :id => false do |t|
|
23
|
+
t.binary :uuid, :limit => 16
|
24
|
+
t.string :name
|
25
|
+
t.timestamps
|
26
|
+
end
|
27
|
+
|
22
28
|
create_table :post_base64s, :force => true, :id => false do |t|
|
23
29
|
t.string :uuid, :limit => 24
|
24
30
|
t.string :text
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record_uuid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-07-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -126,11 +126,14 @@ files:
|
|
126
126
|
- Rakefile
|
127
127
|
- active_record_uuid.gemspec
|
128
128
|
- lib/active_record_uuid.rb
|
129
|
-
- lib/active_record_uuid/association_methods.rb
|
130
129
|
- lib/active_record_uuid/config.rb
|
130
|
+
- lib/active_record_uuid/extensions/association_methods.rb
|
131
131
|
- lib/active_record_uuid/extensions/quoting_extension.rb
|
132
|
+
- lib/active_record_uuid/hooks.rb
|
132
133
|
- lib/active_record_uuid/model.rb
|
133
134
|
- lib/active_record_uuid/rails/db.rake
|
135
|
+
- lib/active_record_uuid/rails/generators/config_generator.rb
|
136
|
+
- lib/active_record_uuid/rails/generators/templates/active_record_uuid_config.rb
|
134
137
|
- lib/active_record_uuid/rails/railtie.rb
|
135
138
|
- lib/active_record_uuid/serializer.rb
|
136
139
|
- lib/active_record_uuid/uuid_base.rb
|
@@ -141,6 +144,7 @@ files:
|
|
141
144
|
- spec/lib/binary_uuid_spec.rb
|
142
145
|
- spec/lib/config_spec.rb
|
143
146
|
- spec/lib/deprecation_spec.rb
|
147
|
+
- spec/lib/has_uuid_spec.rb
|
144
148
|
- spec/lib/hexdigest_uuid_spec.rb
|
145
149
|
- spec/lib/serializer_spec.rb
|
146
150
|
- spec/lib/string_uuid_spec.rb
|
@@ -178,6 +182,7 @@ test_files:
|
|
178
182
|
- spec/lib/binary_uuid_spec.rb
|
179
183
|
- spec/lib/config_spec.rb
|
180
184
|
- spec/lib/deprecation_spec.rb
|
185
|
+
- spec/lib/has_uuid_spec.rb
|
181
186
|
- spec/lib/hexdigest_uuid_spec.rb
|
182
187
|
- spec/lib/serializer_spec.rb
|
183
188
|
- spec/lib/string_uuid_spec.rb
|