Class: NetworkClipboard::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/network_clipboard/config.rb

Constant Summary collapse

DEFAULTS =
{
  # http://tools.ietf.org/html/rfc2365
  # Ultimately though, we'd need to reserve a specific address
  # or implemend MADCAP or ZMAAP (Except nothing supports those).
  multicast_ip: '239.255.193.172',
  # Randomly picked by mashing the keyboard.
  port: 53712,
  # This file needs to be shared to enable clipboard transfer.
  secret_file: '~/.networkclipboard.secret',
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename = '~/.networkclipboard.conf') ⇒ Config

Returns a new instance of Config.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/network_clipboard/config.rb', line 19

def initialize(filename='~/.networkclipboard.conf')
  filename = File.expand_path(filename)
  begin
    parsed = YAML.load(File.read(filename))
  rescue Errno::ENOENT
    parsed = {}
  end
  config = DEFAULTS.merge(parsed)

  secret_filename = File.expand_path(config[:secret_file])
  begin
    @secret = [File.read(secret_filename)].pack('H*')
  rescue Errno::ENOENT
    @secret = SecureRandom.random_bytes(32)
    File.open(secret_filename,'w',0400){|f|f.write(secret.unpack('H*')[0])}
  end

  @multicast_ip = config[:multicast_ip]
  @port = config[:port]
  @client_id = SecureRandom.uuid.gsub('-','')
end

Instance Attribute Details

#client_idObject (readonly)

Returns the value of attribute client_id.



17
18
19
# File 'lib/network_clipboard/config.rb', line 17

def client_id
  @client_id
end

#multicast_ipObject (readonly)

Returns the value of attribute multicast_ip.



17
18
19
# File 'lib/network_clipboard/config.rb', line 17

def multicast_ip
  @multicast_ip
end

#portObject (readonly)

Returns the value of attribute port.



17
18
19
# File 'lib/network_clipboard/config.rb', line 17

def port
  @port
end

#secretObject (readonly)

Returns the value of attribute secret.



17
18
19
# File 'lib/network_clipboard/config.rb', line 17

def secret
  @secret
end