Class: Nailgun::Client
- Inherits:
-
Object
- Object
- Nailgun::Client
- Defined in:
- lib/nailgun/client.rb,
lib/nailgun/client/chunk.rb,
lib/nailgun/client/chunk_header.rb
Defined Under Namespace
Classes: Chunk, ChunkHeader
Instance Attribute Summary collapse
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#socket ⇒ Object
readonly
Returns the value of attribute socket.
Class Method Summary collapse
-
.run(command, args, opts = {}) ⇒ Object
Public: Convinience method to instantiate and run the command.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Client
constructor
Public: Initialize a Client.
-
#receive_loop ⇒ Object
Public: Start the receiver loop Thread, memoize it, and return the Thread.
-
#run(command, *args) ⇒ Object
Public: Run a command on the Client instance.
Constructor Details
#initialize(opts = {}) ⇒ Client
Public: Initialize a Client.
opts = {} - a Hash of options to override the defaults in Nailgun::DEFAULTS
24 25 26 27 |
# File 'lib/nailgun/client.rb', line 24 def initialize(opts = {}) @opts = Nailgun::DEFAULTS.merge(opts) @socket = TCPSocket.new(*@opts.values_at(:hostname, :port)) end |
Instance Attribute Details
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
8 9 10 |
# File 'lib/nailgun/client.rb', line 8 def opts @opts end |
#socket ⇒ Object (readonly)
Returns the value of attribute socket.
8 9 10 |
# File 'lib/nailgun/client.rb', line 8 def socket @socket end |
Class Method Details
.run(command, args, opts = {}) ⇒ Object
Public: Convinience method to instantiate and run the command
command - see #run args - see #run opts = {} - see #initialize
Returns the duplicated String.
17 18 19 |
# File 'lib/nailgun/client.rb', line 17 def self.run(command, args, opts = {}) self.new(opts).run(command, args) end |
Instance Method Details
#receive_loop ⇒ Object
Public: Start the receiver loop Thread, memoize it, and return the Thread
Returns the Thread object, whose value will eventually be the exit status from the Nailgun server
50 51 52 53 54 55 56 |
# File 'lib/nailgun/client.rb', line 50 def receive_loop @loop ||= Thread.new { catch(:exit) do loop { receive_chunk } end } end |
#run(command, *args) ⇒ Object
Public: Run a command on the Client instance
command - the command string *args - any arguments to send
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/nailgun/client.rb', line 33 def run(command, *args) receive_loop # start the loop send_args args.flatten send_env opts[:env] send_dir opts[:dir] send_command command send_stdin opts[:stdin] receive_loop.join return nil end |