Class: Zget::Zput

Inherits:
Command show all
Defined in:
lib/zget/command/zput.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_alias: SecureRandom.hex(2), bind_address: "0.0.0.0", file:, port: 6666) ⇒ Zput

Returns a new instance of Zput.



5
6
7
8
9
10
11
12
13
14
# File 'lib/zget/command/zput.rb', line 5

def initialize(_alias: SecureRandom.hex(2), bind_address: "0.0.0.0", file:, port: 6666)
  @bind_address = IPAddr.new bind_address
  @file = file.tap do |f|
    raise InvalidFileError unless File.exist? f
  end
  @alias = _alias
  @port = port.tap do |p|
    raise InvalidPortError unless p.between? 0, 65535
  end
end

Instance Attribute Details

#aliasObject (readonly)

Returns the value of attribute alias.



3
4
5
# File 'lib/zget/command/zput.rb', line 3

def alias
  @alias
end

#bind_addressObject (readonly)

Returns the value of attribute bind_address.



3
4
5
# File 'lib/zget/command/zput.rb', line 3

def bind_address
  @bind_address
end

#fileObject (readonly)

Returns the value of attribute file.



3
4
5
# File 'lib/zget/command/zput.rb', line 3

def file
  @file
end

#portObject (readonly)

Returns the value of attribute port.



3
4
5
# File 'lib/zget/command/zput.rb', line 3

def port
  @port
end

Instance Method Details

#callObject



16
17
18
19
20
21
22
23
24
# File 'lib/zget/command/zput.rb', line 16

def call
  puts "Download this file using `zget #{File.basename file}` or `zget #{@alias}`"

  hashes.each do |hash|
    DNSSD.register hash, "_http._tcp", nil, port
  end

  server.start
end