devise_couch 0.1.1 → 0.1.2

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.
data/Gemfile CHANGED
@@ -1,7 +1,7 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
- #gem 'rails', '3.0.0.rc'
4
- gem 'rails', :git => 'git://github.com/rails/rails.git'
3
+ gem 'rails', '3.0.0'
4
+ #gem 'rails', :git => 'git://github.com/rails/rails.git'
5
5
 
6
6
  gem 'warden'
7
7
  gem 'devise', :git => 'git://github.com/plataformatec/devise.git'
@@ -16,4 +16,4 @@ gem 'rails3-generators', :git => 'git://github.com/shenoudab/rails3-generators.g
16
16
 
17
17
  gem 'webrat', '0.7.0'
18
18
  gem 'mocha', :require => false
19
- gem 'bcrypt-ruby', :require => 'bcrypt'
19
+ gem 'bcrypt-ruby', :require => 'bcrypt'
data/README.markdown CHANGED
@@ -2,25 +2,6 @@
2
2
 
3
3
  *devise_couch* will let you use [devise](http://github.com/plataformatec/devise) with [CocuhrestModel](http://github.com/couchrest/couchrest_model).
4
4
 
5
- *devise_couch* is intended for use with *Rails 3* and *Devise 1.1.1*. It may work with earlier versions of devise, but it's not been tested.
6
-
7
- This README only covers *devise_couch* specifics. Make sure to read the [devise README](http://github.com/plataformatec/devise/blob/master/README.rdoc)
8
-
9
- ## Usage options
10
-
11
- The gem gives you the options of 2 ORM setups depending on what library you wish to use for validations:
12
-
13
- * *couchrest_model* - Uses CocuhrestModel validations
14
- * *couchrest_model_active_model* - Uses ActiveModel::Validations
15
-
16
- The advantage to this is ActiveModel's I18n support for error messages, and it uses the same validations lib as devise does by default.
17
-
18
- ## ActiveModel compatibility
19
-
20
- Currently only the <code>couchrest_model</code> option has been tested.
21
- There should be full ActiveModel support in a future version of CocuhrestModel, after Rails 3 is released.
22
- ActiveModel support will likely be part of *CocuhrestModel 1.0* (as mentioned by jnunemaker in a post).
23
-
24
5
  ## Installation
25
6
 
26
7
  Add *devise*, *devise_couch* and *couchrest_model* gems to your Gemfile (your Rails app Gemfile). The following gems are required
@@ -33,10 +14,8 @@ Add *devise*, *devise_couch* and *couchrest_model* gems to your Gemfile (your Ra
33
14
  gem 'devise_couch'
34
15
  gem 'rails3-generators', :git => 'git://github.com/shenoudab/rails3-generators.git'
35
16
  </pre>
36
-
37
- <pre>gem install rails3-generators</pre>
38
17
 
39
- Alternatively use bundler to install all required gems in your Rails 3 app
18
+ Use bundler to install all required gems in your Rails 3 app
40
19
 
41
20
  <pre>bundle install</pre>
42
21
 
@@ -46,7 +25,7 @@ Run the generator:
46
25
 
47
26
  The generator will install an initializer which describes ALL Devise's
48
27
  configuration options and you MUST take a look at it. Make sure to specify
49
- either <code>mongo_mapper</code> or <code>mongo_mapper_active_model</code> (ActiveModel::Validations)
28
+ either <code>couchrest_model</code> (ActiveModel::Validations)
50
29
  as the orm in the configuration file.
51
30
 
52
31
  To add Devise to any of your models using the generator:
data/Rakefile CHANGED
@@ -49,6 +49,7 @@ spec = Gem::Specification.new do |s|
49
49
  s.email = "sbertel@mobithought.com"
50
50
  s.homepage = "http://github.com/shenoudab/devise_couch"
51
51
  s.author = 'Shenouda Bertel'
52
+ s.require_path = 'lib'
52
53
  end
53
54
 
54
55
  Rake::GemPackageTask.new(spec) do |pkg|
@@ -57,4 +58,4 @@ end
57
58
  desc "Install the gem #{spec.name}-#{spec.version}.gem"
58
59
  task :install do
59
60
  system("gem install pkg/#{spec.name}-#{spec.version}.gem --no-ri --no-rdoc")
60
- end
61
+ end
@@ -2,25 +2,9 @@ module Devise
2
2
  module Orm
3
3
  module CouchrestModel
4
4
  module Compatibility
5
- extend ActiveSupport::Concern
6
-
7
5
  extend ActiveSupport::Concern
8
6
  extend ActiveModel::Naming
9
7
 
10
- include ActiveModel::Serializers::Xml
11
- include ActiveModel::Serializers::JSON
12
-
13
- def to_xml(options = {}, &block)
14
- options[:except] ||= []
15
- options[:except] << :_id
16
-
17
- super options do |b|
18
- b.id self.id
19
- block.call(b) if block_given?
20
- end
21
- end
22
-
23
-
24
8
  module ClassMethods
25
9
  # Hooks for confirmable
26
10
  def before_create(*args)
@@ -48,42 +32,8 @@ module Devise
48
32
  METHOD
49
33
  end
50
34
  end
51
-
52
- # Add ActiveRecord like finder
53
- def find(*args)
54
- case args.first
55
- when :first, :all
56
- send(args.shift, *args)
57
- else
58
- where(:'_id' => args.first).first
59
- end
60
- end
61
- end
62
-
63
- # def changed?
64
- # dirty?
65
- # end
66
-
67
- def save(options=nil)
68
- if options.is_a?(Hash) && options[:validate] == false
69
- save!
70
- else
71
- super()
72
- end
73
- end
74
-
75
- def update_attribute(name, value)
76
- update_attributes(name => value)
77
- end
78
- #
79
- # def update_attributes(*args)
80
- # update(*args)
81
- # end
82
-
83
- def invalid?
84
- !valid?
85
35
  end
86
36
  end
87
37
  end
88
38
  end
89
- end
39
+ end
@@ -1,4 +1,5 @@
1
- require "couchrest/model/base"
1
+ require 'couchrest/model/base'
2
+ require 'devise/orm/couchrest_model/compatibility'
2
3
 
3
4
  module Devise
4
5
  module Orm
@@ -6,24 +7,24 @@ module Devise
6
7
  module Hook
7
8
  def devise_modules_hook!
8
9
  extend Schema
9
- #Include Compatibility
10
+ #include Compatibility
10
11
  yield
11
12
  return unless Devise.apply_schema
12
13
  devise_modules.each { |m| send(m) if respond_to?(m, true) }
13
14
  end
14
- end #Hook
15
+ end
15
16
 
16
17
  module Schema
17
18
  include Devise::Schema
18
19
  # Tell how to apply schema methods.
19
20
  def apply_devise_schema(name, type, options={})
20
21
  return unless Devise.apply_schema
21
- property name, :type => type
22
+ property name, type, options
22
23
  end
23
- end #Module Schema
24
- end #CouchRest
25
- end #Orm
26
- end #Devise
24
+ end
25
+ end
26
+ end
27
+ end
27
28
 
28
29
  module CouchRest
29
30
  module Model
@@ -1,5 +1,5 @@
1
1
  module CouchrestModel
2
2
  module Devise
3
- VERSION = "0.1.1".freeze
3
+ VERSION = "0.1.2".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 1
9
- version: 0.1.1
8
+ - 2
9
+ version: 0.1.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Shenouda Bertel
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-08-16 00:00:00 +02:00
17
+ date: 2010-09-07 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -33,11 +33,7 @@ files:
33
33
  - Rakefile
34
34
  - README.markdown
35
35
  - lib/devise_couch/version.rb
36
- - lib/devise/orm/couchrest_model/date_time.rb
37
- - lib/devise/orm/couchrest_model/schema.rb
38
- - lib/devise/orm/couchrest_model/couch_validations.rb
39
36
  - lib/devise/orm/couchrest_model/compatibility.rb
40
- - lib/devise/orm/couchrest_model_active_model.rb
41
37
  - lib/devise/orm/couchrest_model.rb
42
38
  - lib/generators/couchrest_model/devise_generator.rb
43
39
  has_rdoc: true
@@ -1,88 +0,0 @@
1
- module Validatable
2
- # Monkey-patch Validatable::Errors to support generation of error message from a Symbol.
3
- class Errors
4
- @@default_error_messages = {}
5
-
6
- # Holds a hash with all the default error messages that can be replaced by your own copy or localizations.
7
- def self.default_error_messages=(default_error_messages)
8
- @@default_error_messages = default_error_messages
9
- end
10
-
11
- def self.default_error_message(key, field, *values)
12
- field = field.to_s.humanize
13
- @@default_error_messages[key] % [field, *values].flatten
14
- end
15
-
16
- # original add before monkey-patch
17
- # def add(attribute, message) #:nodoc:
18
- # errors[attribute.to_sym] = [] if errors[attribute.to_sym].nil?
19
- # errors[attribute.to_sym] << message
20
- # end
21
-
22
- alias_method :original_add, :add
23
-
24
- # If the message is a Symbol, allow +default_error_message+ to generate
25
- # the message, including translation.
26
- def add(field_name, message)
27
- if message.kind_of?(Symbol)
28
- message = self.class.default_error_message(message, field_name)
29
- end
30
- fld_name = field_name.to_sym
31
- errors[fld_name] = [] if errors[fld_name].nil?
32
- original_add(fld_name, message) unless errors[fld_name].include?(message)
33
- end
34
- end
35
- end
36
-
37
- module Validatable
38
- class ValidatesPresenceOf < ValidationBase #:nodoc:
39
- def message(instance)
40
- super || "can't be blank"
41
- end
42
- end
43
- end
44
-
45
- module Validatable
46
- class ValidatesLengthOf < ValidationBase #:nodoc:
47
- def message(instance)
48
- min = !within.nil? ? within.first : minimum
49
- max = !within.nil? ? within.last : maximum
50
- super || "must be between #{min} and #{max} characters long"
51
- end
52
- end
53
- end
54
-
55
-
56
- # Default error messages consistent with ActiveModel messages and devise
57
- # expectations.
58
- Validatable::Errors.default_error_messages = {
59
- :absent => 'must be absent',
60
- :inclusion => 'is not included in the list',
61
- :exclusion => 'is reserved',
62
- :invalid => 'is invalid',
63
- :confirmation => " doesn't match confirmation",
64
- :accepted => 'must be accepted',
65
- :nil => 'must not be nil',
66
- :empty => "can't be empty",
67
- :blank => "can't be blank",
68
- :length_between => 'must be between %s and %s characters long',
69
- :too_long => 'is too long (maximum is %s characters)',
70
- :too_short => 'is too short (minimum is %s characters)',
71
- :wrong_length => 'is the wrong length (should be %s characters)',
72
- :taken => 'has already been taken',
73
- :not_a_number => 'is not a number',
74
- :not_an_integer => 'must be an integer',
75
- :greater_than => 'must be greater than %s',
76
- :greater_than_or_equal_to => 'must be greater than or equal to ',
77
- :equal_to => 'must be equal to %s',
78
- :not_equal_to => 'must not be equal to %s',
79
- :less_than => 'must be less than %s',
80
- :less_than_or_equal_to => 'must be less than or equal to %s',
81
- :value_between => 'must be between %s and %s',
82
- :odd => 'must be odd',
83
- :even => 'must be even',
84
- :primitive => 'must be of type %s',
85
- :not_found => 'not found',
86
- :already_confirmed => 'was already confirmed',
87
- :not_locked => 'was not locked'
88
- }
@@ -1,14 +0,0 @@
1
- class Date
2
- unless method_defined?(:gmtime)
3
- delegate :gmtime, :to => :to_time
4
- end
5
-
6
- def utc
7
- Time.zone.parse("#{hour.to_i - zone.to_i}:#{min}:#{sec}")
8
- # self.to_datetime.new_offset(0)
9
- end
10
-
11
- def to_i
12
- to_time.utc.to_i
13
- end
14
- end
@@ -1,85 +0,0 @@
1
- module CouchrestModel
2
- class ValidationUtil
3
- class << self
4
- attr_accessor :counter
5
-
6
- def inc_counter
7
- @counter ||= 0
8
- @counter += 1
9
- end
10
- end
11
- end
12
- end
13
- module Devise
14
- module Orm
15
- module CouchrestModel
16
- module Schema
17
- include Devise::Schema
18
-
19
- SCHEMA_OPTIONS = {
20
- :null => :required,
21
- :limit => :length
22
- }
23
-
24
- # Tell how to apply schema methods. This automatically maps :limit to
25
- # :length and :null to :required.
26
- def apply_devise_schema(name, type, options={})
27
- SCHEMA_OPTIONS.each do |old_key, new_key|
28
- next unless options.key?(old_key)
29
- if :null == old_key
30
- # :required is opposite of :null
31
- options[new_key] = !options.delete(old_key)
32
- else
33
- options[new_key] = options.delete(old_key)
34
- end
35
- end
36
-
37
- options.delete(:default) if options[:default].nil?
38
- required_option = options.delete(:required)
39
- length_option = options.delete(:length)
40
-
41
- type = Time if type == DateTime
42
-
43
- key name, type, options
44
-
45
- counter = ::CouchrestModel::ValidationUtil.inc_counter
46
-
47
- handle_email(name, counter) if name == :email
48
- handle_length(name, counter, length_option) if length_option
49
- handle_required(name, counter) if required_option
50
- end
51
-
52
- protected
53
-
54
- def make_key prefix, name, counter
55
- "#{prefix}_#{name}_#{counter}"
56
- end
57
-
58
- def handle_required name, counter
59
- key = make_key :presence, name, counter
60
- validates_presence_of name.to_sym, :key => key
61
- end
62
-
63
- def handle_email name, counter
64
- key = make_key :unique, name, counter
65
- validates_uniqueness_of name.to_sym, :key => key
66
- end
67
-
68
- def handle_length name, counter, length_option
69
- key = make_key :length, name, counter
70
- options = case length_option
71
- when Fixnum
72
- {:maximum => length_option}
73
- when Hash
74
- length_option
75
- else
76
- raise ArgumentError, "length validation option must be either a Fixnum or Hash"
77
- end
78
- options[:key] = key
79
-
80
- validates_length_of name.to_sym, options
81
- end
82
- end
83
- end
84
- end
85
- end
@@ -1,66 +0,0 @@
1
- require 'devise/orm/couchrest_model/compatibility'
2
- require 'devise/orm/couchrest_model/schema'
3
- require 'devise/orm/couchrest_model/date_time'
4
-
5
- module Devise
6
- module Orm
7
- module CouchrestModel
8
- module Hook
9
- def devise_modules_hook!
10
- extend Schema
11
- include ActiveModel::Validations
12
- include ActiveModelCompatibility
13
- include Compatibility
14
- class << self; attr_reader :descendants; end;
15
-
16
- def self.validates_uniqueness_of(*fields)
17
- validates_with UniquenessValidator, _merge_attributes(fields)
18
- end
19
-
20
- yield
21
-
22
- return unless Devise.apply_schema
23
- devise_modules.each { |m| send(m) if respond_to?(m, true) }
24
- end
25
- end
26
-
27
- # http://github.com/jkaramon/CouchrestModel/blob/rails3/lib/couchrest_model/plugins/validations.rb
28
- # ==============================================================
29
- # validates_each in couchrest_model should work just fine!
30
- # ==============================================================
31
-
32
- # class UniquenessValidator < ActiveModel::EachValidator
33
- # def validate_each(target, attribute, value)
34
- # resource = ::DataMapper.repository(target.repository.name) { target.model.first(attribute => value) }
35
- # if resource.nil? || (target.saved? && resource.key == target.key)
36
- # return true
37
- # else
38
- # target.errors.add(attribute, :taken)
39
- # return false
40
- # end
41
- # end
42
- # end
43
-
44
- module ActiveModelCompatibility
45
- # include ActiveModel::Validations does not make save check valid?.
46
- # This may not be the best solution, but it seems to work. Note that
47
- # Compatibility is included after this module; its #save method handles
48
- # the :validate => false option.
49
- def save(*args)
50
- retval = valid? && super(*args)
51
- assert_save_successful(:save, retval)
52
- retval
53
- end
54
- end
55
- end
56
- end
57
- end
58
-
59
- module CouchRest
60
- module Model
61
- class Base
62
- extend ::Devise::Models
63
- extend ::Devise::Orm::CouchrestModel::Hook
64
- end
65
- end
66
- end