fixed for Mongoid 2 support

This commit is contained in:
JGW Maxwell 2012-07-11 03:45:24 +01:00
parent a53363d9f6
commit 2f8c47a46f
4 changed files with 14 additions and 1 deletions

View File

@ -7,6 +7,7 @@ module Impressionist
def copy_config_file def copy_config_file
template 'impression.rb', 'config/initializers/impression.rb' template 'impression.rb', 'config/initializers/impression.rb'
end end
end end
end end
end end

View File

@ -0,0 +1 @@
impression-mongoid-2.rb

View File

@ -1,9 +1,10 @@
ImpressionistController::InstanceMethods.send(:define_method, :direct_create_statement) do |query_params={}| ImpressionistController::InstanceMethods.send(:define_method, :direct_create_statement) do |query_params={}|
# creates a statment hash that contains default values for creating an impression. # creates a statment hash that contains default values for creating an impression.
# if :impressionable_id is a valid ObjectId then convert it into one # if :impressionable_id is a valid ObjectId then convert it into one
base = (defined? Moped) ? Moped::BSON : BSON
query_params.reverse_merge!( query_params.reverse_merge!(
:impressionable_type => controller_name.singularize.camelize, :impressionable_type => controller_name.singularize.camelize,
:impressionable_id=> !Moped::BSON::ObjectId.legal?(params[:id]) ? params[:id] : Moped::BSON::ObjectId.from_string(params[:id]) :impressionable_id=> !base::ObjectId.legal?(params[:id]) ? params[:id] : base::ObjectId.from_string(params[:id])
) )
associative_create_statement(query_params) associative_create_statement(query_params)
end end

View File

@ -0,0 +1,10 @@
ImpressionistController::InstanceMethods.send(:define_method, :direct_create_statement) do |query_params={}|
# creates a statment hash that contains default values for creating an impression.
# if :impressionable_id is a valid ObjectId then convert it into one
base = (defined? Moped) ? Moped::BSON :: BSON
query_params.reverse_merge!(
:impressionable_type => controller_name.singularize.camelize,
:impressionable_id=> !base::ObjectId.legal?(params[:id]) ? params[:id] : base::ObjectId.from_string(params[:id])
)
associative_create_statement(query_params)
end