rtoken 0.0.1 → 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.
Files changed (2) hide show
  1. data/lib/rtoken.rb +14 -0
  2. metadata +1 -1
data/lib/rtoken.rb CHANGED
@@ -5,6 +5,7 @@
5
5
  #
6
6
  # @example Generate 10 length token
7
7
  # RToken.rtoken(:size => 10) #=> Random sequence 10 chars
8
+ # RTolen.rtoken(10) #=> Less verbose fashion
8
9
  #
9
10
  # @example Generate 16 length token with special chars
10
11
  # RToken.rtoken(:size => 16, :special_chars => '!@#$%%&')
@@ -48,11 +49,13 @@ class RToken
48
49
  # @param [Hash] opts options that will be merged to the predefined on initialize
49
50
  # @return [String] token
50
51
  def rtoken(opts=nil)
52
+ opts = RToken.check_param(opts)
51
53
  RToken.rtoken @options.merge(opts || {})
52
54
  end
53
55
 
54
56
  # Generates a token
55
57
  #
58
+ # @param [Integer] opts Sames as :size => n
56
59
  # @param [Hash] opts The options to configure the token generator
57
60
  # @param opts [Fixnum] :size The size of token string. Default 8
58
61
  # @param opts :uppercase if true all chars will be replaced by uppercase. Default false
@@ -61,6 +64,7 @@ class RToken
61
64
  # @param opts [String] :special_chars special chars to be include on token generation, by default include alphanumeric chars
62
65
  # @return [String] token
63
66
  def self.rtoken(opts=nil)
67
+ opts = check_param(opts)
64
68
  options = DEAFULT_OPTIONS.merge(opts || {})
65
69
  size = options[:size] || 8
66
70
  # Merge available chars
@@ -80,4 +84,14 @@ class RToken
80
84
  end
81
85
  token_chars.join
82
86
  end
87
+
88
+ private
89
+
90
+ # @return If param is a Integer then convert it to {:size => param}
91
+ def self.check_param(param)
92
+ if param && param.is_a?(Integer)
93
+ return {:size => param}
94
+ end
95
+ param
96
+ end
83
97
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: rtoken
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.1.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Thiago Lewin