Module: Djinn::Rails::Handlers

Defined in:
lib/djinn/rails/handlers.rb

Instance Method Summary collapse

Instance Method Details

#djinnify_rails(config = {}) ⇒ Object

Create an instance of your Djinn, interpret any command line switches defined in your configuration block, loads Rails environment and starts the Djinn in the background



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/djinn/rails/handlers.rb', line 8

def djinnify_rails config={}
  djinn = new
  
  # handle rails environment
  env = Djinn::Base::Dsl::ConfigItem.new(:posix, :rails_env)
  env.short_switch "-e"
  env.long_switch "--environment"
  env.description "Run in specific Rails environment"
  @definition.config_helper.config_items << env
  
  @definition.prepare(djinn.config.update(config))
  
  unless djinn.config[:__stop]
    yield djinn if block_given?
    if djinn.config[:__daemonize]
      djinn.start do
        ENV["RAILS_ENV"] = djinn.config[:rails_env] || "development"
        load_rails
      end
    else
      djinn.run do
        ENV["RAILS_ENV"] = djinn.config[:rails_env] || "development"
        load_rails
      end
    end
  else
    djinn.stop
  end
end