Permalink
Browse files

modify schema module

  • Loading branch information...
1 parent c2164da commit 8708b6b32d2a3250e28a5588c46561f247c8cd49 @shenoudab committed Sep 27, 2010
View
@@ -5,7 +5,7 @@ gem 'rails'
gem 'devise', :git => 'git://github.com/plataformatec/devise.git'
gem 'couchrest', :git => 'git://github.com/couchrest/couchrest.git'
-gem 'couchrest_model', :git => 'git://github.com/shenoudab/couchrest_model.git'
+gem 'couchrest_model', :git => 'git://github.com/couchrest/couchrest_model.git'
gem 'oauth2'
View
@@ -7,8 +7,6 @@
Add *devise*, *devise_couch* and *couchrest_model* gems to your Gemfile (your Rails app Gemfile). The following gems are required
<pre>
- gem 'couchrest'
- gem 'couchrest_extended_document'
gem 'couchrest_model'
gem 'devise'
gem 'devise_couch'
View
@@ -0,0 +1,17 @@
+# -*- encoding: utf-8 -*-
+lib = File.expand_path('../lib/', __FILE__)
+$:.unshift lib unless $:.include?(lib)
+
+require 'devise_couch/version'
+
+Gem::Specification.new do |s|
+ s.name = "devise_couch"
+ s.summary = "CouchDB integration for Devise framework"
+ s.description = "CouchDB integration for Devise authentication framework"
+ s.version = DeviseCouch::VERSION
+ s.email = "sbertel@mobithought.com"
+ s.homepage = "http://github.com/shenoudab/devise_couch"
+ s.author = 'Shenouda Bertel'
+ s.files = Dir.glob("{lib,test}/**/*") + %w(MIT-LICENSE README.markdown Gemfile Rakefile devise_couch.gemspec)
+ s.require_path = 'lib'
+end
@@ -1,25 +1,27 @@
require 'devise_couch'
-require 'devise/orm/couchrest_model/compatibility'
+require 'couchrest_model/schema'
module Devise
module Orm
module CouchrestModel
module Hook
def devise_modules_hook!
extend Schema
- include Compatibility
+ create_authentication_views
yield
return unless Devise.apply_schema
devise_modules.each { |m| send(m) if respond_to?(m, true) }
end
- end
- module Schema
- include Devise::Schema
- # Tell how to apply schema methods.
- def apply_devise_schema(name, type, options={})
- return unless Devise.apply_schema
- property name, type, options
+ private
+ def create_authentication_views
+ authentication_keys.each do |key_name|
+ view_by key_name
+ end
+ view_by :confirmation_token
+ view_by :authentication_token
+ view_by :reset_password_token
+ view_by :unlock_token
end
end
end
@@ -1,26 +0,0 @@
-module Devise
- module Orm
- module CouchrestModel
- module Compatibility
- extend ActiveSupport::Concern
- extend ActiveModel::Naming
-
- module ClassMethods
- def find(*args)
- options = args.extract_options!
- conditions = options[:conditions]
- case authentication_keys.first
- when :login then by_login(:key => conditions[authentication_keys.first]).first
- when :username then by_username(:key => conditions[authentication_keys.first]).first
- when :email then by_email(:key => conditions[authentication_keys.first]).first
- else by_login(:key => conditions[authentication_keys.first]).first
- end
- end
- end
-
- def reload
- end
- end
- end
- end
-end
@@ -0,0 +1,34 @@
+module Devise
+ module Orm
+ module CouchrestModel
+ module Schema
+ include Devise::Schema
+ # Tell how to apply schema methods.
+ def apply_devise_schema(name, type, options={})
+ return unless Devise.apply_schema
+ property name, type, options
+ end
+
+ def find_for_authentication(conditions)
+ find(:conditions => conditions)
+ end
+
+ def find(*args)
+ options = args.extract_options!
+ raise "You can't search with more than one condition yet =(" if options[:conditions].keys.size > 1
+ find_by_key_and_value(options[:conditions].keys.first, options[:conditions].values.first)
+ end
+
+ private
+
+ def find_by_key_and_value(key, value)
+ if key == :id
+ get(value)
+ else
+ send("by_#{key}", {:key => value, :limit => 1}).first
+ end
+ end
+ end
+ end
+ end
+end
@@ -1,3 +1,3 @@
module DeviseCouch
- VERSION = "1.0.0.beta1".freeze
+ VERSION = "1.0.0.beta1"
end

0 comments on commit 8708b6b

Please sign in to comment.