Class: SlowServer::Config
- Inherits:
-
Object
- Object
- SlowServer::Config
- Defined in:
- lib/slow_server/config.rb
Instance Attribute Summary collapse
-
#chunk_delay ⇒ Object
Returns the value of attribute chunk_delay.
-
#chunks ⇒ Object
Returns the value of attribute chunks.
-
#port ⇒ Object
Returns the value of attribute port.
-
#response ⇒ Object
Returns the value of attribute response.
-
#response_delay ⇒ Object
Returns the value of attribute response_delay.
Instance Method Summary collapse
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #opts ⇒ Object
- #parse_opts ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
7 8 9 10 11 12 13 14 |
# File 'lib/slow_server/config.rb', line 7 def initialize # set defaults self.response = File.read(File.("../../../files/response.txt", __FILE__)) self.port = 4000 self.chunks = 1 self.response_delay = 0 self.chunk_delay = 0 end |
Instance Attribute Details
#chunk_delay ⇒ Object
Returns the value of attribute chunk_delay.
5 6 7 |
# File 'lib/slow_server/config.rb', line 5 def chunk_delay @chunk_delay end |
#chunks ⇒ Object
Returns the value of attribute chunks.
5 6 7 |
# File 'lib/slow_server/config.rb', line 5 def chunks @chunks end |
#port ⇒ Object
Returns the value of attribute port.
5 6 7 |
# File 'lib/slow_server/config.rb', line 5 def port @port end |
#response ⇒ Object
Returns the value of attribute response.
5 6 7 |
# File 'lib/slow_server/config.rb', line 5 def response @response end |
#response_delay ⇒ Object
Returns the value of attribute response_delay.
5 6 7 |
# File 'lib/slow_server/config.rb', line 5 def response_delay @response_delay end |
Instance Method Details
#opts ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/slow_server/config.rb', line 16 def opts @opts ||= OptionParser.new do |opt| opt. = "Usage: #{File.basename($PROGRAM_NAME)} [OPTIONS] [RESPONSE]" opt.on("-p", "--port NUMBER", Integer, "Listen Port (default: #{self.port}") { |v| self.port = v } opt.on("-c", "--chunks BYTES", Integer, "Chunks (default: #{self.chunks})") { |v| self.chunks = v } opt.on("-r", "--response-delay SECONDS", Integer, "Response delay after connecting (default: #{self.response_delay})") { |v| self.response_delay = v } opt.on("-k", "--chunk-delay SECONDS", Float, "Delay between chunks (default: #{self.chunk_delay})") { |v| self.chunk_delay = v } opt.on("-v", "--version", "Show Version") { puts SlowServer::VERSION; throw :exit } end end |
#parse_opts ⇒ Object
27 28 29 30 |
# File 'lib/slow_server/config.rb', line 27 def parse_opts response = opts.parse!.join(" ") self.response = response unless response.empty? end |