randomized_id 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.
- data/MIT-LICENSE +20 -0
- data/README +25 -0
- data/Rakefile +43 -0
- data/init.rb +1 -0
- data/lib/randomized_id.rb +21 -0
- data/rails/init.rb +0 -0
- metadata +72 -0
data/MIT-LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2009--2010 Bence Golda <golda@bitandpixel.hu>, Bit and Pixel Kft.
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
RandomizedID
|
|
2
|
+
============
|
|
3
|
+
|
|
4
|
+
This plugin will give your models random generated primary keys in a simple and
|
|
5
|
+
clean way. Now it only supports single primary keys that is named `id`.
|
|
6
|
+
|
|
7
|
+
Requirements and installation
|
|
8
|
+
=============================
|
|
9
|
+
|
|
10
|
+
It is based on ActiveRecord / ActiveModel and mainly aims to provide Rails
|
|
11
|
+
support so installing it as a plugin is the best way to install. But you may
|
|
12
|
+
use it whereever your model provides #count() and #before_create() class
|
|
13
|
+
methods.
|
|
14
|
+
|
|
15
|
+
Example
|
|
16
|
+
=======
|
|
17
|
+
|
|
18
|
+
class YourClass < ActiveRecord::Base
|
|
19
|
+
include RandomizedID
|
|
20
|
+
...
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
Copyright (c) 2009--2010 Bence Golda <golda@bitandpixel.hu>, released under the
|
|
25
|
+
MIT license
|
data/Rakefile
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
require 'rake'
|
|
2
|
+
require 'rake/rdoctask'
|
|
3
|
+
require 'rake/gempackagetask'
|
|
4
|
+
|
|
5
|
+
#desc 'Default: run unit tests.'
|
|
6
|
+
#task :default => :test
|
|
7
|
+
|
|
8
|
+
desc 'Generate documentation for the randomized_id plugin.'
|
|
9
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
11
|
+
rdoc.title = 'RandomizedID'
|
|
12
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
|
13
|
+
rdoc.rdoc_files.include('README')
|
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
PKG_FILES = FileList[
|
|
18
|
+
'[a-zA-Z]*',
|
|
19
|
+
'generators/**/*',
|
|
20
|
+
'lib/**/*',
|
|
21
|
+
'rails/**/*',
|
|
22
|
+
'tasks/**/*',
|
|
23
|
+
'test/**/*'
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
spec = Gem::Specification.new do |s|
|
|
27
|
+
s.name = "randomized_id"
|
|
28
|
+
s.version = "0.0.2"
|
|
29
|
+
s.author = "Bence Golda"
|
|
30
|
+
s.email = "golda@bitandpixel.hu"
|
|
31
|
+
s.homepage = "http://bitandpixel.hu/"
|
|
32
|
+
s.platform = Gem::Platform::RUBY
|
|
33
|
+
s.summary = "Random id generator for ActiveModel and co."
|
|
34
|
+
s.files = PKG_FILES.to_a
|
|
35
|
+
s.require_path = "lib"
|
|
36
|
+
s.has_rdoc = false
|
|
37
|
+
s.extra_rdoc_files = ["README"]
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
desc "Turn this plugin into a gem."
|
|
41
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
|
42
|
+
pkg.gem_spec = spec
|
|
43
|
+
end
|
data/init.rb
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'lib', 'randomized_id'))
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# RandomizedID
|
|
2
|
+
|
|
3
|
+
require 'digest/sha1'
|
|
4
|
+
|
|
5
|
+
module RandomizedID
|
|
6
|
+
def self.included base
|
|
7
|
+
super
|
|
8
|
+
base.class_eval do
|
|
9
|
+
include InstanceMethods
|
|
10
|
+
before_create :randomize_id
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
module InstanceMethods
|
|
15
|
+
def randomize_id
|
|
16
|
+
id_candidate = rand(1<<31)
|
|
17
|
+
id_candidate = rand(1<<31) while send(:class).where(:id => id_candidate).count > 0
|
|
18
|
+
write_attribute(:id, id_candidate)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
data/rails/init.rb
ADDED
|
File without changes
|
metadata
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: randomized_id
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
hash: 27
|
|
5
|
+
prerelease: false
|
|
6
|
+
segments:
|
|
7
|
+
- 0
|
|
8
|
+
- 0
|
|
9
|
+
- 2
|
|
10
|
+
version: 0.0.2
|
|
11
|
+
platform: ruby
|
|
12
|
+
authors:
|
|
13
|
+
- Bence Golda
|
|
14
|
+
autorequire:
|
|
15
|
+
bindir: bin
|
|
16
|
+
cert_chain: []
|
|
17
|
+
|
|
18
|
+
date: 2010-12-07 00:00:00 +01:00
|
|
19
|
+
default_executable:
|
|
20
|
+
dependencies: []
|
|
21
|
+
|
|
22
|
+
description:
|
|
23
|
+
email: golda@bitandpixel.hu
|
|
24
|
+
executables: []
|
|
25
|
+
|
|
26
|
+
extensions: []
|
|
27
|
+
|
|
28
|
+
extra_rdoc_files:
|
|
29
|
+
- README
|
|
30
|
+
files:
|
|
31
|
+
- init.rb
|
|
32
|
+
- README
|
|
33
|
+
- Rakefile
|
|
34
|
+
- MIT-LICENSE
|
|
35
|
+
- lib/randomized_id.rb
|
|
36
|
+
- rails/init.rb
|
|
37
|
+
has_rdoc: true
|
|
38
|
+
homepage: http://bitandpixel.hu/
|
|
39
|
+
licenses: []
|
|
40
|
+
|
|
41
|
+
post_install_message:
|
|
42
|
+
rdoc_options: []
|
|
43
|
+
|
|
44
|
+
require_paths:
|
|
45
|
+
- lib
|
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
47
|
+
none: false
|
|
48
|
+
requirements:
|
|
49
|
+
- - ">="
|
|
50
|
+
- !ruby/object:Gem::Version
|
|
51
|
+
hash: 3
|
|
52
|
+
segments:
|
|
53
|
+
- 0
|
|
54
|
+
version: "0"
|
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
|
+
none: false
|
|
57
|
+
requirements:
|
|
58
|
+
- - ">="
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
hash: 3
|
|
61
|
+
segments:
|
|
62
|
+
- 0
|
|
63
|
+
version: "0"
|
|
64
|
+
requirements: []
|
|
65
|
+
|
|
66
|
+
rubyforge_project:
|
|
67
|
+
rubygems_version: 1.3.7
|
|
68
|
+
signing_key:
|
|
69
|
+
specification_version: 3
|
|
70
|
+
summary: Random id generator for ActiveModel and co.
|
|
71
|
+
test_files: []
|
|
72
|
+
|