devise_uid 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in devise_uid.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Jingwen Owen Ou
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,62 @@
1
+ # devise_uid
2
+
3
+ Add UID stupport to Devise.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'devise'
10
+ gem 'devise_uid'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ ### Automatic Installation
17
+
18
+ Add devise_uid to any of your Devise models using the
19
+ following generator:
20
+
21
+ rails generate devise_uid MODEL
22
+
23
+ Replace MODEL with the class name you want to add devise_uid.
24
+ This will add the :uid flag to your model's Devise modules.
25
+ The generator will also create a migration file.
26
+ Currently only ActiveRecord is supported.
27
+
28
+ ### Manual Installation
29
+
30
+ Add `:uid` to the `devise` call in your model:
31
+
32
+ ```ruby
33
+ class User < ActiveRecord
34
+ devise :database_authenticable, :confirmable, :uid
35
+ end
36
+ ```
37
+
38
+ Add `uid` field to your Devise model migration:
39
+
40
+ ```ruby
41
+ class AddUidToUser< ActiveRecord::Migration
42
+ add_column :users, :uid, :string
43
+ add_index :users, :uid, :unique => true
44
+ end
45
+ ```
46
+
47
+ ## Usage
48
+
49
+ An uid is generated when a Devise MODEL is created. Access it like this:
50
+
51
+ ```ruby
52
+ user = User.create(email: "foo@bar.com")
53
+ puts user.uid
54
+ ```
55
+
56
+ ## Contributing
57
+
58
+ 1. Fork it
59
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
60
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
61
+ 4. Push to the branch (`git push origin my-new-feature`)
62
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ desc "Run specs"
7
+ task :default => :spec
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'devise_uid/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "devise_uid"
8
+ gem.version = DeviseUid::VERSION
9
+ gem.authors = ["Jingwen Owen Ou"]
10
+ gem.email = ["jingweno@gmail.com"]
11
+ gem.description = %q{Add UID stupport to Devise}
12
+ gem.summary = %q{Add UID stupport to Devise}
13
+ gem.homepage = "https://github.com/jingweno/devise_uid"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency("devise", "~> 2.1.2")
21
+ gem.add_dependency("railties", "~> 3.0")
22
+
23
+ gem.add_development_dependency "rspec", "~> 2.12"
24
+ gem.add_development_dependency "activerecord", "~> 3.0"
25
+ gem.add_development_dependency "sqlite3", "~> 1.3.6"
26
+ end
@@ -0,0 +1,23 @@
1
+ module Devise
2
+ module Models
3
+ module Uid
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ before_save :generate_uid
8
+ end
9
+
10
+ module ClassMethods
11
+ def uid
12
+ generate_token(:uid)
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def generate_uid
19
+ self.uid = self.class.uid if self.uid.nil?
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module DeviseUid
2
+ VERSION = "0.0.1"
3
+ end
data/lib/devise_uid.rb ADDED
@@ -0,0 +1,4 @@
1
+ require "devise_uid/version"
2
+ require "devise"
3
+
4
+ Devise.add_module :uid, :model => "devise_uid/model"
@@ -0,0 +1,13 @@
1
+ require 'rails/generators/active_record'
2
+
3
+ module ActiveRecord
4
+ module Generators
5
+ class DeviseUidGenerator < ActiveRecord::Generators::Base
6
+ source_root File.expand_path("../templates", __FILE__)
7
+
8
+ def copy_devise_migration
9
+ migration_template "migration.rb", "db/migrate/devise_uid_add_to_#{table_name}"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,6 @@
1
+ class DeviseUidAddTo<%= table_name.camelize %> < ActiveRecord::Migration
2
+ def change
3
+ add_column :users, :uid, :string
4
+ add_index :users, :uid, :unique => true
5
+ end
6
+ end
@@ -0,0 +1,16 @@
1
+ module DeviseUid
2
+ module Generators
3
+ class DeviseUidGenerator < Rails::Generators::NamedBase
4
+ namespace "devise_uid"
5
+
6
+ desc "Add :uid directive in the given model. Also generate migration for ActiveRecord"
7
+
8
+ def inject_devise_invitable_content
9
+ path = File.join("app", "models", "#{file_path}.rb")
10
+ inject_into_file(path, "uid, :", :after => "devise :") if File.exists?(path)
11
+ end
12
+
13
+ hook_for :orm
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,25 @@
1
+ class CreateTables < ActiveRecord::Migration
2
+ def change
3
+ create_table :users do |t|
4
+ ## Database authenticatable
5
+ t.string :email, :null => true, :default => ""
6
+ t.string :encrypted_password, :null => true, :default => ""
7
+
8
+ ## Recoverable
9
+ t.string :reset_password_token
10
+ t.datetime :reset_password_sent_at
11
+
12
+ ## Confirmable
13
+ t.string :confirmation_token
14
+ t.datetime :confirmed_at
15
+ t.datetime :confirmation_sent_at
16
+ t.string :unconfirmed_email # Only if using reconfirmable
17
+
18
+ # uid
19
+ t.string :uid
20
+
21
+ t.timestamps
22
+ end
23
+ add_index :users, :uid, :unique => true
24
+ end
25
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ class User < ActiveRecord::Base
4
+ devise :uid
5
+ end
6
+
7
+ describe User do
8
+ it "generates uid before save" do
9
+ user = User.create!(email: "foo@bar.com")
10
+ user.uid.should be
11
+ end
12
+
13
+ it "doesn't generate uid if it has it" do
14
+ user = User.create!(email: "foo@bar.com")
15
+ uid = user.uid
16
+
17
+ user.update_attributes(email: "bar@baz.com")
18
+ user.uid.should == uid
19
+ end
20
+ end
@@ -0,0 +1,18 @@
1
+ $:.unshift File.expand_path("..", __FILE__)
2
+ $:.unshift File.expand_path("../../lib", __FILE__)
3
+
4
+ require "rspec"
5
+ require "devise_uid"
6
+ require "devise/orm/active_record"
7
+ require "active_record"
8
+
9
+ ActiveRecord::Migration.verbose = false
10
+ ActiveRecord::Base.logger = Logger.new(nil)
11
+ ActiveRecord::Base.establish_connection(
12
+ :adapter => "sqlite3",
13
+ :database => ":memory:",
14
+ :pool => 5)
15
+ ActiveRecord::Migrator.migrate(File.expand_path("../db/migrate/", __FILE__))
16
+
17
+ RSpec.configure do |config|
18
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: devise_uid
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jingwen Owen Ou
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: devise
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.1.2
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 2.1.2
30
+ - !ruby/object:Gem::Dependency
31
+ name: railties
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '3.0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '3.0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '2.12'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.12'
62
+ - !ruby/object:Gem::Dependency
63
+ name: activerecord
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '3.0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '3.0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: sqlite3
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 1.3.6
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 1.3.6
94
+ description: Add UID stupport to Devise
95
+ email:
96
+ - jingweno@gmail.com
97
+ executables: []
98
+ extensions: []
99
+ extra_rdoc_files: []
100
+ files:
101
+ - .gitignore
102
+ - Gemfile
103
+ - LICENSE.txt
104
+ - README.md
105
+ - Rakefile
106
+ - devise_uid.gemspec
107
+ - lib/devise_uid.rb
108
+ - lib/devise_uid/model.rb
109
+ - lib/devise_uid/version.rb
110
+ - lib/generators/active_record/devise_uid_generator.rb
111
+ - lib/generators/active_record/templates/migration.rb
112
+ - lib/generators/devise_uid/devise_uid_generator.rb
113
+ - spec/db/migrate/20100401102949_create_tables.rb
114
+ - spec/devise_uid/model_spec.rb
115
+ - spec/spec_helper.rb
116
+ homepage: https://github.com/jingweno/devise_uid
117
+ licenses: []
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ! '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ segments:
129
+ - 0
130
+ hash: -1643572958233822709
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ none: false
133
+ requirements:
134
+ - - ! '>='
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ segments:
138
+ - 0
139
+ hash: -1643572958233822709
140
+ requirements: []
141
+ rubyforge_project:
142
+ rubygems_version: 1.8.24
143
+ signing_key:
144
+ specification_version: 3
145
+ summary: Add UID stupport to Devise
146
+ test_files:
147
+ - spec/db/migrate/20100401102949_create_tables.rb
148
+ - spec/devise_uid/model_spec.rb
149
+ - spec/spec_helper.rb