Permalink
Browse files

Merge pull request #7 from bmarini/v-0-9-support

MongoMapper 0.9 support
  • Loading branch information...
kristianmandrup committed Jun 4, 2011
2 parents 1fbe207 + c868c97 commit 692b2453849aa9cb4770167d1fd182c4c59d7a03
View
26 Gemfile
@@ -1,31 +1,29 @@
source :rubygems
-source 'http://gems.github.com/'
-
-gem "rails"
-
group :test do
gem "test-unit", "~> 2.0.9"
- gem "webrat", "~> 0.7.0"
+ gem "webrat", "~> 0.7.2"
gem "mocha", "~> 0.9.8", :require => false
end
group :default do
- gem "webrat", "~> 0.7.0"
+ gem "rails", "~> 3.0.7"
+ gem "webrat", "~> 0.7.2"
- gem "bcrypt-ruby", :require => "bcrypt"
- gem "oauth2"
- gem "warden", ">= 0.10.7"
- gem 'mongo_mapper', '>= 0.8.4'
+ gem 'mongo_mapper', '0.9.0'
gem 'sugar-high', '~> 0.3.4'
gem 'devise', '>= 1.1.1'
gem 'rails3-generators', '>= 0.13.0'
- gem 'jnunemaker-validatable', '~> 1.8.1'
gem 'bson_ext', '>= 1.0.9'
-
+
+ gem 'rake', '0.8.7'
gem "orm_adapter"
- gem "omniauth"
-
+ gem "oa-oauth", '~> 0.2.0', :require => "omniauth/oauth"
+ gem "oa-openid", '~> 0.2.0', :require => "omniauth/openid"
+
+ platforms :mri_18 do
+ gem "SystemTimer"
+ end
end
View
@@ -4,14 +4,11 @@ require 'rake'
require 'bundler'
Bundler::GemHelper.install_tasks
-
require 'rake/testtask'
require 'rake/rdoctask'
require File.join(File.dirname(__FILE__), 'lib', 'mm-devise', 'version')
desc 'Run Devise tests using MongoMapper. Specify path to devise with DEVISE_PATH'
-
-
Rake::TestTask.new(:test) do |test|
ENV['DEVISE_ORM'] ||= 'mongo_mapper'
ENV['DEVISE_PATH'] ||= File.join(File.dirname(__FILE__), '../devise')
@@ -27,56 +24,5 @@ Rake::TestTask.new(:test) do |test|
test.verbose = true
end
-desc 'Default: run tests for all ORMs.'
-task :default => :tests
-
-=begin
-desc 'Default: run tests for all MongoMapper ORM setups.'
-task :default => :pre_commit
-
-desc 'Run Devise tests for all MongoMapper ORM setups.'
-task :pre_commit do
- Dir[File.join(File.dirname(__FILE__), 'test', 'orm', '*.rb')].each do |file|
- orm = File.basename(file).split(".").first
- ENV['DEVISE_PATH'] ||= File.expand_path('../devise')
- system "rake test DEVISE_ORM=#{orm} DEVISE_PATH=#{ENV['DEVISE_PATH']}"
- end
-end
-
-
-task :test
-
-desc 'Generate documentation for dm-devise.'
-Rake::RDocTask.new(:rdoc) do |rdoc|
- rdoc.rdoc_dir = 'rdoc'
- rdoc.title = 'mm-devise #{version}'
- rdoc.options << '--line-numbers' << '--inline-source'
- rdoc.rdoc_files.include('README.rdoc')
- rdoc.rdoc_files.include('lib/**/*.rb')
-end
-
-begin
- require 'jeweler'
- Jeweler::Tasks.new do |gem|
- gem.name = "mm-devise"
- gem.version = MongoMapper::Devise::VERSION.dup
- gem.summary = %Q{Support for using MongoMapper ORM with devise}
- gem.description = %Q{dm-devise adds MongoMapper support to devise (http://github.com/plataformatec/devise) for authentication support for Rails}
- gem.email = "jmorgan@morgancreative.net"
- gem.homepage = "http://github.com/kristianmandrup/mm-devise"
- gem.authors = ["Kristian Mandrup"]
- gem.add_dependency 'mongo_mapper', '>= 0.8.4'
- gem.add_dependency 'bson', '>= 1.0.9'
- gem.add_dependency 'rails3-generators', '>= 0.13.0'
- gem.add_dependency 'jnunemaker-validatable', '>= 1.8.1'
- gem.add_dependency 'devise', '>= 1.1.1'
- gem.add_dependency 'sugar-high', '~> 0.3.0'
- gem.add_dependency 'warden', '>= 0.10.7'
- gem.add_dependency 'bcrypt-ruby', '>= 2.1.2'
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
- end
- Jeweler::GemcutterTasks.new
-rescue LoadError
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
-end
-=end
+desc 'Default: run tests for MongoMapper'
+task :default => :test
@@ -1,26 +1,37 @@
-require 'mongo_mapper'
-require 'devise/orm/mongo_mapper/compatibility'
-require 'devise/orm/mongo_mapper/schema'
-require 'devise/orm/mongo_mapper/date_time'
-require 'devise/orm/mongo_mapper/mm-validations'
+require 'orm_adapter/adapters/mongo_mapper'
module Devise
module Orm
module MongoMapper
+ extend ActiveSupport::Concern
+
+ included do
+ extend Devise::Models
+ extend Devise::Orm::MongoMapper::Hook
+ end
+
module Hook
def devise_modules_hook!
extend Schema
- include Compatibility
- include Validatable
yield
return unless Devise.apply_schema
devise_modules.each { |m| send(m) if respond_to?(m, true) }
- end
+ end
+
end
+
+ module Schema
+ include Devise::Schema
+
+ # Tell how to apply schema methods
+ def apply_devise_schema(name, type, options={})
+ type = Time if type == DateTime
+ key(name, type, options)
+ end
+ end
+
end
end
end
-MongoMapper::Document.append_extensions(Devise::Models)
-MongoMapper::Document.append_extensions(Devise::Orm::MongoMapper::Hook)
-
+MongoMapper::Document.plugin Devise::Orm::MongoMapper
@@ -1,89 +0,0 @@
-module Devise
- module Orm
- module MongoMapper
- module Compatibility
- extend ActiveSupport::Concern
-
- extend ActiveSupport::Concern
- extend ActiveModel::Naming
-
- include ActiveModel::Serializers::Xml
- include ActiveModel::Serializers::JSON
-
- def to_xml(options = {}, &block)
- options[:except] ||= []
- options[:except] << :_id
-
- super options do |b|
- b.id self.id
- block.call(b) if block_given?
- end
- end
-
-
- module ClassMethods
- # Hooks for confirmable
- def before_create(*args)
- wrap_hook(:before, :create, *args)
- end
-
- def after_create(*args)
- wrap_hook(:after, :create, *args)
- end
-
- def before_save(*args)
- wrap_hook(:before, :save, *args)
- end
-
- def wrap_hook(action, method, *args)
- options = args.extract_options!
-
- args.each do |callback|
- callback_method = :"#{callback}_callback_wrap"
- send action, method, callback_method
- class_eval <<-METHOD, __FILE__, __LINE__ + 1
- def #{callback_method}
- #{callback} if #{options[:if] || true}
- end
- METHOD
- end
- end
-
- # Add ActiveRecord like finder
- def find(*args)
- case args.first
- when :first, :all
- send(args.shift, *args)
- else
- where(:'_id' => args.first).first
- end
- end
- end
-
- # def changed?
- # dirty?
- # end
-=begin
- def save(options=nil)
- if options.is_a?(Hash) && options[:validate] == false
- save!
- else
- super()
- end
- end
-
- def update_attribute(name, value)
- update_attributes(name => value)
- end
- #
- # def update_attributes(*args)
- # update(*args)
- # end
-=end
- def invalid?
- !valid?
- end
- end
- end
- end
-end
@@ -1,14 +0,0 @@
-class Date
- unless method_defined?(:gmtime)
- delegate :gmtime, :to => :to_time
- end
-
- def utc
- Time.zone.parse("#{hour.to_i - zone.to_i}:#{min}:#{sec}")
- # self.to_datetime.new_offset(0)
- end
-
- def to_i
- to_time.utc.to_i
- end
-end
@@ -1,91 +0,0 @@
-require 'validatable'
-
-module Validatable
- # Monkey-patch Validatable::Errors to support generation of error message from
- # a Symbol.
- class Errors
- @@default_error_messages = {}
-
- # Holds a hash with all the default error messages that can be replaced by your own copy or localizations.
- def self.default_error_messages=(default_error_messages)
- @@default_error_messages = default_error_messages
- end
-
- def self.default_error_message(key, field, *values)
- field = field.to_s.humanize
- @@default_error_messages[key] % [field, *values].flatten
- end
-
- # original add before monkey-patch
- # def add(attribute, message) #:nodoc:
- # errors[attribute.to_sym] = [] if errors[attribute.to_sym].nil?
- # errors[attribute.to_sym] << message
- # end
-
- alias_method :original_add, :add
-
- # If the message is a Symbol, allow +default_error_message+ to generate
- # the message, including translation.
- def add(field_name, message)
- if message.kind_of?(Symbol)
- message = self.class.default_error_message(message, field_name)
- end
- fld_name = field_name.to_sym
- errors[fld_name] = [] if errors[fld_name].nil?
- original_add(fld_name, message) unless errors[fld_name].include?(message)
- end
- end
-end
-
-module Validatable
- class ValidatesPresenceOf < ValidationBase #:nodoc:
- def message(instance)
- super || "can't be blank"
- end
- end
-end
-
-module Validatable
- class ValidatesLengthOf < ValidationBase #:nodoc:
- def message(instance)
- min = !within.nil? ? within.first : minimum
- max = !within.nil? ? within.last : maximum
- super || "must be between #{min} and #{max} characters long"
- end
- end
-end
-
-
-# Default error messages consistent with ActiveModel messages and devise
-# expectations.
-Validatable::Errors.default_error_messages = {
- :absent => 'must be absent',
- :inclusion => 'is not included in the list',
- :exclusion => 'is reserved',
- :invalid => 'is invalid',
- :confirmation => " doesn't match confirmation",
- :accepted => 'must be accepted',
- :nil => 'must not be nil',
- :empty => "can't be empty",
- :blank => "can't be blank",
- :length_between => 'must be between %s and %s characters long',
- :too_long => 'is too long (maximum is %s characters)',
- :too_short => 'is too short (minimum is %s characters)',
- :wrong_length => 'is the wrong length (should be %s characters)',
- :taken => 'has already been taken',
- :not_a_number => 'is not a number',
- :not_an_integer => 'must be an integer',
- :greater_than => 'must be greater than %s',
- :greater_than_or_equal_to => 'must be greater than or equal to ',
- :equal_to => 'must be equal to %s',
- :not_equal_to => 'must not be equal to %s',
- :less_than => 'must be less than %s',
- :less_than_or_equal_to => 'must be less than or equal to %s',
- :value_between => 'must be between %s and %s',
- :odd => 'must be odd',
- :even => 'must be even',
- :primitive => 'must be of type %s',
- :not_found => 'not found',
- :already_confirmed => 'was already confirmed',
- :not_locked => 'was not locked'
-}
Oops, something went wrong.

0 comments on commit 692b245

Please sign in to comment.