laserlemon-tokenize 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/MIT_LICENSE +20 -0
- data/Manifest +10 -0
- data/README.rdoc +35 -0
- data/Rakefile +14 -0
- data/VERSION.yml +4 -0
- data/init.rb +1 -0
- data/lib/tokenize.rb +35 -0
- data/test/test_helper.rb +3 -0
- data/test/tokenize_test.rb +8 -0
- data/tokenize.gemspec +32 -0
- metadata +69 -0
data/MIT_LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Steve Richert
|
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/Manifest
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
= belongs_to_versioned
|
2
|
+
|
3
|
+
The purpose of <tt>belongs_to_versioned</tt> is to save version information as used by the <tt>acts_as_versioned</tt>[http://github.com/technoweenie/acts_as_versioned/tree/master] plugin by technoweenie[http://github.com/technoweenie] alongside <tt>belongs_to</tt> ActiveRecord associations.
|
4
|
+
|
5
|
+
== Installation
|
6
|
+
|
7
|
+
script/plugin install git://github.com/laserlemon/tokenize.git
|
8
|
+
|
9
|
+
== Example
|
10
|
+
|
11
|
+
In your migration:
|
12
|
+
|
13
|
+
create_table :users do |t|
|
14
|
+
t.string :first_name
|
15
|
+
t.string :last_name
|
16
|
+
t.string :token, :limit => 8
|
17
|
+
t.timestamps
|
18
|
+
end
|
19
|
+
|
20
|
+
In your model:
|
21
|
+
|
22
|
+
class User < ActiveRecord::Base
|
23
|
+
validates_presence_of :first_name, :last_name
|
24
|
+
|
25
|
+
tokenize
|
26
|
+
end
|
27
|
+
|
28
|
+
In your controller:
|
29
|
+
|
30
|
+
user = User.create(:first_name => 'Steve', :last_name => 'Richert')
|
31
|
+
|
32
|
+
== Tips
|
33
|
+
|
34
|
+
* You can pass multiple token columns into the <tt>tokenize</tt> or omit the column names to use the default (<tt>:token</tt>).
|
35
|
+
* You can pass <tt>:length</tt> and <tt>:characters</tt> options to the <tt>tokenize</tt> method for finer control over the token format. The default is an 8-character string of lowercase and uppercase letters as well as numbers, producing 218,340,105,584,896 possible tokens.
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
|
5
|
+
Echoe.new('tokenize', '0.1.0') do |g|
|
6
|
+
g.description = %(Generate unique tokens for your ActiveRecord models)
|
7
|
+
g.url = 'http://github.com/laserlemon/tokenize'
|
8
|
+
g.author = 'Steve Richert'
|
9
|
+
g.email = 'steve@laserlemon.com'
|
10
|
+
g.ignore_pattern = %w(tmp/* script/*)
|
11
|
+
g.development_dependencies = []
|
12
|
+
end
|
13
|
+
|
14
|
+
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each{|t| load t }
|
data/VERSION.yml
ADDED
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'tokenize'
|
data/lib/tokenize.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
module LaserLemon
|
2
|
+
module Tokenize
|
3
|
+
|
4
|
+
CHARACTERS = ('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a
|
5
|
+
|
6
|
+
def self.included(base)
|
7
|
+
base.extend ClassMethods
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
def tokenize(*columns)
|
12
|
+
options = columns.extract_options!.symbolize_keys.reverse_merge(
|
13
|
+
:length => 8,
|
14
|
+
:characters => LaserLemon::Tokenize::CHARACTERS
|
15
|
+
)
|
16
|
+
columns.empty? ? columns.replace([:token]) : columns.collect!(&:to_sym)
|
17
|
+
write_inheritable_hash :tokens, columns.inject({}){|h,c| h.update(c => options) }
|
18
|
+
class_inheritable_reader :tokens
|
19
|
+
include InstanceMethods
|
20
|
+
before_create :generate_token
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
module InstanceMethods
|
25
|
+
def generate_token
|
26
|
+
self.class.tokens.each do |column, options|
|
27
|
+
new_token = Array.new(options[:length]){ options[:characters].rand }.join
|
28
|
+
send("#{column}=", new_token) while self.class.exists?(column => new_token)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
ActiveRecord::Base.send(:include, LaserLemon::Tokenize)
|
data/test/test_helper.rb
ADDED
data/tokenize.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{tokenize}
|
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 = ["Steve Richert"]
|
9
|
+
s.date = %q{2009-04-28}
|
10
|
+
s.description = %q{Generate unique tokens for your ActiveRecord models}
|
11
|
+
s.email = %q{steve@laserlemon.com}
|
12
|
+
s.extra_rdoc_files = ["lib/tokenize.rb", "README.rdoc"]
|
13
|
+
s.files = ["init.rb", "lib/tokenize.rb", "Manifest", "MIT_LICENSE", "Rakefile", "README.rdoc", "test/test_helper.rb", "test/tokenize_test.rb", "tokenize.gemspec", "VERSION.yml"]
|
14
|
+
s.has_rdoc = true
|
15
|
+
s.homepage = %q{http://github.com/laserlemon/tokenize}
|
16
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Tokenize", "--main", "README.rdoc"]
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
s.rubyforge_project = %q{tokenize}
|
19
|
+
s.rubygems_version = %q{1.3.1}
|
20
|
+
s.summary = %q{Generate unique tokens for your ActiveRecord models}
|
21
|
+
s.test_files = ["test/test_helper.rb", "test/tokenize_test.rb"]
|
22
|
+
|
23
|
+
if s.respond_to? :specification_version then
|
24
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
25
|
+
s.specification_version = 2
|
26
|
+
|
27
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
28
|
+
else
|
29
|
+
end
|
30
|
+
else
|
31
|
+
end
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: laserlemon-tokenize
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Steve Richert
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-04-28 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Generate unique tokens for your ActiveRecord models
|
17
|
+
email: steve@laserlemon.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- lib/tokenize.rb
|
24
|
+
- README.rdoc
|
25
|
+
files:
|
26
|
+
- init.rb
|
27
|
+
- lib/tokenize.rb
|
28
|
+
- Manifest
|
29
|
+
- MIT_LICENSE
|
30
|
+
- Rakefile
|
31
|
+
- README.rdoc
|
32
|
+
- test/test_helper.rb
|
33
|
+
- test/tokenize_test.rb
|
34
|
+
- tokenize.gemspec
|
35
|
+
- VERSION.yml
|
36
|
+
has_rdoc: true
|
37
|
+
homepage: http://github.com/laserlemon/tokenize
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options:
|
40
|
+
- --line-numbers
|
41
|
+
- --inline-source
|
42
|
+
- --title
|
43
|
+
- Tokenize
|
44
|
+
- --main
|
45
|
+
- README.rdoc
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: "0"
|
53
|
+
version:
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "1.2"
|
59
|
+
version:
|
60
|
+
requirements: []
|
61
|
+
|
62
|
+
rubyforge_project: tokenize
|
63
|
+
rubygems_version: 1.2.0
|
64
|
+
signing_key:
|
65
|
+
specification_version: 2
|
66
|
+
summary: Generate unique tokens for your ActiveRecord models
|
67
|
+
test_files:
|
68
|
+
- test/test_helper.rb
|
69
|
+
- test/tokenize_test.rb
|