Sha256: ae59947d4943f510599e0c67eea515c3d0527fb871927547b9e04929eca0b0b9

Contents?: true

Size: 1.25 KB

Versions: 3

Compression:

Stored size: 1.25 KB

Contents

if defined?(Rails::Railtie)
  module Woodhouse::RailsExtensions
    def layout(&blk)
      unless @delay_finished
        @delayed_layout = blk
      else
        super
      end
    end

    def finish_loading_layout!
      @delay_finished = true
      if @delayed_layout
        layout &@delayed_layout
      end
    end
  end

  Woodhouse.extend Woodhouse::RailsExtensions
 
  class Woodhouse::Rails < Rails::Engine
#    config.autoload_paths << Rails.root.join("app/workers")

    initializer 'woodhouse' do
      config_paths = %w[woodhouse.yml workling.yml].map{|file|
        Rails.root.join("config/" + file)
      }
      # Preload everything in app/workers so default layout includes them 
      Rails.root.join("app/workers").tap do |workers|
        Pathname.glob(workers.join("**/*.rb")).each do |worker_path|
          worker_path.relative_path_from(workers).basename(".rb").to_s.camelize.constantize
        end
      end
      # Set up reasonable defaults
      Woodhouse.configure do |config|
        config.logger = ::Rails.logger
        config_paths.each do |path|
          if File.exist?(path)
            config.server_info = YAML.load(File.read(path))[::Rails.env]
          end
        end
      end
      Woodhouse.finish_loading_layout!
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
woodhouse-0.1.5 lib/woodhouse/rails.rb
woodhouse-0.1.2 lib/woodhouse/rails.rb
woodhouse-0.1.1 lib/woodhouse/rails.rb