Class: Velocity::Instance::SearchCollection::Status::ServiceStatus

Inherits:
Object
  • Object
show all
Defined in:
lib/acceleration/velocity.rb

Overview

An abstracted wrapper for the various parts of the collection status XML returned by Velocity.

Direct Known Subclasses

CrawlerStatus, IndexerStatus

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doc) ⇒ ServiceStatus

Create a new service status wrapper



796
797
798
799
# File 'lib/acceleration/velocity.rb', line 796

def initialize(doc)
  @doc = doc
  @attrs = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

Capture attributes accessed as instance variables



832
833
834
835
836
837
838
839
840
841
# File 'lib/acceleration/velocity.rb', line 832

def method_missing(function, *args, &block)
  f = function.to_s.dasherize
  if doc.attributes.member? f
    attribute f
  elsif doc.attributes.member? 'n-' + f
    attribute 'n-' + f
  else
    super
  end
end

Instance Attribute Details

#docObject

The raw document describing the status



794
795
796
# File 'lib/acceleration/velocity.rb', line 794

def doc
  @doc
end

Instance Method Details

#attribute(attr) ⇒ Object

Get a single attribute



825
826
827
# File 'lib/acceleration/velocity.rb', line 825

def attribute(attr)
  doc.attribute(attr).value
end

#attributesObject

Return a symbol-keyed hash of all attributes

This method resolves the value of all of the Nokogiri attributes so that you don’t have to.



814
815
816
817
818
819
820
# File 'lib/acceleration/velocity.rb', line 814

def attributes
  return @attrs unless @attrs.empty?
  doc.attributes.each do |key, nattr|
    @attrs[key.to_sym.dedasherize] = nattr.value
  end
  @attrs
end

#has_status?Boolean

Ensure that the status is actually there

Returns:

  • (Boolean)


804
805
806
# File 'lib/acceleration/velocity.rb', line 804

def has_status?
  !doc.nil?
end

#respond_to_missing?(function, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


843
844
845
846
847
848
849
850
# File 'lib/acceleration/velocity.rb', line 843

def respond_to_missing?(function, include_private = false)
  f = function.to_s.dasherize
  if doc.attributes.member?(f) || doc.attributes.member?('n-' + f)
    true
  else
    super(function, include_private)
  end
end