paulinohuerta-uniquifyb 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.rdoc +0 -0
- data/Rakefile +16 -0
- data/lib/uniquify.rb +35 -0
- data/uniquifyb.gemspec +29 -0
- metadata +63 -0
data/README.rdoc
ADDED
File without changes
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
|
5
|
+
Echoe.new('uniquifyb', '0.1.0') do |p|
|
6
|
+
p.description = "Generate a unique token with Active Record."
|
7
|
+
p.url = "http://github.com/paulinohuerta/uniquifyb"
|
8
|
+
p.author = "Ryan Bates"
|
9
|
+
p.email = "paulinohuerta@gmail.com"
|
10
|
+
p.ignore_pattern = ["tmp/*", "script/*"]
|
11
|
+
p.development_dependencies = []
|
12
|
+
end
|
13
|
+
|
14
|
+
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
|
15
|
+
|
16
|
+
|
data/lib/uniquify.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
module Uniquify
|
2
|
+
def self.included(base)
|
3
|
+
base.extend ClassMethods
|
4
|
+
end
|
5
|
+
|
6
|
+
def ensure_unique(name)
|
7
|
+
begin
|
8
|
+
self[name] = yield
|
9
|
+
end while self.class.exists?(name => self[name])
|
10
|
+
end
|
11
|
+
|
12
|
+
module ClassMethods
|
13
|
+
|
14
|
+
def uniquify(*args, &block)
|
15
|
+
options = { :length => 8, :chars => ('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a }
|
16
|
+
options.merge!(args.pop) if args.last.kind_of? Hash
|
17
|
+
args.each do |name|
|
18
|
+
before_create do |record|
|
19
|
+
if block
|
20
|
+
record.ensure_unique(name, &block)
|
21
|
+
else
|
22
|
+
record.ensure_unique(name) do
|
23
|
+
Array.new(options[:length]) { options[:chars].to_a[rand(options[:chars].to_a.size)] }.join
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class ActiveRecord::Base
|
34
|
+
include Uniquify
|
35
|
+
end
|
data/uniquifyb.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = %q{uniquifyb}
|
3
|
+
s.version = "0.1.0"
|
4
|
+
|
5
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
6
|
+
s.authors = ["Ryan Bates"]
|
7
|
+
s.date = %q{2009-01-04}
|
8
|
+
s.description = %q{Generate a unique token with Active Record.}
|
9
|
+
s.email = %q{paulinohuerta@gmail.com}
|
10
|
+
s.extra_rdoc_files = ["lib/uniquify.rb", "README.rdoc"]
|
11
|
+
s.files = ["lib/uniquify.rb", "README.rdoc", "Rakefile", "Manifest", "uniquifyb.gemspec"]
|
12
|
+
s.has_rdoc = true
|
13
|
+
s.homepage = %q{http://github.com/paulinohuerta/uniquifyb}
|
14
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Uniquifyb", "--main", "README.rdoc"]
|
15
|
+
s.require_paths = ["lib"]
|
16
|
+
s.rubyforge_project = %q{uniquifyb}
|
17
|
+
s.rubygems_version = %q{1.2.0}
|
18
|
+
s.summary = %q{Generate a unique token with Active Record.}
|
19
|
+
|
20
|
+
if s.respond_to? :specification_version then
|
21
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
22
|
+
s.specification_version = 2
|
23
|
+
|
24
|
+
if current_version >= 3 then
|
25
|
+
else
|
26
|
+
end
|
27
|
+
else
|
28
|
+
end
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: paulinohuerta-uniquifyb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryan Bates
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-01-04 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Generate a unique token with Active Record.
|
17
|
+
email: paulinohuerta@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- lib/uniquify.rb
|
24
|
+
- README.rdoc
|
25
|
+
files:
|
26
|
+
- lib/uniquify.rb
|
27
|
+
- README.rdoc
|
28
|
+
- Rakefile
|
29
|
+
- Manifest
|
30
|
+
- uniquifyb.gemspec
|
31
|
+
has_rdoc: true
|
32
|
+
homepage: http://github.com/paulinohuerta/uniquifyb
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options:
|
35
|
+
- --line-numbers
|
36
|
+
- --inline-source
|
37
|
+
- --title
|
38
|
+
- Uniquifyb
|
39
|
+
- --main
|
40
|
+
- README.rdoc
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: "0"
|
48
|
+
version:
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "1.2"
|
54
|
+
version:
|
55
|
+
requirements: []
|
56
|
+
|
57
|
+
rubyforge_project: uniquifyb
|
58
|
+
rubygems_version: 1.2.0
|
59
|
+
signing_key:
|
60
|
+
specification_version: 2
|
61
|
+
summary: Generate a unique token with Active Record.
|
62
|
+
test_files: []
|
63
|
+
|