commit
3821a7f0ba
|
@ -3,31 +3,46 @@ require "rails"
|
||||||
|
|
||||||
module Impressionist
|
module Impressionist
|
||||||
class Engine < Rails::Engine
|
class Engine < Rails::Engine
|
||||||
initializer 'impressionist.model' do |app|
|
attr_accessor :orm
|
||||||
require "#{root}/app/models/impressionist/impressionable.rb"
|
|
||||||
if Impressionist.orm == :active_record && defined? ActiveRecord
|
def initialize
|
||||||
require "impressionist/models/active_record/impression.rb"
|
define_orm_type(Impressionist.orm)
|
||||||
require "impressionist/models/active_record/impressionist/impressionable.rb"
|
end
|
||||||
ActiveRecord::Base.send(:include, Impressionist::Impressionable)
|
|
||||||
elsif Impressionist.orm == :mongo_mapper
|
initializer 'impressionist.model' do |app|
|
||||||
require "impressionist/models/mongo_mapper/impression.rb"
|
require_orm
|
||||||
require "impressionist/models/mongo_mapper/impressionist/impressionable.rb"
|
ActiveRecord::Base.send(:include, Impressionist::Impressionable)
|
||||||
MongoMapper::Document.plugin Impressionist::Impressionable
|
|
||||||
elsif Impressionist.orm == :mongoid
|
end
|
||||||
require 'impressionist/models/mongoid/impression.rb'
|
|
||||||
require 'impressionist/models/mongoid/impressionist/impressionable.rb'
|
|
||||||
Mongoid::Document.send(:include, Impressionist::Impressionable)
|
initializer 'impressionist.controller' do
|
||||||
end
|
require "impressionist/controllers/mongoid/impressionist_controller.rb" if orm == :mongoid.to_s
|
||||||
end
|
|
||||||
|
ActiveSupport.on_load(:action_controller) do
|
||||||
|
include ImpressionistController::InstanceMethods
|
||||||
|
extend ImpressionistController::ClassMethods
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
private
|
||||||
|
def require_orm
|
||||||
|
require "#{root}/app/models/impressionist/impressionable.rb"
|
||||||
|
require "impressionist/models/#{orm}/impression.rb"
|
||||||
|
require "impressionist/models/#{orm}/impressionist/impressionable.rb"
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def define_orm_type(str)
|
||||||
|
@orm = matcher(str.to_s)
|
||||||
|
end
|
||||||
|
|
||||||
|
def matcher(str)
|
||||||
|
matched = str.match(/active_record|mongo_mapper|mongoid|/)
|
||||||
|
matched[0]
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
initializer 'impressionist.controller' do
|
|
||||||
if Impressionist.orm == :mongoid
|
|
||||||
require 'impressionist/controllers/mongoid/impressionist_controller.rb'
|
|
||||||
end
|
|
||||||
ActiveSupport.on_load(:action_controller) do
|
|
||||||
include ImpressionistController::InstanceMethods
|
|
||||||
extend ImpressionistController::ClassMethods
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue