mini_token 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.bundle/config ADDED
@@ -0,0 +1,2 @@
1
+ ---
2
+ BUNDLE_DISABLE_SHARED_GEMS: "1"
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color --format nested
data/.rvmrc ADDED
@@ -0,0 +1,2 @@
1
+ rvm --create 1.9.2@mini-token
2
+
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source :gemcutter
2
+
3
+ group :test do
4
+ gem "shoulda"
5
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,10 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ shoulda (2.11.3)
5
+
6
+ PLATFORMS
7
+ ruby
8
+
9
+ DEPENDENCIES
10
+ shoulda
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Antônio Roberto Silva
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.rdoc ADDED
@@ -0,0 +1,23 @@
1
+ = MiniToken
2
+
3
+ Simple token generator for short url and some other things :)
4
+
5
+ == Instalation
6
+
7
+ gem install mini_token
8
+
9
+ == Example
10
+
11
+ Generate token with default size
12
+
13
+ MiniToken.output
14
+ # => "S8hQNy"
15
+
16
+ Generate token with other size
17
+
18
+ MiniToken.output(9)
19
+ # => "2u27Jum8Y"
20
+
21
+ == Copyright
22
+
23
+ Copyright (c) 2010 Antônio Roberto Silva. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,52 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "mini_token"
8
+ gem.summary = %Q{Simple token generator}
9
+ gem.description = %Q{Generate simple tokens for short url and other things}
10
+ gem.email = "forevertonny@gmail.com"
11
+ gem.homepage = "http://github.com/dev_ton/mini_token"
12
+ gem.authors = ["Antonio Roberto Silva"]
13
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
14
+ end
15
+ Jeweler::GemcutterTasks.new
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
18
+ end
19
+
20
+ require 'rake/testtask'
21
+ Rake::TestTask.new(:test) do |test|
22
+ test.libs << 'lib' << 'test'
23
+ test.pattern = 'test/**/test_*.rb'
24
+ test.verbose = true
25
+ end
26
+
27
+ begin
28
+ require 'rcov/rcovtask'
29
+ Rcov::RcovTask.new do |test|
30
+ test.libs << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+ rescue LoadError
35
+ task :rcov do
36
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
37
+ end
38
+ end
39
+
40
+ task :test => :check_dependencies
41
+
42
+ task :default => :test
43
+
44
+ require 'rake/rdoctask'
45
+ Rake::RDocTask.new do |rdoc|
46
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
47
+
48
+ rdoc.rdoc_dir = 'rdoc'
49
+ rdoc.title = "mini_token #{version}"
50
+ rdoc.rdoc_files.include('README*')
51
+ rdoc.rdoc_files.include('lib/**/*.rb')
52
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/lib/mini_token.rb ADDED
@@ -0,0 +1,24 @@
1
+ class MiniToken < Struct.new(:token_size, :token)
2
+ TOKEN_SIZE = 6
3
+ TOKEN_CHARACTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890'
4
+
5
+ class << self
6
+ def output(size = nil)
7
+ generate { @token_size = size.nil? ? TOKEN_SIZE : size }
8
+ end
9
+
10
+ private
11
+
12
+ def generate
13
+ yield if block_given?
14
+ token = []
15
+ @token_size.times { token << TOKEN_CHARACTERS[pointer] }
16
+ token.join
17
+ end
18
+
19
+ def pointer
20
+ srand
21
+ rand(MiniToken::TOKEN_CHARACTERS.size)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,56 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{mini_token}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Antonio Roberto Silva"]
12
+ s.date = %q{2010-10-10}
13
+ s.description = %q{Generate simple tokens for short url and other things}
14
+ s.email = %q{forevertonny@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".bundle/config",
21
+ ".document",
22
+ ".gitignore",
23
+ ".rspec",
24
+ ".rvmrc",
25
+ "Gemfile",
26
+ "Gemfile.lock",
27
+ "LICENSE",
28
+ "README.rdoc",
29
+ "Rakefile",
30
+ "VERSION",
31
+ "lib/mini_token.rb",
32
+ "mini_token.gemspec",
33
+ "test/helper.rb",
34
+ "test/test_mini_token.rb"
35
+ ]
36
+ s.homepage = %q{http://github.com/dev_ton/mini_token}
37
+ s.rdoc_options = ["--charset=UTF-8"]
38
+ s.require_paths = ["lib"]
39
+ s.rubygems_version = %q{1.3.7}
40
+ s.summary = %q{Simple token generator}
41
+ s.test_files = [
42
+ "test/helper.rb",
43
+ "test/test_mini_token.rb"
44
+ ]
45
+
46
+ if s.respond_to? :specification_version then
47
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
48
+ s.specification_version = 3
49
+
50
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
51
+ else
52
+ end
53
+ else
54
+ end
55
+ end
56
+
data/test/helper.rb ADDED
@@ -0,0 +1,17 @@
1
+ require 'bundler'
2
+ require 'rubygems'
3
+ require 'test/unit'
4
+ require 'minitest/unit'
5
+ require 'minitest/spec'
6
+ require 'shoulda'
7
+
8
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
9
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
10
+
11
+
12
+ require 'mini_token'
13
+ Bundler.setup
14
+
15
+
16
+ class Test::Unit::TestCase
17
+ end
@@ -0,0 +1,32 @@
1
+ require 'helper'
2
+ MiniTest::Unit.autorun
3
+
4
+ describe MiniToken do
5
+ describe "MiniToken Constants" do
6
+ it "Default Token Size" do
7
+ assert_equal 6, MiniToken::TOKEN_SIZE
8
+ end
9
+
10
+ it "Default Token Characters" do
11
+ assert_equal 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890', MiniToken::TOKEN_CHARACTERS
12
+ end
13
+ end
14
+
15
+ describe "MiniToken" do
16
+ it "without size defined the generated token should be have 6 characters" do
17
+ assert_equal 6, MiniToken.output.size
18
+ end
19
+
20
+ it "with size defined the token should be have the size passed characters" do
21
+ assert_equal 9, MiniToken.output(9).size
22
+ end
23
+
24
+ it 'should be return the token string with default size' do
25
+ assert_match /([a-zA-Z0-9]{6})/, MiniToken.output
26
+ end
27
+
28
+ it 'should be return the token string with size' do
29
+ assert_match /([a-zA-Z0-9]{10})/, MiniToken.output(10)
30
+ end
31
+ end
32
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mini_token
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Antonio Roberto Silva
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-10-10 00:00:00 -03:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Generate simple tokens for short url and other things
22
+ email: forevertonny@gmail.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - LICENSE
29
+ - README.rdoc
30
+ files:
31
+ - .bundle/config
32
+ - .document
33
+ - .gitignore
34
+ - .rspec
35
+ - .rvmrc
36
+ - Gemfile
37
+ - Gemfile.lock
38
+ - LICENSE
39
+ - README.rdoc
40
+ - Rakefile
41
+ - VERSION
42
+ - lib/mini_token.rb
43
+ - mini_token.gemspec
44
+ - test/helper.rb
45
+ - test/test_mini_token.rb
46
+ has_rdoc: true
47
+ homepage: http://github.com/dev_ton/mini_token
48
+ licenses: []
49
+
50
+ post_install_message:
51
+ rdoc_options:
52
+ - --charset=UTF-8
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ segments:
69
+ - 0
70
+ version: "0"
71
+ requirements: []
72
+
73
+ rubyforge_project:
74
+ rubygems_version: 1.3.7
75
+ signing_key:
76
+ specification_version: 3
77
+ summary: Simple token generator
78
+ test_files:
79
+ - test/helper.rb
80
+ - test/test_mini_token.rb