ar-tokens 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bbf6514fb51c630818b049f9391e2c1332a8221e
4
+ data.tar.gz: 3e7734e2a023372a9f8324aa21a02d9a3a28ee0e
5
+ SHA512:
6
+ metadata.gz: 0708d4e9f52437c54b5fd5746bf05f15ebe5095e29ec222beec02b50517830b562e1942bd10f28b8d4bc83846784cc92cdce33dec0b5750d2d7d1283bbcdc34b
7
+ data.tar.gz: db42c13c051e11d10daaa6f7cf90a9e8d061fd230fc488162669873c1c48f4e572a92526d93ff0fe3949e265959daaa5200bf574f9508f3bc8a87b9e8e0769bc
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
data/Gemfile CHANGED
@@ -4,3 +4,7 @@ source "http://rubygems.org"
4
4
  gemspec
5
5
  gem 'rspec'
6
6
  gem 'sqlite3'
7
+
8
+ group :test do
9
+ gem 'rake'
10
+ end
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 Paul Spieker
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.markdown CHANGED
@@ -1,3 +1,5 @@
1
+ [![Build Status](https://travis-ci.org/spieker/tokens.png?branch=master)](https://travis-ci.org/spieker/tokens)
2
+
1
3
  For generating a token on an active record column you can use `generate_token`
2
4
 
3
5
  Parameters
@@ -8,6 +10,7 @@ Parameters
8
10
  * :length: the token length (default: 8)
9
11
  * :uniq: whether the token must be uniq or not (default: true)
10
12
  * :scope: the column for the scope to check the uniqueness (default: nil)
13
+ * :characters: an array of characters the tokens should be build from (default: a-zA-Z0-9)
11
14
 
12
15
  Example
13
16
  -------
@@ -37,3 +40,6 @@ Currently the gem is not available on rubyforge, so you have to install it with
37
40
  gem 'ar-tokens'
38
41
  ```
39
42
 
43
+ License
44
+ -------
45
+ This project rocks and uses MIT-LICENSE.
data/Rakefile CHANGED
@@ -1,2 +1,8 @@
1
1
  require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
+
4
+ task :default => [:spec]
5
+ desc 'run Rspec specs'
6
+ task :spec do
7
+ sh 'rspec spec'
8
+ end
@@ -15,6 +15,7 @@ module ActiveRecord
15
15
  # ** :uniq: whether the token must be uniq or not (default: true)
16
16
  # ** :scope: the column for the scope to check the uniqueness (default: nil)
17
17
  # ** :same_token: if an array of columns is given and this option is true, all columns will get the same token (default: false)
18
+ # ** :characters: an array of characters used for token generation
18
19
  #
19
20
  # == Example
20
21
  # class User < ActiveRecord::Base
@@ -29,7 +30,8 @@ module ActiveRecord
29
30
  :uniq => true,
30
31
  :scope => nil,
31
32
  :same_token => false,
32
- :max_try => 8
33
+ :max_try => 8,
34
+ :characters => ('a'..'z').to_a+('A'..'Z').to_a+(0..9).to_a
33
35
  }.merge(args.extract_options!)
34
36
 
35
37
  columns = [columns] unless columns.is_a?(Array)
@@ -42,7 +44,7 @@ module ActiveRecord
42
44
  raise NoFreeToken.new(column) if counter >= options[:max_try]
43
45
  counter += 1
44
46
 
45
- token = new_token(options[:length]) if(token.blank? or not options[:same_token])
47
+ token = new_token(options[:length], options[:characters]) if(token.blank? or not options[:same_token])
46
48
  self.send("#{column}=".to_sym, token)
47
49
  result[column.to_sym] = token
48
50
  condition = { column => token }
@@ -64,8 +66,8 @@ module ActiveRecord
64
66
  options = {
65
67
  :on => :create
66
68
  }.merge(args.extract_options!)
67
- before_validation_options = options.reject { |k,v| [:length, :uniq, :scope, :same_token].include?(k) }
68
- options.select! { |k,v| [:length, :uniq, :scope, :same_token].include?(k) }
69
+ before_validation_options = options.reject { |k,v| [:length, :uniq, :scope, :same_token, :characters].include?(k) }
70
+ options.select! { |k,v| [:length, :uniq, :scope, :same_token, :characters].include?(k) }
69
71
 
70
72
  before_validation before_validation_options do |obj|
71
73
  obj.generate_token column, options
@@ -1,3 +1,3 @@
1
1
  module Tokens
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe ActiveRecord::Mixin::TokenGenerator do
4
4
  before :each do
5
- @klass = TokenTest.dup
5
+ @klass = TokenTest.dup
6
6
  end
7
7
 
8
8
  it "geneates a token" do
@@ -55,4 +55,10 @@ describe ActiveRecord::Mixin::TokenGenerator do
55
55
  r = @klass.create!
56
56
  r.token.should == r.token_two
57
57
  end
58
+
59
+ it "generates tokens from the given character map" do
60
+ SecureRandom.stub(:random_number).and_return(0)
61
+ @klass.tokenize :token, :characters => ['x']
62
+ @klass.create.token.should == 'xxxxxxxx'
63
+ end
58
64
  end
metadata CHANGED
@@ -1,30 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ar-tokens
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
5
- prerelease:
4
+ version: 0.0.5
6
5
  platform: ruby
7
6
  authors:
8
7
  - Paul Spieker
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-12-28 00:00:00.000000000 Z
11
+ date: 2013-09-25 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activerecord
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  description: This gem lets you easily generate tokens on ruby objects and provides
@@ -36,7 +33,9 @@ extensions: []
36
33
  extra_rdoc_files: []
37
34
  files:
38
35
  - .gitignore
36
+ - .travis.yml
39
37
  - Gemfile
38
+ - MIT-LICENSE
40
39
  - README.markdown
41
40
  - Rakefile
42
41
  - ar-tokens.gemspec
@@ -51,31 +50,29 @@ files:
51
50
  - spec/support/active_record.rb
52
51
  homepage: https://github.com/spieker/tokens
53
52
  licenses: []
53
+ metadata: {}
54
54
  post_install_message:
55
55
  rdoc_options: []
56
56
  require_paths:
57
57
  - lib
58
58
  required_ruby_version: !ruby/object:Gem::Requirement
59
- none: false
60
59
  requirements:
61
- - - ! '>='
60
+ - - '>='
62
61
  - !ruby/object:Gem::Version
63
62
  version: '0'
64
63
  required_rubygems_version: !ruby/object:Gem::Requirement
65
- none: false
66
64
  requirements:
67
- - - ! '>='
65
+ - - '>='
68
66
  - !ruby/object:Gem::Version
69
67
  version: '0'
70
68
  requirements: []
71
69
  rubyforge_project: tokens
72
- rubygems_version: 1.8.24
70
+ rubygems_version: 2.0.5
73
71
  signing_key:
74
- specification_version: 3
72
+ specification_version: 4
75
73
  summary: Generating tokens on ruby objects and active record columns
76
74
  test_files:
77
75
  - spec/active_record_spec.rb
78
76
  - spec/object_spec.rb
79
77
  - spec/spec_helper.rb
80
78
  - spec/support/active_record.rb
81
- has_rdoc: