has_tokens 1.0.1 → 3.27.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.
- checksums.yaml +7 -0
- data/.travis.yml +4 -3
- data/License.txt +23 -0
- data/README.md +73 -0
- data/has_tokens.gemspec +2 -1
- data/lib/has_tokens/version.rb +1 -1
- data/spec/active_record_integration_spec.rb +6 -6
- data/spec/creating_tokens_spec.rb +8 -8
- metadata +22 -18
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 49cf2386311a83a572118003ee32cf0ab8bbc8d5
|
4
|
+
data.tar.gz: f54d39e626d21e97eb9b98d52185825ffbe936bf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7685cbc160a9c8ea0eabf2b4ca37097d4c49486cfd844abe7358fe66f01f9a03dc3ecfa7d6b928b6f1fb9f111ca6025b61599e3cad65e6d26491d228ebbf6c1b
|
7
|
+
data.tar.gz: 519f51e9d085da61a621402eaa3b99f184aec77359383728c6c41d9db694e177f16b756693efa82aa301d2fe1eb55b96396878faf244d892363f39ab78081f95
|
data/.travis.yml
CHANGED
data/License.txt
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
(The MIT License)
|
2
|
+
|
3
|
+
Copyright (c) 2012 Corey Haines and Josh Cheek
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
19
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
20
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
21
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
22
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
|
data/README.md
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
[](https://travis-ci.org/coreyhaines/has_tokens)
|
2
|
+
[](https://codeclimate.com/github/coreyhaines/has_tokens)
|
3
|
+
|
4
|
+
Has Tokens
|
5
|
+
==========
|
6
|
+
|
7
|
+
Creates tokens for accessing ActiveRecord objects. Allows you to declaratively specify token-based access for your ActiveRecord objects.
|
8
|
+
|
9
|
+
Under the covers, has_tokens uses SecureRandom.hex so they'll be all "c07a2". The size is configurable, so if you need a token that is trillions of characters long, you can make that happen, man.
|
10
|
+
|
11
|
+
Install
|
12
|
+
-------
|
13
|
+
|
14
|
+
```
|
15
|
+
gem install has_tokens
|
16
|
+
```
|
17
|
+
|
18
|
+
|
19
|
+
Active Record Implementation
|
20
|
+
-------------------
|
21
|
+
|
22
|
+
1. Create a Migration to add a string "public_token" to your model
|
23
|
+
2. Index that public_token field
|
24
|
+
|
25
|
+
```
|
26
|
+
class YourSuperActiveRecordClass < ActiveRecord::Base
|
27
|
+
HasTokens.on self
|
28
|
+
has_tokens public: 5
|
29
|
+
|
30
|
+
before_validation :generate_tokens, on: :create
|
31
|
+
validates_uniqueness_of :public_token
|
32
|
+
|
33
|
+
def self.for_token(token)
|
34
|
+
find_by_public_token!(token)
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_param
|
38
|
+
public_token
|
39
|
+
end
|
40
|
+
end
|
41
|
+
```
|
42
|
+
|
43
|
+
Now, your urls will be tokenized "/models/5245c"
|
44
|
+
|
45
|
+
Note, if you have a bunch of models, you'll want to generate tokens for each using generate_tokens (and then save the model).
|
46
|
+
|
47
|
+
So, you first include has_tokens in your class with `HasTokens.on self`. Then, the has_tokens will define your public_token method.
|
48
|
+
|
49
|
+
|
50
|
+
PORO (ruby object) Implementation
|
51
|
+
------------------------------
|
52
|
+
|
53
|
+
```
|
54
|
+
class YourHipsterClass
|
55
|
+
HasTokens.on self
|
56
|
+
has_tokens public: 5
|
57
|
+
def initialize
|
58
|
+
generate_tokens
|
59
|
+
end
|
60
|
+
end
|
61
|
+
```
|
62
|
+
|
63
|
+
You know, or whatever.
|
64
|
+
|
65
|
+
Authors
|
66
|
+
-------
|
67
|
+
|
68
|
+
[Corey Haines](https://github.com/coreyhaines) and [Josh Cheek](https://github.com/joshcheek)
|
69
|
+
|
70
|
+
License
|
71
|
+
-------
|
72
|
+
|
73
|
+
Please see [License.txt](/License.txt)
|
data/has_tokens.gemspec
CHANGED
@@ -7,9 +7,10 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.version = HasTokens::VERSION
|
8
8
|
s.authors = ["coreyhaines", "josh cheek"]
|
9
9
|
s.email = ["coreyhaines@gmail.com", "josh.cheek@gmail.com"]
|
10
|
-
s.homepage = ""
|
10
|
+
s.homepage = "https://github.com/coreyhaines/has_tokens"
|
11
11
|
s.summary = %q{Creates tokens for accessing ActiveRecord objects}
|
12
12
|
s.description = %q{Allows you to declaratively specify token-based access for your ActiveRecord objects.}
|
13
|
+
s.license = "MIT"
|
13
14
|
|
14
15
|
s.rubyforge_project = "has_tokens"
|
15
16
|
|
data/lib/has_tokens/version.rb
CHANGED
@@ -10,11 +10,11 @@ end
|
|
10
10
|
|
11
11
|
describe "Looking up by the tokens with for_<token_name>" do
|
12
12
|
it "calls the appropriate ActiveRecord finder" do
|
13
|
-
admin_version =
|
14
|
-
ActiveRecordDummyWithTokens.
|
15
|
-
ActiveRecordDummyWithTokens.for_admin("admin_token").
|
16
|
-
public_version =
|
17
|
-
ActiveRecordDummyWithTokens.
|
18
|
-
ActiveRecordDummyWithTokens.for_public("public_token").
|
13
|
+
admin_version = double
|
14
|
+
expect(ActiveRecordDummyWithTokens).to receive(:find_by_admin_token!).with("admin_token") { admin_version }
|
15
|
+
expect(ActiveRecordDummyWithTokens.for_admin("admin_token")).to be(admin_version)
|
16
|
+
public_version = double
|
17
|
+
expect(ActiveRecordDummyWithTokens).to receive(:find_by_public_token!).with("public_token") { public_version }
|
18
|
+
expect(ActiveRecordDummyWithTokens.for_public("public_token")).to be(public_version)
|
19
19
|
end
|
20
20
|
end
|
@@ -16,18 +16,18 @@ describe "Creating a single token with #generate_tokens" do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
it "sets the appropriate token property" do
|
19
|
-
tokened.public_token.
|
19
|
+
expect(tokened.public_token).not_to be_nil
|
20
20
|
end
|
21
21
|
|
22
22
|
describe "the generated token" do
|
23
23
|
it 'is unique' do
|
24
24
|
tokened2 = WantsOneToken.new
|
25
25
|
tokened2.generate_tokens
|
26
|
-
tokened.public_token.
|
26
|
+
expect(tokened.public_token).not_to eq(tokened2.public_token)
|
27
27
|
end
|
28
28
|
|
29
29
|
it "has the length that was given" do
|
30
|
-
tokened.public_token.length.
|
30
|
+
expect(tokened.public_token.length).to eq(5)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
@@ -47,19 +47,19 @@ describe "Creating multiple tokens with #generate_tokens" do
|
|
47
47
|
end
|
48
48
|
|
49
49
|
it "sets all the token properties" do
|
50
|
-
tokened.public_token.
|
51
|
-
tokened.admin_token.
|
50
|
+
expect(tokened.public_token).not_to be_nil
|
51
|
+
expect(tokened.admin_token).not_to be_nil
|
52
52
|
end
|
53
53
|
|
54
54
|
it "has the length that was given for each token" do
|
55
|
-
tokened.public_token.length.
|
56
|
-
tokened.admin_token.length.
|
55
|
+
expect(tokened.public_token.length).to eq(5)
|
56
|
+
expect(tokened.admin_token.length).to eq(10)
|
57
57
|
end
|
58
58
|
|
59
59
|
it "does not over-write an existing token" do
|
60
60
|
tokened = WantsMultipleTokens.new
|
61
61
|
tokened.admin_token = "existing"
|
62
62
|
tokened.generate_tokens
|
63
|
-
tokened.admin_token.
|
63
|
+
expect(tokened.admin_token).to eq("existing")
|
64
64
|
end
|
65
65
|
end
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: has_tokens
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
5
|
-
prerelease:
|
4
|
+
version: 3.27.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- coreyhaines
|
@@ -10,19 +9,22 @@ authors:
|
|
10
9
|
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date:
|
12
|
+
date: 2015-02-14 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: rspec
|
17
|
-
requirement:
|
18
|
-
none: false
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
19
17
|
requirements:
|
20
|
-
- -
|
18
|
+
- - ">="
|
21
19
|
- !ruby/object:Gem::Version
|
22
20
|
version: '0'
|
23
21
|
type: :development
|
24
22
|
prerelease: false
|
25
|
-
version_requirements:
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
26
28
|
description: Allows you to declaratively specify token-based access for your ActiveRecord
|
27
29
|
objects.
|
28
30
|
email:
|
@@ -32,39 +34,41 @@ executables: []
|
|
32
34
|
extensions: []
|
33
35
|
extra_rdoc_files: []
|
34
36
|
files:
|
35
|
-
- .gitignore
|
36
|
-
- .rspec
|
37
|
-
- .travis.yml
|
37
|
+
- ".gitignore"
|
38
|
+
- ".rspec"
|
39
|
+
- ".travis.yml"
|
38
40
|
- Gemfile
|
41
|
+
- License.txt
|
42
|
+
- README.md
|
39
43
|
- Rakefile
|
40
44
|
- has_tokens.gemspec
|
41
45
|
- lib/has_tokens.rb
|
42
46
|
- lib/has_tokens/version.rb
|
43
47
|
- spec/active_record_integration_spec.rb
|
44
48
|
- spec/creating_tokens_spec.rb
|
45
|
-
homepage:
|
46
|
-
licenses:
|
49
|
+
homepage: https://github.com/coreyhaines/has_tokens
|
50
|
+
licenses:
|
51
|
+
- MIT
|
52
|
+
metadata: {}
|
47
53
|
post_install_message:
|
48
54
|
rdoc_options: []
|
49
55
|
require_paths:
|
50
56
|
- lib
|
51
57
|
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
-
none: false
|
53
58
|
requirements:
|
54
|
-
- -
|
59
|
+
- - ">="
|
55
60
|
- !ruby/object:Gem::Version
|
56
61
|
version: '0'
|
57
62
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
-
none: false
|
59
63
|
requirements:
|
60
|
-
- -
|
64
|
+
- - ">="
|
61
65
|
- !ruby/object:Gem::Version
|
62
66
|
version: '0'
|
63
67
|
requirements: []
|
64
68
|
rubyforge_project: has_tokens
|
65
|
-
rubygems_version:
|
69
|
+
rubygems_version: 2.4.5
|
66
70
|
signing_key:
|
67
|
-
specification_version:
|
71
|
+
specification_version: 4
|
68
72
|
summary: Creates tokens for accessing ActiveRecord objects
|
69
73
|
test_files:
|
70
74
|
- spec/active_record_integration_spec.rb
|