Top Level Namespace

Constant Summary collapse

Thin_Upstreams_Version =
"0.3.0"

Instance Method Summary collapse

Instance Method Details

#Thin_Port_To_Array(raw_port, raw_num) ⇒ Object



27
28
29
30
31
# File 'lib/Thin_Upstreams.rb', line 27

def Thin_Port_To_Array raw_port, raw_num
  port = Integer(raw_port)
  q    = Integer(raw_num || 1)
  (0...q).to_a.map { |i| port + i }
end

#Thin_Upstreams(glob = "./*/{config,.}/thin.yml") ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/Thin_Upstreams.rb', line 4

def Thin_Upstreams glob = "./*/{config,.}/thin.yml"

  str = %~\n~
  arr = Dir.glob(glob).sort.each { |file|
      o = YAML::load File.read(file)
      app_name = begin
                   pwd  = File.join( File.expand_path("."), "/" )
                   path = File.expand_path(file)
                   path.sub(pwd, '').split("/").first
                 end
      
      ports = Thin_Port_To_Array(o["port"], o["servers"])
      str << %~
        upstream #{app_name} {
          #{ ports.map { |i| "server 127.0.0.1:#{i}" }.join(";
          ") };
        }
      ~
    }

  File.write "upstreams.conf", str
end