rtoken 0.2.0 → 0.2.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.
- checksums.yaml +7 -0
- data/LICENSE +18 -0
- data/README.rdoc +39 -0
- data/bin/rtoken +47 -0
- data/lib/rtoken.rb +3 -3
- metadata +44 -35
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0e7cccd8a8c08cca55c899a56d93801eff464181
|
4
|
+
data.tar.gz: 5278076136829bfb29c771f3f00a52277201a6d2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 29c01ee58e775b58a6da902104f87413811e55350d067d5666e75c3c24a74a7db33f147e615d3c31e7d9a396bd0fb0e07b137fb7aaf657fba02b84d51df3ab13
|
7
|
+
data.tar.gz: f74a193b65bc6681eb7cebc9dae0c3b95a35aa2898854b1b81320201d7c24094ba9a98d5d9968df8657e9132c33995ac8289c1cce3add65d8d0f5359112556d0
|
data/LICENSE
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Copyright (c) 2012 Thiago Lewin
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to
|
5
|
+
deal in the Software without restriction, including without limitation the
|
6
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
7
|
+
sell copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
16
|
+
THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
= RToken
|
2
|
+
|
3
|
+
Simple Random Token Generator for general purpose.
|
4
|
+
|
5
|
+
require 'rtoken'
|
6
|
+
|
7
|
+
# Generates a random 8 length token with letters and numbers
|
8
|
+
puts RToken.rtoken
|
9
|
+
|
10
|
+
Install the gem:
|
11
|
+
|
12
|
+
gem install rtoken
|
13
|
+
|
14
|
+
== Examples
|
15
|
+
|
16
|
+
require 'rtoken'
|
17
|
+
|
18
|
+
# Generates a random 16 length token with letters and numbers
|
19
|
+
# and some special chars
|
20
|
+
RToken.rtoken(:size => 16, :special_chars => '!@#$%')
|
21
|
+
|
22
|
+
# Generates a random 32 length token with ONLY letters
|
23
|
+
RToken.rtoken(:size => 32, :numeric => false)
|
24
|
+
|
25
|
+
# Generates a random token with all lowercase chars
|
26
|
+
RToken.rtoken(:size => 32, :numeric => false, :lowercase => true)
|
27
|
+
|
28
|
+
It is possible to create an instance with predefined options
|
29
|
+
|
30
|
+
require 'rtoken'
|
31
|
+
|
32
|
+
rtkn = RToken.new(:size => 10, :special_chars => '+-*/')
|
33
|
+
|
34
|
+
# All subsequent calls will keep the same options
|
35
|
+
rtkn.rtoken #=> Random 10 length token with special chars
|
36
|
+
|
37
|
+
# It is possible to make individual changes
|
38
|
+
rtkn.rtoken :size => 4 #=> Random 4 length token with special chars
|
39
|
+
rtkn.rtoken 4 # Less verbose fashion
|
data/bin/rtoken
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rtoken'
|
3
|
+
require 'optparse'
|
4
|
+
require 'clipboard'
|
5
|
+
|
6
|
+
options = {}
|
7
|
+
|
8
|
+
parser = OptionParser.new do |opts|
|
9
|
+
opts.banner = 'Usage: rtoken [options]'
|
10
|
+
|
11
|
+
opts.on('-s', '--size TOKEN_SIZE', Integer, "token size (default #{RToken::DEFAULT_OPTIONS[:size]})") do |size|
|
12
|
+
options[:size] = size
|
13
|
+
end
|
14
|
+
|
15
|
+
opts.on('-U', '--uppercase', "only uppercase chars (default #{RToken::DEFAULT_OPTIONS[:uppercase]})") do
|
16
|
+
options[:uppercase] = true
|
17
|
+
end
|
18
|
+
|
19
|
+
opts.on('-l', '--lowercase', "only lowercase chars (default #{RToken::DEFAULT_OPTIONS[:lowercase]})") do
|
20
|
+
options[:lowercase] = true
|
21
|
+
end
|
22
|
+
|
23
|
+
opts.on('-n', '--[no]-numeric', "allow numeric chars [0-9] (default #{RToken::DEFAULT_OPTIONS[:numeric]})") do |n|
|
24
|
+
options[:numeric] = n
|
25
|
+
end
|
26
|
+
|
27
|
+
opts.on('-p', '--special CHARS', String, 'include special chars') do |chars|
|
28
|
+
options[:special_chars] = chars
|
29
|
+
end
|
30
|
+
|
31
|
+
opts.on('-c', '--clipboard', 'copy token to the clipboard (default false)') do
|
32
|
+
options[:clipboard] = true
|
33
|
+
end
|
34
|
+
|
35
|
+
opts.on_tail('-h', '--help', 'show this message') do
|
36
|
+
puts opts
|
37
|
+
exit
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
parser.parse! ARGV
|
42
|
+
|
43
|
+
t = RToken.rtoken(options)
|
44
|
+
|
45
|
+
Clipboard.copy t if options[:clipboard]
|
46
|
+
puts t
|
47
|
+
|
data/lib/rtoken.rb
CHANGED
@@ -21,12 +21,12 @@ class RToken
|
|
21
21
|
|
22
22
|
NUMERIC_CHARS = ('0'..'9').to_a.freeze
|
23
23
|
|
24
|
-
|
24
|
+
DEFAULT_OPTIONS = {
|
25
25
|
:size => 8,
|
26
26
|
:uppercase => false,
|
27
27
|
:lowercase => false,
|
28
28
|
:numeric => true,
|
29
|
-
:
|
29
|
+
:special_chars => ''
|
30
30
|
}.freeze
|
31
31
|
|
32
32
|
# Creates an instance of RToken and handle the options for later calls
|
@@ -71,7 +71,7 @@ class RToken
|
|
71
71
|
# @return [String] token
|
72
72
|
def self.rtoken(opts=nil)
|
73
73
|
opts = check_param(opts)
|
74
|
-
options =
|
74
|
+
options = DEFAULT_OPTIONS.merge(opts || {})
|
75
75
|
size = options[:size] || 8
|
76
76
|
# Merge available chars
|
77
77
|
chars_array = options[:numeric] ? Array.new(NUMERIC_CHARS) : []
|
metadata
CHANGED
@@ -1,55 +1,64 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: rtoken
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
version: 0.2.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.1
|
6
5
|
platform: ruby
|
7
|
-
authors:
|
6
|
+
authors:
|
8
7
|
- Thiago Lewin
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
date: 2012-03-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: clipboard
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: 'RToken generates random tokens, of any length, for multiple purposes,
|
28
|
+
ex: web urls, data identification, etc.'
|
17
29
|
email: thiago_lewin@yahoo.com.br
|
18
|
-
executables:
|
19
|
-
|
30
|
+
executables:
|
31
|
+
- rtoken
|
20
32
|
extensions: []
|
21
|
-
|
22
33
|
extra_rdoc_files: []
|
23
|
-
|
24
|
-
files:
|
34
|
+
files:
|
25
35
|
- lib/rtoken.rb
|
36
|
+
- bin/rtoken
|
37
|
+
- README.rdoc
|
38
|
+
- LICENSE
|
26
39
|
homepage: https://github.com/tlewin/rtoken
|
27
|
-
licenses:
|
28
|
-
|
40
|
+
licenses:
|
41
|
+
- MIT
|
42
|
+
metadata: {}
|
29
43
|
post_install_message:
|
30
44
|
rdoc_options: []
|
31
|
-
|
32
|
-
require_paths:
|
45
|
+
require_paths:
|
33
46
|
- lib
|
34
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: "0"
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
46
57
|
requirements: []
|
47
|
-
|
48
58
|
rubyforge_project:
|
49
|
-
rubygems_version:
|
59
|
+
rubygems_version: 2.0.3
|
50
60
|
signing_key:
|
51
|
-
specification_version:
|
61
|
+
specification_version: 4
|
52
62
|
summary: Simple Random Token Generator
|
53
63
|
test_files: []
|
54
|
-
|
55
64
|
has_rdoc:
|