Sha256: 0ecf8df37b00c73ba48bef57ef693200cbeda169032b1fc37d56aaf38c0b6bec

Contents?: true

Size: 1.92 KB

Versions: 5

Compression:

Stored size: 1.92 KB

Contents

# see http://api.rubyonrails.org/classes/Rails/Railtie.html

require 'simple_worker'
require 'rails'

module SimpleWorker
  class Railtie < Rails::Railtie
    #    railtie_name :simple_worker deprecated

    initializer "simple_worker.configure_rails_initialization" do |app|
      puts "Initializing SimpleWorker for Rails 3..."
      SimpleWorker.configure do |c2|
        models_path = File.join(Rails.root, 'app/models/*.rb')
        c2.models = Dir.glob(models_path)
        mailers_path = File.join(Rails.root, 'app/mailers/*.rb')
        c2.mailers =Dir.glob(mailers_path).collect { |m| {:filename=>m, :name => File.basename(m), :path_to_templates=>File.join(Rails.root, "app/views/#{File.basename(m, File.extname(m))}")} }
        c2.extra_requires += ['active_support/core_ext', 'active_record', 'action_mailer']
        c2.database = Rails.configuration.database_configuration[Rails.env]
        c2.gems = get_required_gems if defined?(Bundler)
        SimpleWorker.logger.debug "MODELS " + c2.models.inspect
        SimpleWorker.logger.debug "MAILERS " + c2.mailers.inspect
        SimpleWorker.logger.debug "DATABASE " + c2.database.inspect
        SimpleWorker.logger.debug "GEMS " + c2.gems.inspect
      end
    end

    def get_required_gems
      gems_in_gemfile = Bundler.environment.dependencies.select { |d| d.groups.include?(:default) }
      gems =[]
      specs = Bundler.load.specs
      puts 'specs=' + specs.inspect
      gems_in_gemfile.each do |dep|
        next if dep.name=='rails' #monkey patch
        gem_info = {:name=>dep.name, :version=>dep.requirement}
        gem_info.merge!({:require=>dep.autorequire.join}) if dep.autorequire
        spec = specs.find { |g| g.name==gem_info[:name] }
        if spec
          gem_info[:version] = spec.version.to_s
          gems << gem_info
        else
          SimpleWorker.logger.warn "Could not find gem spec for #{gem_info[:name]}"
        end
      end
      gems
    end
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
simple_worker-0.6.6 lib/railtie.rb
simple_worker-0.6.5 lib/railtie.rb
simple_worker-0.6.4 lib/railtie.rb
simple_worker-0.6.3 lib/railtie.rb
simple_worker-0.6.2 lib/railtie.rb