mongo_mapper-token_keys 0.1.0

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: 3273be071c93636df1e9002f5f6022e80736ab1b
4
+ data.tar.gz: 2f34e7ab2785c56c8fcce384e77dc39622016968
5
+ SHA512:
6
+ metadata.gz: 2d2fd2f8dc6cb0b8a23257ec477754be6f965ef23ef9a13d1d389f41961a37b82315161b0d25c00724c69d3acc1d910b6769394c65c62d74df793416f6cecf82
7
+ data.tar.gz: 7d29c7c307f66e269a54b5ab80383d75115e95c5a3492cafd084a219926bf5f019e141398f7ff2798ca2c836995e65ec85849a83256ef2bfd2cd45ed1d28a182
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mongomapper-tokenkeys.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Michael Bleigh
2
+
3
+ MIT License
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
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # MongoMapper::TokenKeys
2
+
3
+ MongoMapper::TokenKeys provides a simple way to add randomized, url safe tokens to
4
+ your MongoMapper models. Formerly a [gem in a gist](https://gist.github.com/mbleigh/1428845),
5
+ it's now a full-blown RubyGem.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'mongomapper-tokenkeys'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install mongomapper-tokenkeys
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ require 'mongo_mapper/token_keys'
25
+
26
+ class User
27
+ key :name
28
+ token :api_token, size: 30
29
+ end
30
+
31
+ user = User.create(name: 'Bob')
32
+ user.api_token # => 2Hj5GGvWsyI78yCe8j8uOSfDP0w2yWhJBJ0Y9EmS
33
+ ```
34
+
35
+ ## License
36
+
37
+ Copyright (c) 2011-2013 Michael Bleigh
38
+
39
+ Permission is hereby granted, free of charge, to any person obtaining a copy
40
+ of this software and associated documentation files (the "Software"), to deal
41
+ in the Software without restriction, including without limitation the rights
42
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
43
+ copies of the Software, and to permit persons to whom the Software is
44
+ furnished to do so, subject to the following conditions:
45
+
46
+ The above copyright notice and this permission notice shall be included in
47
+ all copies or substantial portions of the Software.
48
+
49
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
50
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
51
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
52
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
53
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
54
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
55
+ THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+ RSpec::Core::RakeTask.new
4
+
5
+ task default: :spec
@@ -0,0 +1,36 @@
1
+ require "mongo_mapper/token_keys/version"
2
+
3
+ require 'mongo_mapper'
4
+ require 'securerandom'
5
+
6
+ module MongoMapper
7
+ module TokenKeys
8
+ extend ActiveSupport::Concern
9
+ DEFAULT_SIZE = 20
10
+
11
+ def self.generate(size = DEFAULT_SIZE)
12
+ SecureRandom.urlsafe_base64(size)
13
+ end
14
+
15
+ module ClassMethods
16
+ def tokens
17
+ @tokens ||= {}
18
+ end
19
+
20
+ def token(name, options = {})
21
+ key name, String, options
22
+ tokens[name.to_sym] = options.delete(:size) || DEFAULT_SIZE
23
+
24
+ if tokens.size == 1
25
+ before_validation(:on => :create) do
26
+ self.class.tokens.each_pair do |token, size|
27
+ self[token] ||= MongoMapper::TokenKeys.generate(size)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ MongoMapper::Document.plugin(MongoMapper::TokenKeys)
@@ -0,0 +1,5 @@
1
+ module MongoMapper
2
+ module TokenKeys
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mongo_mapper/token_keys/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'mongo_mapper-token_keys'
8
+ s.version = MongoMapper::TokenKeys::VERSION
9
+ s.author = 'Michael Bleigh'
10
+ s.email = 'mbleigh@mbleigh.com'
11
+ s.summary = 'Add simple autogenerated tokens to your MongoMapper models.'
12
+ s.description = 'Add simple autogenerated tokens to your MongoMapper models.'
13
+ s.homepage = 'https://github.com/mbleigh/mongo_mapper-token_keys'
14
+ s.license = 'MIT'
15
+
16
+ s.files = `git ls-files`.split($/)
17
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency('mongo_mapper')
22
+ s.add_development_dependency('rspec', ["~> 2.0"])
23
+ end
24
+
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe MongoMapper::TokenKeys do
4
+ let(:doc){ k = Class.new; k.send(:include, MongoMapper::Document); k }
5
+
6
+ it 'should be available by default on documents' do
7
+ doc.ancestors.should be_include(MongoMapper::TokenKeys)
8
+ end
9
+
10
+ it 'should provide a .token method' do
11
+ doc.should be_respond_to(:token)
12
+ end
13
+
14
+ it 'should call through to .key when token is called' do
15
+ doc.should_receive(:key).with(:example, String, {})
16
+ doc.token :example
17
+ end
18
+
19
+ it 'should keep track of the token (and any supplied size)' do
20
+ doc.token :first
21
+ doc.token :second, :size => 10
22
+
23
+ doc.tokens.should == {:first => MongoMapper::TokenKeys::DEFAULT_SIZE, :second => 10}
24
+ end
25
+
26
+ it 'should automatically generate tokens on validation' do
27
+ doc.token :example
28
+ instance = doc.new
29
+ MongoMapper::TokenKeys.should_receive(:generate).with(MongoMapper::TokenKeys::DEFAULT_SIZE).and_return('abc')
30
+ instance.example.should be_nil
31
+ instance.valid?
32
+ instance.example.should == 'abc'
33
+ end
34
+ end
@@ -0,0 +1,22 @@
1
+ require 'bundler'
2
+ Bundler.setup :default, :test
3
+
4
+ require 'mongo_mapper/token_keys'
5
+
6
+ # This file was generated by the `rspec --init` command. Conventionally, all
7
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
8
+ # Require this file using `require "spec_helper"` to ensure that it is only
9
+ # loaded once.
10
+ #
11
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
12
+ RSpec.configure do |config|
13
+ config.treat_symbols_as_metadata_keys_with_true_values = true
14
+ config.run_all_when_everything_filtered = true
15
+ config.filter_run :focus
16
+
17
+ # Run specs in random order to surface order dependencies. If you find an
18
+ # order dependency and want to debug it, you can fix the order by providing
19
+ # the seed, which is printed after each run.
20
+ # --seed 1234
21
+ config.order = 'random'
22
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mongo_mapper-token_keys
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Michael Bleigh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mongo_mapper
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
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ description: Add simple autogenerated tokens to your MongoMapper models.
42
+ email: mbleigh@mbleigh.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - .gitignore
48
+ - .rspec
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - lib/mongo_mapper/token_keys.rb
54
+ - lib/mongo_mapper/token_keys/version.rb
55
+ - mongo_mapper-token_keys.gemspec
56
+ - spec/mongo_mapper/token_keys_spec.rb
57
+ - spec/spec_helper.rb
58
+ homepage: https://github.com/mbleigh/mongo_mapper-token_keys
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.0.3
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Add simple autogenerated tokens to your MongoMapper models.
82
+ test_files:
83
+ - spec/mongo_mapper/token_keys_spec.rb
84
+ - spec/spec_helper.rb