Class: HAProxyCluster::Member
- Inherits:
-
Object
- Object
- HAProxyCluster::Member
- Defined in:
- lib/haproxy_cluster/member.rb
Instance Attribute Summary collapse
-
#backends ⇒ Object
Returns the value of attribute backends.
-
#log ⇒ Object
Returns the value of attribute log.
-
#name ⇒ Object
Returns the value of attribute name.
-
#source ⇒ Object
Returns the value of attribute source.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(source, log) ⇒ Member
constructor
A new instance of Member.
-
#method_missing(m, *args, &block) ⇒ Object
Allow Backends to be accessed by dot-notation.
- #poll! ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(source, log) ⇒ Member
Returns a new instance of Member.
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/haproxy_cluster/member.rb', line 9 def initialize(source,log) @source = source @log = log @backends = Hash.new { |h,k| h[k] = Backend.new({},self) } if source =~ /https?:/ @type = :url @name = URI.parse(@source).host else @type = :file @name = @source end poll! end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
Allow Backends to be accessed by dot-notation
44 45 46 47 48 49 50 |
# File 'lib/haproxy_cluster/member.rb', line 44 def method_missing(m, *args, &block) if @backends.has_key? m @backends[m] else super end end |
Instance Attribute Details
#backends ⇒ Object
Returns the value of attribute backends.
23 24 25 |
# File 'lib/haproxy_cluster/member.rb', line 23 def backends @backends end |
#log ⇒ Object
Returns the value of attribute log.
23 24 25 |
# File 'lib/haproxy_cluster/member.rb', line 23 def log @log end |
#name ⇒ Object
Returns the value of attribute name.
23 24 25 |
# File 'lib/haproxy_cluster/member.rb', line 23 def name @name end |
#source ⇒ Object
Returns the value of attribute source.
23 24 25 |
# File 'lib/haproxy_cluster/member.rb', line 23 def source @source end |
#type ⇒ Object
Returns the value of attribute type.
23 24 25 |
# File 'lib/haproxy_cluster/member.rb', line 23 def type @type end |
Instance Method Details
#poll! ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/haproxy_cluster/member.rb', line 26 def poll! csv = case @type when :url RestClient.get(@source + ';csv') when :file File.read(@source) end CSV.parse(csv.gsub(/^# /,'').gsub(/,$/,''), { :headers => :first_row, :converters => :all, :header_converters => [:downcase,:symbol] } ) do |row| case row[:type] when Backend::TYPE_ID @backends[ row[:pxname].to_sym ].stats = row.to_hash when Server::TYPE_ID @backends[ row[:pxname].to_sym ].servers[ row[:svname] ].stats = row.to_hash end end end |
#to_s ⇒ Object
24 |
# File 'lib/haproxy_cluster/member.rb', line 24 def to_s; @name; end |