devise_couch_potato 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +31 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/devise_couch_potato.gemspec +53 -0
- data/lib/devise/orm/couch_potato/schema.rb +38 -0
- data/lib/devise/orm/couch_potato.rb +58 -0
- data/lib/devise_couch_potato.rb +0 -0
- data/test/helper.rb +10 -0
- data/test/test_devise_couch_potato.rb +7 -0
- metadata +75 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Andi Bade
|
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.rdoc
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
= devise_couch_potato
|
2
|
+
|
3
|
+
add
|
4
|
+
|
5
|
+
require 'devise/orm/couch_potato'
|
6
|
+
|
7
|
+
to your devise config (devise.rb)
|
8
|
+
|
9
|
+
class User
|
10
|
+
include CouchPotato::Persistence
|
11
|
+
include Devise::Orm::CouchPotato
|
12
|
+
|
13
|
+
devise :database_authenticatable, :registerable,
|
14
|
+
:recoverable, :rememberable, :trackable, :validatable
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
== Note on Patches/Pull Requests
|
20
|
+
|
21
|
+
* Fork the project.
|
22
|
+
* Make your feature addition or bug fix.
|
23
|
+
* Add tests for it. This is important so I don't break it in a
|
24
|
+
future version unintentionally.
|
25
|
+
* Commit, do not mess with rakefile, version, or history.
|
26
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
27
|
+
* Send me a pull request. Bonus points for topic branches.
|
28
|
+
|
29
|
+
== Copyright
|
30
|
+
|
31
|
+
Copyright (c) 2010 Andi Bade. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "devise_couch_potato"
|
8
|
+
gem.summary = %Q{use couch_potato with devise}
|
9
|
+
gem.description = %Q{this gem enables devise for couch_potato models}
|
10
|
+
gem.email = "andi@galaxycats.com"
|
11
|
+
gem.homepage = "http://github.com/galaxycats/devise_couch_potato"
|
12
|
+
gem.authors = ["Andi Bade"]
|
13
|
+
# gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'rake/testtask'
|
22
|
+
Rake::TestTask.new(:test) do |test|
|
23
|
+
test.libs << 'lib' << 'test'
|
24
|
+
test.pattern = 'test/**/test_*.rb'
|
25
|
+
test.verbose = true
|
26
|
+
end
|
27
|
+
|
28
|
+
begin
|
29
|
+
require 'rcov/rcovtask'
|
30
|
+
Rcov::RcovTask.new do |test|
|
31
|
+
test.libs << 'test'
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
rescue LoadError
|
36
|
+
task :rcov do
|
37
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
task :test => :check_dependencies
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "devise_couch_potato #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{devise_couch_potato}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Andi Bade"]
|
12
|
+
s.date = %q{2010-10-11}
|
13
|
+
s.description = %q{this gem enables devise for couch_potato models}
|
14
|
+
s.email = %q{andi@galaxycats.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"devise_couch_potato.gemspec",
|
27
|
+
"lib/devise/orm/couch_potato.rb",
|
28
|
+
"lib/devise/orm/couch_potato/schema.rb",
|
29
|
+
"lib/devise_couch_potato.rb",
|
30
|
+
"test/helper.rb",
|
31
|
+
"test/test_devise_couch_potato.rb"
|
32
|
+
]
|
33
|
+
s.homepage = %q{http://github.com/galaxycats/devise_couch_potato}
|
34
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
35
|
+
s.require_paths = ["lib"]
|
36
|
+
s.rubygems_version = %q{1.3.6}
|
37
|
+
s.summary = %q{use couch_potato with devise}
|
38
|
+
s.test_files = [
|
39
|
+
"test/helper.rb",
|
40
|
+
"test/test_devise_couch_potato.rb"
|
41
|
+
]
|
42
|
+
|
43
|
+
if s.respond_to? :specification_version then
|
44
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
45
|
+
s.specification_version = 3
|
46
|
+
|
47
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
48
|
+
else
|
49
|
+
end
|
50
|
+
else
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Devise
|
2
|
+
module Orm
|
3
|
+
module CouchPotato
|
4
|
+
module Schema
|
5
|
+
include Devise::Schema
|
6
|
+
# Tell how to apply schema methods.
|
7
|
+
def apply_devise_schema(name, type, options={})
|
8
|
+
return unless Devise.apply_schema
|
9
|
+
if [Date, DateTime].include?(type)
|
10
|
+
property name, options.merge({ :type => Time })
|
11
|
+
else
|
12
|
+
property name, options
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def find_for_authentication(conditions)
|
17
|
+
find(:conditions => conditions)
|
18
|
+
end
|
19
|
+
|
20
|
+
def find(*args)
|
21
|
+
options = args.extract_options!
|
22
|
+
raise "You can't search with more than one condition yet =(" if options[:conditions].keys.size > 1
|
23
|
+
find_by_key_and_value(options[:conditions].keys.first, options[:conditions].values.first)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def find_by_key_and_value(key, value)
|
29
|
+
if key == :id
|
30
|
+
::CouchPotato.database.load(value.to_s)
|
31
|
+
else
|
32
|
+
::CouchPotato.database.view(send("by_#{key}", {:key => value.to_s, :limit => 1})).first
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'devise/orm/couch_potato/schema'
|
2
|
+
|
3
|
+
module Devise
|
4
|
+
module Orm
|
5
|
+
module CouchPotato
|
6
|
+
module ClassMethods
|
7
|
+
def validates_uniqueness_of(*args)
|
8
|
+
options = args.extract_options!
|
9
|
+
attrib = args.first.to_s
|
10
|
+
|
11
|
+
if self.respond_to?("by_#{attrib}")
|
12
|
+
validate "uniqueness_of_#{attrib}".to_sym
|
13
|
+
define_method "uniqueness_of_#{attrib}" do
|
14
|
+
unless self.class.find(:conditions => { attrib => self.send(attrib) }).nil?
|
15
|
+
self.errors.add(attrib, options[:message] || :taken)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
else
|
19
|
+
Rails.logger.warn "WARNING you tried to validate uniqueness of #{attrib} but no view named 'by_#{attrib}' exists. Validation could not be added."
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def devise_modules_hook!
|
24
|
+
create_authentication_views
|
25
|
+
yield
|
26
|
+
return unless Devise.apply_schema
|
27
|
+
devise_modules.each { |m| send(m) if respond_to?(m, true) }
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
def create_authentication_views
|
32
|
+
authentication_keys.each do |key_name|
|
33
|
+
view "by_#{key_name}", :key => key_name
|
34
|
+
end
|
35
|
+
|
36
|
+
view :by_confirmation_token, :key => :confirmation_token
|
37
|
+
view :by_authentication_token, :key => :authentication_token
|
38
|
+
view :by_reset_password_token, :key => :reset_password_token
|
39
|
+
view :by_unlock_token, :key => :unlock_token
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
module InstanceMethods
|
45
|
+
def save(options = nil)
|
46
|
+
::CouchPotato.database.save(self)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.included(receiver)
|
51
|
+
receiver.extend ::Devise::Models
|
52
|
+
receiver.extend ClassMethods
|
53
|
+
receiver.extend Schema
|
54
|
+
receiver.send(:include, InstanceMethods)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
File without changes
|
data/test/helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: devise_couch_potato
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Andi Bade
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-10-11 00:00:00 +02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: this gem enables devise for couch_potato models
|
22
|
+
email: andi@galaxycats.com
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files:
|
28
|
+
- LICENSE
|
29
|
+
- README.rdoc
|
30
|
+
files:
|
31
|
+
- .document
|
32
|
+
- .gitignore
|
33
|
+
- LICENSE
|
34
|
+
- README.rdoc
|
35
|
+
- Rakefile
|
36
|
+
- VERSION
|
37
|
+
- devise_couch_potato.gemspec
|
38
|
+
- lib/devise/orm/couch_potato.rb
|
39
|
+
- lib/devise/orm/couch_potato/schema.rb
|
40
|
+
- lib/devise_couch_potato.rb
|
41
|
+
- test/helper.rb
|
42
|
+
- test/test_devise_couch_potato.rb
|
43
|
+
has_rdoc: true
|
44
|
+
homepage: http://github.com/galaxycats/devise_couch_potato
|
45
|
+
licenses: []
|
46
|
+
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options:
|
49
|
+
- --charset=UTF-8
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
version: "0"
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
version: "0"
|
66
|
+
requirements: []
|
67
|
+
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 1.3.6
|
70
|
+
signing_key:
|
71
|
+
specification_version: 3
|
72
|
+
summary: use couch_potato with devise
|
73
|
+
test_files:
|
74
|
+
- test/helper.rb
|
75
|
+
- test/test_devise_couch_potato.rb
|