ar-uuid 0.1.1
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 +7 -0
- data/.gitignore +9 -0
- data/.rspec +1 -0
- data/.travis.yml +10 -0
- data/Gemfile +4 -0
- data/README.md +63 -0
- data/Rakefile +6 -0
- data/ar-uuid.gemspec +24 -0
- data/lib/active_record/uuid.rb +10 -0
- data/lib/active_record/uuid/ext.rb +6 -0
- data/lib/active_record/uuid/schema.rb +15 -0
- data/lib/active_record/uuid/table_definition.rb +15 -0
- data/lib/active_record/uuid/version.rb +5 -0
- data/lib/ar-uuid.rb +1 -0
- metadata +142 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 211af2aa01d2050af8510cd61f090734e8eb2e5c
|
4
|
+
data.tar.gz: b679257afd1846687f2b29d6a6c96ffc596316ed
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4192b75517ae01de3b0e3dd4550c759ee129be1adbc9e96da6c4daaf1d3829bacbe577abb08aa59e0358448fb3f730b2c737f340ab17e3b01bb12247f5e93450
|
7
|
+
data.tar.gz: 4cd10cdf46460e9708f003f94f408db821529e0d768a3681e8b676db9d7f50faf006c241e0a0208bff4bff930366b6cea5d50cc546a332dc576af7cea966190d
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# ActiveRecord::UUID
|
2
|
+
|
3
|
+
[](https://travis-ci.org/fnando/ar-uuid)
|
4
|
+
|
5
|
+
Override migration methods to support UUID columns without having to be explicit about it.
|
6
|
+
|
7
|
+
What this gem will do for you:
|
8
|
+
|
9
|
+
- When creating new tables, will set the `id` column as `uuid`.
|
10
|
+
- When creating associations with `t.belongs_to`, `t.references` or `add_reference`, will set the column type as `uuid`.
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem 'ar-uuid'
|
18
|
+
```
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
$ bundle
|
23
|
+
|
24
|
+
Or install it yourself as:
|
25
|
+
|
26
|
+
$ gem install ar-uuid
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
There's no setup. Just adding the gem to your Gemfile is enough. When you create a new table, the `id` column will be defined as `uuid`. This is also true for references.
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
create_table :users
|
34
|
+
add_reference :posts, :users
|
35
|
+
|
36
|
+
create_table :posts do |t|
|
37
|
+
t.belongs_to :user
|
38
|
+
# or
|
39
|
+
t.references :user
|
40
|
+
end
|
41
|
+
```
|
42
|
+
|
43
|
+
If you need a serial column, AR's PostgreSQL supports the `bigserial` column type.
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
create_table :users do |t|
|
47
|
+
t.column :position, :bigserial, null: false
|
48
|
+
end
|
49
|
+
```
|
50
|
+
|
51
|
+
## Development
|
52
|
+
|
53
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
54
|
+
4
|
55
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
56
|
+
|
57
|
+
## Contributing
|
58
|
+
|
59
|
+
1. Fork it ( https://github.com/[my-github-username]/ar-uuid/fork )
|
60
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
61
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
62
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
63
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/ar-uuid.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require './lib/active_record/uuid/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.required_ruby_version = '>= 2.1.0'
|
5
|
+
spec.name = 'ar-uuid'
|
6
|
+
spec.version = ActiveRecord::UUID::VERSION
|
7
|
+
spec.authors = ['Nando Vieira']
|
8
|
+
spec.email = ['fnando.vieira@gmail.com']
|
9
|
+
spec.summary = %[Add UUID support for ActiveRecord. It enforces uuid primary keys, fixes ActiveRecord's first/last methods and more.]
|
10
|
+
spec.description = spec.summary
|
11
|
+
spec.homepage = 'http://rubygems.org/gems/ar-uuid'
|
12
|
+
|
13
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
14
|
+
spec.bindir = 'exe'
|
15
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
16
|
+
spec.require_paths = ['lib']
|
17
|
+
|
18
|
+
spec.add_dependency 'activerecord'
|
19
|
+
spec.add_development_dependency 'bundler', '~> 1.9'
|
20
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
21
|
+
spec.add_development_dependency 'rspec'
|
22
|
+
spec.add_development_dependency 'pg'
|
23
|
+
spec.add_development_dependency 'pry-meta'
|
24
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module UUID
|
3
|
+
require 'active_record'
|
4
|
+
require 'active_record/base'
|
5
|
+
require 'active_record/uuid/version'
|
6
|
+
require 'active_record/uuid/schema'
|
7
|
+
require 'active_record/uuid/table_definition'
|
8
|
+
require 'active_record/uuid/ext'
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
ActiveSupport.on_load(:active_record) do
|
2
|
+
require 'active_record/connection_adapters/postgresql_adapter'
|
3
|
+
|
4
|
+
ActiveRecord::Schema.include ActiveRecord::UUID::Schema
|
5
|
+
ActiveRecord::ConnectionAdapters::PostgreSQL::TableDefinition.include ActiveRecord::UUID::TableDefinition
|
6
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module UUID
|
3
|
+
module Schema
|
4
|
+
def create_table(table_name, options = {}, &block)
|
5
|
+
options[:id] = :uuid unless options.key?(:id)
|
6
|
+
super(table_name, options, &block)
|
7
|
+
end
|
8
|
+
|
9
|
+
def add_reference(table_name, ref_name, options = {})
|
10
|
+
options[:type] = :uuid unless options.key?(:type)
|
11
|
+
super(table_name, ref_name, options)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module UUID
|
3
|
+
module TableDefinition
|
4
|
+
def references(*args)
|
5
|
+
options = args.extract_options!
|
6
|
+
options[:type] = :uuid unless options.include?(:type)
|
7
|
+
args << options
|
8
|
+
|
9
|
+
super(*args)
|
10
|
+
end
|
11
|
+
|
12
|
+
alias_method :belongs_to, :references
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/ar-uuid.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'active_record/uuid'
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ar-uuid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nando Vieira
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.9'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.9'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pg
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry-meta
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Add UUID support for ActiveRecord. It enforces uuid primary keys, fixes
|
98
|
+
ActiveRecord's first/last methods and more.
|
99
|
+
email:
|
100
|
+
- fnando.vieira@gmail.com
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rspec"
|
107
|
+
- ".travis.yml"
|
108
|
+
- Gemfile
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- ar-uuid.gemspec
|
112
|
+
- lib/active_record/uuid.rb
|
113
|
+
- lib/active_record/uuid/ext.rb
|
114
|
+
- lib/active_record/uuid/schema.rb
|
115
|
+
- lib/active_record/uuid/table_definition.rb
|
116
|
+
- lib/active_record/uuid/version.rb
|
117
|
+
- lib/ar-uuid.rb
|
118
|
+
homepage: http://rubygems.org/gems/ar-uuid
|
119
|
+
licenses: []
|
120
|
+
metadata: {}
|
121
|
+
post_install_message:
|
122
|
+
rdoc_options: []
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: 2.1.0
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
requirements: []
|
136
|
+
rubyforge_project:
|
137
|
+
rubygems_version: 2.4.6
|
138
|
+
signing_key:
|
139
|
+
specification_version: 4
|
140
|
+
summary: Add UUID support for ActiveRecord. It enforces uuid primary keys, fixes ActiveRecord's
|
141
|
+
first/last methods and more.
|
142
|
+
test_files: []
|