laserlemon-tokenize 0.1.0 → 0.1.1

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 CHANGED
@@ -4,6 +4,7 @@ Manifest
4
4
  MIT_LICENSE
5
5
  Rakefile
6
6
  README.rdoc
7
+ tasks/tokenize_tasks.rake
7
8
  test/test_helper.rb
8
9
  test/tokenize_test.rb
9
10
  tokenize.gemspec
data/README.rdoc CHANGED
@@ -1,6 +1,6 @@
1
- = belongs_to_versioned
1
+ = tokenize
2
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.
3
+ <tt>tokenize</tt> generates unique strings for ActiveRecord models before creation. This works well for setting API keys, temporary passwords, etc. <tt>tokenize</tt> is also great for creating forward-facing IDs for models such as products or orders where you may not want to use the numeric primary key and reveal your volume.
4
4
 
5
5
  == Installation
6
6
 
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('tokenize', '0.1.0') do |g|
5
+ Echoe.new('tokenize', '0.1.1') do |g|
6
6
  g.description = %(Generate unique tokens for your ActiveRecord models)
7
7
  g.url = 'http://github.com/laserlemon/tokenize'
8
8
  g.author = 'Steve Richert'
@@ -0,0 +1,28 @@
1
+ def get_class
2
+ klass = ENV['CLASS'] || ENV['class']
3
+ raise 'Must specify CLASS' unless klass
4
+ @class = Object.const_get(klass)
5
+ end
6
+
7
+ def get_columns
8
+ raise "Class #{@class.name} has no tokenized columns" unless @class.respond_to?(:tokens)
9
+ @columns = if column = ENV['COLUMN'] || ENV['column']
10
+ raise "Class #{@class.name} has no tokenized column #{column}" unless @class.tokens.has_key?(column.to_sym)
11
+ @class.tokens.slice(column_to_sym)
12
+ else @class.tokens
13
+ end
14
+ end
15
+
16
+ desc 'Generates unique tokens for a given CLASS (and optional COLUMN)'
17
+ task :tokenize => :environment do
18
+ get_class and get_columns
19
+ @class.all.each do |instance|
20
+ @columns.each do |column, options|
21
+ if instance.send(column).blank?
22
+ new_token = Array.new(options[:length]){ options[:characters].rand }.join
23
+ instance.send("#{column}=", new_token) while instance.class.exists?(column => new_token)
24
+ end
25
+ end
26
+ instance.save
27
+ end
28
+ end
data/tokenize.gemspec CHANGED
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{tokenize}
5
- s.version = "0.1.0"
5
+ s.version = "0.1.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Steve Richert"]
9
9
  s.date = %q{2009-04-28}
10
10
  s.description = %q{Generate unique tokens for your ActiveRecord models}
11
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"]
12
+ s.extra_rdoc_files = ["lib/tokenize.rb", "README.rdoc", "tasks/tokenize_tasks.rake"]
13
+ s.files = ["init.rb", "lib/tokenize.rb", "Manifest", "MIT_LICENSE", "Rakefile", "README.rdoc", "tasks/tokenize_tasks.rake", "test/test_helper.rb", "test/tokenize_test.rb", "tokenize.gemspec", "VERSION.yml"]
14
14
  s.has_rdoc = true
15
15
  s.homepage = %q{http://github.com/laserlemon/tokenize}
16
16
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Tokenize", "--main", "README.rdoc"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: laserlemon-tokenize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Richert
@@ -22,6 +22,7 @@ extensions: []
22
22
  extra_rdoc_files:
23
23
  - lib/tokenize.rb
24
24
  - README.rdoc
25
+ - tasks/tokenize_tasks.rake
25
26
  files:
26
27
  - init.rb
27
28
  - lib/tokenize.rb
@@ -29,6 +30,7 @@ files:
29
30
  - MIT_LICENSE
30
31
  - Rakefile
31
32
  - README.rdoc
33
+ - tasks/tokenize_tasks.rake
32
34
  - test/test_helper.rb
33
35
  - test/tokenize_test.rb
34
36
  - tokenize.gemspec