ar-tokens 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +11 -0
- data/README.markdown +1 -1
- data/ar-tokens.gemspec +1 -1
- data/gemfiles/Gemfile.activerecord-3.1.x +11 -0
- data/gemfiles/Gemfile.activerecord-3.2.x +11 -0
- data/gemfiles/Gemfile.activerecord-4.0.x +11 -0
- data/lib/active_record/mixin/token_generator.rb +7 -4
- data/lib/object.rb +2 -2
- data/lib/tokens/version.rb +1 -1
- data/spec/active_record_spec.rb +10 -2
- data/spec/support/active_record.rb +5 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f02a81709949a789c3adff05838e6fc9e7030f43
|
4
|
+
data.tar.gz: ff9afc616e4c4b7318f12ae30d710f8a89eebc3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2231116bd1e5183d29ddb9a6f9863e97b1a594bd44341b81f9bc1635003d8e69917b6e7948d7f073f50ef9e57a0ee6df1a90ae6b6123321a6b09fbdfc98cb87
|
7
|
+
data.tar.gz: 6832ec43e3d7d21be05e2eeec14301708d456bc8c0ea6510f937407aca0a9b5ebfe65218870b58ac1090755abc361479362ed1252062030854a8c70a713b2c19
|
data/.travis.yml
CHANGED
@@ -2,3 +2,14 @@ language: ruby
|
|
2
2
|
rvm:
|
3
3
|
- 1.9.2
|
4
4
|
- 1.9.3
|
5
|
+
- 2.0
|
6
|
+
gemfile:
|
7
|
+
- gemfiles/Gemfile.activerecord-4.0.x
|
8
|
+
- gemfiles/Gemfile.activerecord-3.2.x
|
9
|
+
- gemfiles/Gemfile.activerecord-3.1.x
|
10
|
+
matrix:
|
11
|
+
exclude:
|
12
|
+
- rvm: 1.9.2
|
13
|
+
gemfile: gemfiles/Gemfile.activerecord-4.0.x
|
14
|
+
- rvm: 2.0
|
15
|
+
gemfile: gemfiles/Gemfile.activerecord-3.1.x
|
data/README.markdown
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
[![Build Status](https://travis-ci.org/spieker/tokens.png?branch=master)](https://travis-ci.org/spieker/tokens)
|
2
2
|
|
3
|
-
For generating a token on an active record column you can use `
|
3
|
+
For generating a token on an active record column you can use `tokenize`
|
4
4
|
|
5
5
|
Parameters
|
6
6
|
----------
|
data/ar-tokens.gemspec
CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.description = %q{This gem lets you easily generate tokens on ruby objects and provides additional methods on ActiveRecord::Base to generate tokens on records}
|
14
14
|
|
15
15
|
s.rubyforge_project = "tokens"
|
16
|
-
|
16
|
+
|
17
17
|
s.files = `git ls-files`.split("\n")
|
18
18
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
@@ -33,9 +33,12 @@ module ActiveRecord
|
|
33
33
|
:max_try => 8,
|
34
34
|
:characters => ('a'..'z').to_a+('A'..'Z').to_a+(0..9).to_a
|
35
35
|
}.merge(args.extract_options!)
|
36
|
-
|
36
|
+
|
37
37
|
columns = [columns] unless columns.is_a?(Array)
|
38
|
-
|
38
|
+
if options[:length].respond_to?(:call)
|
39
|
+
options[:length] = options[:length].call(self)
|
40
|
+
end
|
41
|
+
|
39
42
|
result = {}
|
40
43
|
token = nil
|
41
44
|
columns.each do |column|
|
@@ -71,10 +74,10 @@ module ActiveRecord
|
|
71
74
|
|
72
75
|
before_validation before_validation_options do |obj|
|
73
76
|
obj.generate_token column, options
|
74
|
-
end
|
77
|
+
end
|
75
78
|
end
|
76
79
|
end
|
77
|
-
|
80
|
+
|
78
81
|
def self.included(receiver)
|
79
82
|
receiver.send :include, InstanceMethods
|
80
83
|
receiver.extend ClassMethods
|
data/lib/object.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# This provides a method for generating a random token of the given length.
|
2
2
|
# The generated token is base58 encoded, so the token just contains numbers,
|
3
3
|
# up- and down case characters.
|
4
|
-
#
|
4
|
+
#
|
5
5
|
# Example:
|
6
6
|
# Object.new_token(10) # => "S2Mq4mJBv6" (i.e.)
|
7
7
|
# or
|
@@ -15,7 +15,7 @@ class Object
|
|
15
15
|
end
|
16
16
|
result
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def new_token(length=8, characters = ('a'..'z').to_a+('A'..'Z').to_a+(0..9).to_a)
|
20
20
|
self.class.new_token(length, characters)
|
21
21
|
end
|
data/lib/tokens/version.rb
CHANGED
data/spec/active_record_spec.rb
CHANGED
@@ -10,7 +10,7 @@ describe ActiveRecord::Mixin::TokenGenerator do
|
|
10
10
|
@klass.tokenize :token
|
11
11
|
@klass.create.token.should == 'aaaaaaaa'
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
it "raises an exception if no free token is available" do
|
15
15
|
SecureRandom.stub(:random_number).and_return(0)
|
16
16
|
@klass.tokenize :token
|
@@ -26,7 +26,7 @@ describe ActiveRecord::Mixin::TokenGenerator do
|
|
26
26
|
@klass.create.token.should == 'aaaaaaaa'
|
27
27
|
@klass.create.token.should == 'aaaaaaaa'
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
it "generates duplicate tokens in different scopes if allowed" do
|
31
31
|
SecureRandom.stub(:random_number).and_return(0)
|
32
32
|
@klass.tokenize :token, :scope => 'scope'
|
@@ -44,6 +44,14 @@ describe ActiveRecord::Mixin::TokenGenerator do
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
+
it "generates tokens with length specified by the return value of a given block" do
|
48
|
+
(6..32).each do |i|
|
49
|
+
@klass = TokenTest.dup
|
50
|
+
@klass.tokenize :token, :length => Proc.new { |m| i }
|
51
|
+
@klass.create.token.length.should == i
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
47
55
|
it "generates different tokens for different columns" do
|
48
56
|
@klass.tokenize [:token, :token_two]
|
49
57
|
r = @klass.create!
|
@@ -9,5 +9,9 @@ ActiveRecord::Migration.create_table :token_tests do |t|
|
|
9
9
|
end
|
10
10
|
|
11
11
|
class TokenTest < ActiveRecord::Base
|
12
|
-
set_table_name
|
12
|
+
if respond_to?(:set_table_name)
|
13
|
+
set_table_name 'token_tests'
|
14
|
+
else
|
15
|
+
self.table_name = 'token_tests'
|
16
|
+
end
|
13
17
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ar-tokens
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Spieker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -39,6 +39,9 @@ files:
|
|
39
39
|
- README.markdown
|
40
40
|
- Rakefile
|
41
41
|
- ar-tokens.gemspec
|
42
|
+
- gemfiles/Gemfile.activerecord-3.1.x
|
43
|
+
- gemfiles/Gemfile.activerecord-3.2.x
|
44
|
+
- gemfiles/Gemfile.activerecord-4.0.x
|
42
45
|
- lib/active_record/mixin/token_generator.rb
|
43
46
|
- lib/ar-tokens.rb
|
44
47
|
- lib/no_free_token.rb
|
@@ -76,3 +79,4 @@ test_files:
|
|
76
79
|
- spec/object_spec.rb
|
77
80
|
- spec/spec_helper.rb
|
78
81
|
- spec/support/active_record.rb
|
82
|
+
has_rdoc:
|