Sha256: 86beae3fe94acc24b1516090981d6818bf8f6743bf36b4829e471a4996f47c14

Contents?: true

Size: 1.02 KB

Versions: 2

Compression:

Stored size: 1.02 KB

Contents

require "impressionist"
require "rails"

module Impressionist
  class Engine < Rails::Engine
    attr_accessor :orm

  def initialize
    define_orm_type(Impressionist.orm)
  end

  initializer 'impressionist.model' do |app|
    require_orm
    ActiveRecord::Base.send(:include, Impressionist::Impressionable)

  end


  initializer 'impressionist.controller' do
    require "impressionist/controllers/mongoid/impressionist_controller.rb" if orm == :mongoid.to_s

    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


  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
impressionist-1.3.1 lib/impressionist/engine.rb
impressionist-1.3.0 lib/impressionist/engine.rb