sanford 0.11.0 → 0.11.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,15 +11,18 @@ module Sanford
11
11
  options ||= {}
12
12
  @server = server
13
13
  @logger = @server.logger
14
- @name = "sanford-#{@server.name}"
15
14
  @pid_file = PIDFile.new(@server.pid_file)
16
15
  @restart_cmd = RestartCmd.new
17
16
 
18
- @server_ip = ignore_if_blank(ENV['SANFORD_IP'])
19
- @server_port = ignore_if_blank(ENV['SANFORD_PORT']){ |v| v.to_i }
17
+ @server_ip = default_if_blank(ENV['SANFORD_IP'], @server.configured_ip)
18
+ @server_port = default_if_blank(
19
+ ENV['SANFORD_PORT'],
20
+ @server.configured_port
21
+ ){ |v| v.to_i }
20
22
  @server_fd = ignore_if_blank(ENV['SANFORD_SERVER_FD']){ |v| v.to_i }
21
23
  @listen_args = @server_fd ? [ @server_fd ] : [ @server_ip, @server_port ]
22
- @listen_args.compact!
24
+
25
+ @name = "sanford-#{@server.name}-#{@server_ip}-#{@server_port}"
23
26
 
24
27
  @client_fds = (ENV['SANFORD_CLIENT_FDS'] || "").split(',').map(&:to_i)
25
28
 
@@ -71,9 +74,13 @@ module Sanford
71
74
  @restart_cmd.exec
72
75
  end
73
76
 
74
- def ignore_if_blank(value, default = nil, &block)
77
+ def default_if_blank(value, default, &block)
78
+ ignore_if_blank(value, &block) || default
79
+ end
80
+
81
+ def ignore_if_blank(value, &block)
75
82
  block ||= proc{ |v| v }
76
- value && !value.empty? ? block.call(value) : default
83
+ block.call(value) if value && !value.empty?
77
84
  end
78
85
 
79
86
  end
@@ -53,6 +53,14 @@ module Sanford
53
53
  @dat_tcp_server.client_file_descriptors
54
54
  end
55
55
 
56
+ def configured_ip
57
+ @server_data.ip
58
+ end
59
+
60
+ def configured_port
61
+ @server_data.port
62
+ end
63
+
56
64
  def pid_file
57
65
  @server_data.pid_file
58
66
  end
@@ -1,3 +1,3 @@
1
1
  module Sanford
2
- VERSION = "0.11.0"
2
+ VERSION = "0.11.1"
3
3
  end
@@ -59,14 +59,16 @@ class Sanford::Process
59
59
  end
60
60
 
61
61
  should "know its name, pid file and restart cmd" do
62
- assert_equal "sanford-#{@server_spy.name}", subject.name
62
+ expected = "sanford-#{@server_spy.name}-" \
63
+ "#{@server_spy.configured_ip}-#{@server_spy.configured_port}"
64
+ assert_equal expected, subject.name
63
65
  assert_equal @pid_file_spy, subject.pid_file
64
66
  assert_equal @restart_cmd_spy, subject.restart_cmd
65
67
  end
66
68
 
67
69
  should "know its server ip, port and file descriptor" do
68
- assert_nil subject.server_ip
69
- assert_nil subject.server_port
70
+ assert_equal @server_spy.configured_ip, subject.server_ip
71
+ assert_equal @server_spy.configured_port, subject.server_port
70
72
  assert_nil subject.server_fd
71
73
  end
72
74
 
@@ -85,8 +87,8 @@ class Sanford::Process
85
87
  ENV['SANFORD_PORT'] = ''
86
88
  ENV['SANFORD_SERVER_FD'] = ''
87
89
  process = @process_class.new(@server_spy)
88
- assert_nil process.server_ip
89
- assert_nil process.server_port
90
+ assert_equal @server_spy.configured_ip, subject.server_ip
91
+ assert_equal @server_spy.configured_port, subject.server_port
90
92
  assert_nil process.server_fd
91
93
  end
92
94
 
@@ -173,7 +175,8 @@ class Sanford::Process
173
175
 
174
176
  should "have started the server listening" do
175
177
  assert_true @server_spy.listen_called
176
- assert_equal [], @server_spy.listen_args
178
+ expected = [ subject.server_ip, subject.server_port ]
179
+ assert_equal expected, @server_spy.listen_args
177
180
  end
178
181
 
179
182
  should "have set the process name" do
@@ -157,6 +157,8 @@ module Sanford::Server
157
157
  should have_readers :server_data, :dat_tcp_server
158
158
  should have_imeths :name, :ip, :port
159
159
  should have_imeths :file_descriptor, :client_file_descriptors
160
+ should have_imeths :configured_ip, :configured_port
161
+ should have_imeths :pid_file, :logger
160
162
  should have_imeths :listen, :start, :pause, :stop, :halt
161
163
  should have_imeths :paused?
162
164
 
@@ -186,6 +188,8 @@ module Sanford::Server
186
188
 
187
189
  should "know its name, pid file and logger" do
188
190
  assert_equal subject.server_data.name, subject.name
191
+ assert_equal subject.server_data.ip, subject.configured_ip
192
+ assert_equal subject.server_data.port, subject.configured_port
189
193
  assert_equal subject.server_data.pid_file, subject.pid_file
190
194
  assert_equal subject.server_data.logger, subject.logger
191
195
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sanford
3
3
  version: !ruby/object:Gem::Version
4
- hash: 51
4
+ hash: 49
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 11
9
- - 0
10
- version: 0.11.0
9
+ - 1
10
+ version: 0.11.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Collin Redding