uuidable 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +9 -0
- data/.overcommit.yml +32 -0
- data/.rspec +2 -0
- data/.rubocop.yml +5 -0
- data/.travis.yml +15 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +46 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/uuidable/migration.rb +24 -0
- data/lib/uuidable/version.rb +3 -0
- data/lib/uuidable.rb +41 -0
- data/uuidable.gemspec +28 -0
- metadata +141 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
Y2JlMDY1NzVjMWM4YTkwYzdhMWNjMjk0N2E5ZTVlMWZiNGQ2NTVlMA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZWQ3MGIxNmZiNDA4YWQxNDIxMmRmOWZjYmRiNDg4ZGFkM2U5Y2QyYw==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MWFjOTQ0ZDhkZjc1YWI0NGFhYTg1YzM5MGVkNWQxMzVkNzYwZjhmNWEwMTlk
|
10
|
+
YWRhZGE5NjAwZjcxMjYxMmUyZWE1NDAyNjUwZjgxMjkyMzdiYjllZTNhYjg4
|
11
|
+
MjJmZDkyMTc4YTY5MjgxMzc2NjY0NGJjZDVjNjllY2Y1NGY1YmI=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZWZjM2JhZDFmYmIzYjdkMjI4YzY4ZTU0OGFmNDI3MTE0Mjk4NjFlMzRiYzkx
|
14
|
+
NTA1ZmE5NWY1Mzc3Y2UxMzk4MDM1ZWI3NTEzN2Q2ZjkyY2UwODQ3MWNkOWQy
|
15
|
+
YzljMzRkYWU5NzEwNTU1NDMzMTMyMzRhOWMyOGIyMDJiYzUwNTM=
|
data/.gitignore
ADDED
data/.overcommit.yml
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# Use this file to configure the Overcommit hooks you wish to use. This will
|
2
|
+
# extend the default configuration defined in:
|
3
|
+
# https://github.com/brigade/overcommit/blob/master/config/default.yml
|
4
|
+
#
|
5
|
+
# At the topmost level of this YAML file is a key representing type of hook
|
6
|
+
# being run (e.g. pre-commit, commit-msg, etc.). Within each type you can
|
7
|
+
# customize each hook, such as whether to only run it on certain files (via
|
8
|
+
# `include`), whether to only display output if it fails (via `quiet`), etc.
|
9
|
+
#
|
10
|
+
# For a complete list of hooks, see:
|
11
|
+
# https://github.com/brigade/overcommit/tree/master/lib/overcommit/hook
|
12
|
+
#
|
13
|
+
# For a complete list of options that you can use to customize hooks, see:
|
14
|
+
# https://github.com/brigade/overcommit#configuration
|
15
|
+
#
|
16
|
+
# Uncomment the following lines to make the configuration take effect.
|
17
|
+
|
18
|
+
PreCommit:
|
19
|
+
RuboCop:
|
20
|
+
enabled: true
|
21
|
+
on_warn: fail # Treat all warnings as failures
|
22
|
+
|
23
|
+
# TrailingWhitespace:
|
24
|
+
# exclude:
|
25
|
+
# - '**/db/structure.sql' # Ignore trailing whitespace in generated files
|
26
|
+
#
|
27
|
+
#PostCheckout:
|
28
|
+
# ALL: # Special hook name that customizes all hooks of this type
|
29
|
+
# quiet: true # Change all post-checkout hooks to only display output on failure
|
30
|
+
#
|
31
|
+
# IndexTags:
|
32
|
+
# enabled: true # Generate a tags file with `ctags` each time HEAD changes
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.2.4
|
4
|
+
before_install: gem install bundler -v 1.11.2
|
5
|
+
script:
|
6
|
+
- bundle exec rubocop
|
7
|
+
- bundle exec rspec
|
8
|
+
deploy:
|
9
|
+
provider: rubygems
|
10
|
+
api_key:
|
11
|
+
secure: UrlqP2DVITJ7IfNWyJAL1981jzQlrRaBoOINDvaea1fSf54U0Bf4zvhiad/5ZMml8dv07sLnp4+gDyZW2jnxae+44A4BxxOYD8UGmEztSjFfQrR6Mbe7vapTatJ4r86c5kv/ea/seUQyy4JgR7cy6MlsFj6HJIw01IiIz3XDMF0hL0C2PXwtCnWgamgnDE6Eqrj/DJ2qhJf/8ELl53N/4fPfnFZKNXzUHhqJqNFgXmoQ092dhkkjmwSZqg0KyANLC1zMW0fqBGpX29/b2QCw0AQDWDlRstA6y2MaVnCGmAE37xZBbO7w03g1Neyjovoz2SklR3z16zmFMx/b6MGDTmnFtMFD6rNn0Paac5zO8U9UmrL4kCUicF9muekneh26Ba9IBIUc/BjujK+yzRHVX3ycdhKz263P1m5PrmJk4VO6OZxSN7rjHPHoz5dy864h1kfhQUQ7o/RxpN5N5i9/fUHH88dYq8mELRQtZGJl3DqJrv6S2NN67/3VLsbPD2LoO01YMKhJmu6MKQzcjGYaA/wjdPWHVsoORvWEY0oWEMrI8qIOCDQH9D1JPyhBUF35jgKI4AcgLNkboByKXdyZD+qklsy8pCl4BtQHtpowZ5/UOp1wi9K5RkU9AwD4RqNz5czliTyjOn5kICdgrdBk6LmU280sdynSlyxOK6AA1g4=
|
12
|
+
gem: uuidable
|
13
|
+
on:
|
14
|
+
tags: true
|
15
|
+
repo: flant/uuidable
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Sergey Gnuskov
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Uuidable [![Build Status](https://travis-ci.org/flant/uuidable.svg?branch=master)](https://travis-ci.org/flant/uuidable)
|
2
|
+
|
3
|
+
With this gem you can use UUID instead of id in routes. But id is still primary key.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'uuidable'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install uuidable
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Simply add `uuidable` in your ActiveRecord model:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
class Project < ActiveRecord::Base
|
27
|
+
uuidable
|
28
|
+
|
29
|
+
# Rest of the code
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
## Development
|
34
|
+
|
35
|
+
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.
|
36
|
+
|
37
|
+
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`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
38
|
+
|
39
|
+
## Contributing
|
40
|
+
|
41
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/flant/uuidable.
|
42
|
+
|
43
|
+
|
44
|
+
## License
|
45
|
+
|
46
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'uuidable'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
module Uuidable
|
2
|
+
COLUMN_NAME = :uuid
|
3
|
+
COLUMN_TYPE = :binary
|
4
|
+
COLUMN_OPTIONS = { limit: 36, null: false, index: true }.freeze
|
5
|
+
|
6
|
+
# Module adds method to table definition
|
7
|
+
module TableDefinition
|
8
|
+
def uuid(opts = {})
|
9
|
+
column COLUMN_NAME, COLUMN_TYPE, opts.merge(COLUMN_OPTIONS)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# Module adds method to alter table migration
|
14
|
+
module Migration
|
15
|
+
def add_uuid_column(table_name, opts = {})
|
16
|
+
add_column table_name, COLUMN_NAME, COLUMN_TYPE, opts.merge(COLUMN_OPTIONS)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
if defined? ActiveRecord::ConnectionAdapters::TableDefinition
|
21
|
+
ActiveRecord::ConnectionAdapters::TableDefinition.send :include, Uuidable::TableDefinition
|
22
|
+
end
|
23
|
+
|
24
|
+
ActiveRecord::Migration.send :include, Uuidable::Migration if defined? ActiveRecord::Migration
|
data/lib/uuidable.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'uuidable/version'
|
2
|
+
require 'uuidable/migration'
|
3
|
+
|
4
|
+
require 'active_support'
|
5
|
+
|
6
|
+
# Main module
|
7
|
+
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
|
24
|
+
|
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
|
35
|
+
SecureRandom.uuid
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
ActiveSupport.on_load(:active_record) do
|
40
|
+
ActiveRecord::Base.send(:include, Uuidable)
|
41
|
+
end
|
data/uuidable.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'uuidable/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'uuidable'
|
8
|
+
spec.version = Uuidable::VERSION
|
9
|
+
spec.authors = ['Sergey Gnuskov']
|
10
|
+
spec.email = ['sergey.gnuskov@flant.com']
|
11
|
+
|
12
|
+
spec.summary = 'Helps using uuid everywhere in routes instead of id for ActiveRecord models.'
|
13
|
+
spec.description = ''
|
14
|
+
spec.homepage = 'https://github.com/flant/uuidable'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = 'exe'
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
25
|
+
spec.add_development_dependency 'travis', '~> 1.8', '>= 1.8.2'
|
26
|
+
|
27
|
+
spec.add_dependency 'activerecord', '>= 4.2', '< 5.1'
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: uuidable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sergey Gnuskov
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: travis
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.8'
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 1.8.2
|
65
|
+
type: :development
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ~>
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '1.8'
|
72
|
+
- - ! '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 1.8.2
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: activerecord
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ! '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '4.2'
|
82
|
+
- - <
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '5.1'
|
85
|
+
type: :runtime
|
86
|
+
prerelease: false
|
87
|
+
version_requirements: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ! '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '4.2'
|
92
|
+
- - <
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '5.1'
|
95
|
+
description: ''
|
96
|
+
email:
|
97
|
+
- sergey.gnuskov@flant.com
|
98
|
+
executables: []
|
99
|
+
extensions: []
|
100
|
+
extra_rdoc_files: []
|
101
|
+
files:
|
102
|
+
- .gitignore
|
103
|
+
- .overcommit.yml
|
104
|
+
- .rspec
|
105
|
+
- .rubocop.yml
|
106
|
+
- .travis.yml
|
107
|
+
- Gemfile
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- bin/console
|
112
|
+
- bin/setup
|
113
|
+
- lib/uuidable.rb
|
114
|
+
- lib/uuidable/migration.rb
|
115
|
+
- lib/uuidable/version.rb
|
116
|
+
- uuidable.gemspec
|
117
|
+
homepage: https://github.com/flant/uuidable
|
118
|
+
licenses:
|
119
|
+
- MIT
|
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: '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.5
|
138
|
+
signing_key:
|
139
|
+
specification_version: 4
|
140
|
+
summary: Helps using uuid everywhere in routes instead of id for ActiveRecord models.
|
141
|
+
test_files: []
|