0

I'm using the puma application server, and it has a config file at config/puma.rb:

path = "/home/starkers/Documents/" + Rails.application.class.parent_name + "/tmp/puma/"

threads 0,20

environment "production"


daemonize true
bind  "unix://" + path + "socket/puma.sock"
pidfile path + "pid/puma.pid"
state_path path + "pid/puma.state"

When running puma -C config/puma.rb to load this file and start the application server, everything works apart from the Rails.application.class.parent_name.

Can you think of anyway to get constants into the puma.rb file? Failing this, I suppose a workaround whcih gets the directory name of the root would work.

I'd like to use this attribute as well in the config, Rails.root, but I need to get the Rails constant in! Do I need to use require?

Starkers
  • 10,273
  • 21
  • 95
  • 158

1 Answers1

1

You're going to need to load up your entire Rails app to get access to that object. You should be able to do this with a require 'config/environment' at the top of your puma.rb.

tony_winn
  • 26
  • 2
  • Thanks. I do understand that will slow the process down, but's only one once on server boot. – Starkers Nov 13 '13 at 23:28
  • Not that it matters, but if someone could think of way to just load the Rails constant rather than the whole environment, that would be good. No idea if that can be done :) – Starkers Nov 13 '13 at 23:30
  • Yep it will slow it down for sure. You might want getting to the same thing without using the Rails class, maybe you could get what you need using ruby's `File` class? – tony_winn Nov 13 '13 at 23:32
  • I'm pretty sure it's an all or nothing thing getting the Rails constant. – tony_winn Nov 13 '13 at 23:32
  • Yeah, thought as much. I'm using the Ruby Dir constant to get what I want. I think it's working, thanks for the suggestion! – Starkers Nov 13 '13 at 23:35