Sha256: 7575c812b2498894d40fc41f3d2219b630d3ee8d39b6c5b279f69993223f0483

Contents?: true

Size: 1.38 KB

Versions: 3

Compression:

Stored size: 1.38 KB

Contents

module Rich
  module Support
    extend self

    def append_gem_path(path)
      (@gem_paths ||= []) << path

      check_controllers_for path
      check_routes_for      path
      check_views_for       path
    end

    def after_initialize(&block)
      if Rails::VERSION::MAJOR >= 3
        ActiveSupport.on_load :after_initialize, :yield => true, &block
      else
        Rails.configuration.after_initialize &block
      end
    end

  private

    def check_controllers_for(path)
      return if Rails::VERSION::MAJOR >= 3
      if File.exists?(controllers = File.expand_path("app/controllers", path))
        $LOAD_PATH << controllers
        ActiveSupport::Dependencies.autoload_paths << controllers
        ActiveSupport::Dependencies.autoload_once_paths.delete controllers
      end
    end

    def check_routes_for(path)
      return if Rails::VERSION::MAJOR >= 3
      if File.exists?(routes = File.expand_path("config/routes.rb", path))
        require routes
      end
    end

    def check_views_for(path)
      return if Rails::VERSION::MAJOR >= 3
      if File.exists?(views = File.expand_path("app/views", path))
        if ActionController::Base.respond_to? :append_view_path
          ActionController::Base.append_view_path views
        elsif ActionController::Base.respond_to? :view_paths
          ActionController::Base.self.view_paths << views
        end
      end
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rich_support-0.1.2 lib/rich/support.rb
rich_support-0.1.1 lib/rich/support.rb
rich_support-0.1.0 lib/rich/support.rb