1
0
Fork 0
mirror of https://github.com/aasm/aasm synced 2023-03-27 23:22:41 -04:00

Merge pull request #278 from aasm/mongoid_5

Add support for Mongoid 5
This commit is contained in:
Thorsten Böttger 2015-10-27 22:58:35 +13:00
commit d22dd21ee1
6 changed files with 23 additions and 5 deletions

View file

@ -18,11 +18,12 @@ services: mongodb
gemfile:
- gemfiles/rails_3.2.gemfile
- gemfiles/rails_4.0.gemfile
- gemfiles/rails_4.0_bson1.gemfile
- gemfiles/rails_4.0_mongo_mapper.gemfile
- gemfiles/rails_4.1.gemfile
- gemfiles/rails_4.1_bson1.gemfile
- gemfiles/rails_4.1_mongo_mapper.gemfile
- gemfiles/rails_4.2.gemfile
- gemfiles/rails_4.2_bson1.gemfile
- gemfiles/rails_4.2_mongoid_5.gemfile
- gemfiles/rails_4.2_mongo_mapper.gemfile
matrix:
allow_failures:

View file

@ -0,0 +1,12 @@
source "https://rubygems.org"
gem "sqlite3", :platforms => :ruby
gem 'rubysl', :platforms => :rbx
gem 'rubinius-developer_tools', :platforms => :rbx
gem "jruby-openssl", :platforms => :jruby
gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
gem "rails", "4.2.0"
gem 'mongoid', '~>5.0' if Gem::Version.create(RUBY_VERSION.dup) >= Gem::Version.create('1.9.3')
gem 'sequel'
gemspec :path => "../"

View file

@ -56,8 +56,8 @@ module AASM
def state_with_scope(name, *args)
state_without_scope(name, *args)
if @state_machine.config.create_scopes && !@klass.respond_to?(name)
if @klass.ancestors.map {|klass| klass.to_s}.include?("ActiveRecord::Base")
if @klass.ancestors.map {|klass| klass.to_s}.include?("ActiveRecord::Base")
conditions = {"#{@klass.table_name}.#{@klass.aasm(@name).attribute_name}" => name.to_s}
if ActiveRecord::VERSION::MAJOR >= 3
@klass.class_eval do
@ -69,12 +69,17 @@ module AASM
end
end
elsif @klass.ancestors.map {|klass| klass.to_s}.include?("Mongoid::Document")
scope_options = lambda { @klass.send(:where, {@klass.aasm(@name).attribute_name.to_sym => name.to_s}) }
klass = @klass
state_machine_name = @name
scope_options = lambda {
klass.send(:where, {klass.aasm(state_machine_name).attribute_name.to_sym => name.to_s})
}
@klass.send(:scope, name, scope_options)
elsif @klass.ancestors.map {|klass| klass.to_s}.include?("MongoMapper::Document")
conditions = { @klass.aasm(@name).attribute_name.to_sym => name.to_s }
@klass.scope(name, lambda { @klass.where(conditions) })
end
end
end
alias_method :state_without_scope, :state