Sha256: 4e7819808e8114cd3b376cec7d0409c2f32f2bab10a4d2ca9ed3b7da00c4993b

Contents?: true

Size: 995 Bytes

Versions: 3

Compression:

Stored size: 995 Bytes

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_and_include_orm

  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_and_include_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

3 entries across 3 versions & 1 rubygems

Version Path
impressionist-1.4.1 lib/impressionist/engine.rb
impressionist-1.4.0 lib/impressionist/engine.rb
impressionist-1.3.2 lib/impressionist/engine.rb