uniquify_roniyaar 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/Manifest ADDED
@@ -0,0 +1,4 @@
1
+ Manifest
2
+ README.rdoc
3
+ Rakefile
4
+ lib/uniquify.rb
data/README.rdoc ADDED
@@ -0,0 +1,16 @@
1
+ Commands
2
+
3
+ sudo gem install echoe
4
+ mkdir -p uniquify/lib
5
+ touch README.rdoc Rakefile lib/uniquify.rb
6
+ rake -T
7
+ rake manifest
8
+ rake install
9
+ rake build_gemspec
10
+ git init
11
+ git add .
12
+ git commit -m "initial commit"
13
+ git remote add origin git@github.com:ryanb/uniquify.git
14
+ git push
15
+ touch CHANGELOG
16
+ touch init.rb
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('uniquify_roniyaar', '0.1.0') do |p|
6
+ p.description = "Generate a unique token with ActiveRecord"
7
+ p.url = "http://github.com/eifion/uniquify"
8
+ p.author = "Eifion Bedford"
9
+ p.email = "eifion@asciicasts.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 }
data/lib/uniquify.rb ADDED
@@ -0,0 +1,38 @@
1
+
2
+
3
+ module Uniquify
4
+ def self.included(base)
5
+ base.extend ClassMethods
6
+ end
7
+
8
+ def ensure_unique(name)
9
+ begin
10
+ self[name] = yield
11
+ end while self.class.exists?(name => self[name])
12
+ end
13
+
14
+ module ClassMethods
15
+
16
+ def uniquify(*args, &block)
17
+ options = { :length => 8, :chars => ('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a }
18
+ options.merge!(args.pop) if args.last.kind_of? Hash
19
+ args.each do |name|
20
+ before_create do |record|
21
+ if block
22
+ record.ensure_unique(name, &block)
23
+ else
24
+ record.ensure_unique(name) do
25
+ Array.new(options[:length]) { options[:chars].to_a[rand(options[:chars].to_a.size)] }.join
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ end
33
+ end
34
+
35
+ class ActiveRecord::Base
36
+ include Uniquify
37
+ end
38
+
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "uniquify_roniyaar"
5
+ s.version = "0.1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Eifion Bedford"]
9
+ s.date = "2013-04-03"
10
+ s.description = "Generate a unique token with ActiveRecord"
11
+ s.email = "eifion@asciicasts.com"
12
+ s.extra_rdoc_files = ["README.rdoc", "lib/uniquify.rb"]
13
+ s.files = ["Manifest", "README.rdoc", "Rakefile", "lib/uniquify.rb", "uniquify_roniyaar.gemspec"]
14
+ s.homepage = "http://github.com/eifion/uniquify"
15
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Uniquify_roniyaar", "--main", "README.rdoc"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = "uniquify_roniyaar"
18
+ s.rubygems_version = "1.8.16"
19
+ s.summary = "Generate a unique token with ActiveRecord"
20
+
21
+ if s.respond_to? :specification_version then
22
+ s.specification_version = 3
23
+
24
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
25
+ else
26
+ end
27
+ else
28
+ end
29
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: uniquify_roniyaar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Eifion Bedford
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-03 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Generate a unique token with ActiveRecord
15
+ email: eifion@asciicasts.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files:
19
+ - README.rdoc
20
+ - lib/uniquify.rb
21
+ files:
22
+ - Manifest
23
+ - README.rdoc
24
+ - Rakefile
25
+ - lib/uniquify.rb
26
+ - uniquify_roniyaar.gemspec
27
+ homepage: http://github.com/eifion/uniquify
28
+ licenses: []
29
+ post_install_message:
30
+ rdoc_options:
31
+ - --line-numbers
32
+ - --inline-source
33
+ - --title
34
+ - Uniquify_roniyaar
35
+ - --main
36
+ - README.rdoc
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '1.2'
51
+ requirements: []
52
+ rubyforge_project: uniquify_roniyaar
53
+ rubygems_version: 1.8.16
54
+ signing_key:
55
+ specification_version: 3
56
+ summary: Generate a unique token with ActiveRecord
57
+ test_files: []