Class: Ciclope::Host

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/ciclope/host.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection) ⇒ Host

Returns a new instance of Host.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/ciclope/host.rb', line 7

def initialize(connection)
  @connection = connection
  @config     = @connection.instance_variable_get '@config'

  # define every key as a method
  status.keys.each do |m|
    self.class.send :define_method, m.downcase do
      status[m]
    end
  end
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



5
6
7
# File 'lib/ciclope/host.rb', line 5

def config
  @config
end

#connectionObject (readonly)

Returns the value of attribute connection.



5
6
7
# File 'lib/ciclope/host.rb', line 5

def connection
  @connection
end

Instance Method Details

#<=>(other) ⇒ Object

sort by log file names, there is no way to do this by host names, may be there is another way to do this more clean TODO: find the right sort



38
39
40
41
42
43
44
45
46
# File 'lib/ciclope/host.rb', line 38

def <=>(other)
  if log_file == other._master_log_file
    -1
  elsif other.log_file == _master_log_file
    1
  else
    0
  end
end

#_master_log_fileObject

rename becuse there is a key with the same name



32
33
34
# File 'lib/ciclope/host.rb', line 32

def _master_log_file
  cleanfy_log_name relay_master_log_file.split('.').first
end

#log_fileObject



27
28
29
# File 'lib/ciclope/host.rb', line 27

def log_file
  cleanfy_log_name relay_log_file.split('.').first
end

#nameObject



19
20
21
# File 'lib/ciclope/host.rb', line 19

def name
  @config[:host]
end

#statusObject



23
24
25
# File 'lib/ciclope/host.rb', line 23

def status
  @connection.select_one 'SHOW SLAVE STATUS'
end