Class: Pair::Config

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host = HOST, input = STDIN, output = STDOUT) ⇒ Config

Returns a new instance of Config.



15
16
17
18
19
# File 'lib/pair/config.rb', line 15

def initialize(host = HOST, input = STDIN, output = STDOUT)
  self.host   = host
  self.input  = input
  self.output = output
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/pair/config.rb', line 21

def method_missing(method, *args, &block)
  method = method.to_s

  if method =~ /=$/ # setter
    self[method.gsub(/=$/,'').to_sym] = [*args].first
  else
    self[method.to_sym] || super
  end
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



13
14
15
# File 'lib/pair/config.rb', line 13

def host
  @host
end

#inputObject

Returns the value of attribute input.



13
14
15
# File 'lib/pair/config.rb', line 13

def input
  @input
end

#outputObject

Returns the value of attribute output.



13
14
15
# File 'lib/pair/config.rb', line 13

def output
  @output
end

Instance Method Details

#api_tokenObject



31
32
33
# File 'lib/pair/config.rb', line 31

def api_token
  self[:api_token]
end

#growl_enabled?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/pair/config.rb', line 39

def growl_enabled?
  self[:growl_enabled]
end

#ssh_enabled?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/pair/config.rb', line 35

def ssh_enabled?
  self[:ssh_enabled]
end

#ssh_on?Boolean

FIXME: Does this belong in config?

Returns:

  • (Boolean)


44
45
46
47
48
49
50
# File 'lib/pair/config.rb', line 44

def ssh_on?
  if Pair::OS.os_x?
    `systemsetup -getremotelogin`.match("Remote Login: On")
  elsif Pair::OS.linux?
    `ps aux | grep sshd | grep -v grep` != ""
  end
end

#update(options = {}) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/pair/config.rb', line 52

def update(options = {})
  if options.is_a? Hash
    options.each do |key, value|
      self[key] = value
    end
  end
end