Class: Archipelago::Disco::ServiceDescription

Inherits:
Object
  • Object
show all
Defined in:
lib/archipelago/disco.rb

Overview

A Hash-like description of a service.

Direct Known Subclasses

Query, Record

Constant Summary collapse

IGNORABLE_ATTRIBUTES =

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ ServiceDescription

Initialize this service description with a hash that describes its attributes.



205
206
207
# File 'lib/archipelago/disco.rb', line 205

def initialize(hash = {})
  @attributes = hash
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

Forwards as much as possible to our Hash.



211
212
213
214
215
216
217
# File 'lib/archipelago/disco.rb', line 211

def method_missing(meth, *args, &block)
  if @attributes.respond_to?(meth)
    @attributes.send(meth, *args, &block)
  else
    super(*args)
  end
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



200
201
202
# File 'lib/archipelago/disco.rb', line 200

def attributes
  @attributes
end

Instance Method Details

#matches?(match) ⇒ Boolean

Returns whether this ServiceDescription matches the given match.

Returns:

  • (Boolean)


221
222
223
224
225
226
227
228
# File 'lib/archipelago/disco.rb', line 221

def matches?(match)
  match.each do |key, value|
    unless IGNORABLE_ATTRIBUTES.include?(key)
      return false unless @attributes.include?(key) && (value.nil? || @attributes[key] == value)
    end
  end
  true
end