Class: Archipelago::Disco::ServiceDescription
- Inherits:
-
Object
- Object
- Archipelago::Disco::ServiceDescription
- Defined in:
- lib/archipelago/disco.rb
Overview
A Hash-like description of a service.
Constant Summary collapse
- IGNORABLE_ATTRIBUTES =
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Instance Method Summary collapse
-
#initialize(hash = {}) ⇒ ServiceDescription
constructor
Initialize this service description with a hash that describes its attributes.
-
#matches?(match) ⇒ Boolean
Returns whether this ServiceDescription matches the given
match
. -
#method_missing(meth, *args, &block) ⇒ Object
Forwards as much as possible to our Hash.
Constructor Details
#initialize(hash = {}) ⇒ ServiceDescription
Initialize this service description with a hash that describes its attributes.
204 205 206 |
# File 'lib/archipelago/disco.rb', line 204 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.
210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/archipelago/disco.rb', line 210 def method_missing(meth, *args, &block) if @attributes.respond_to?(meth) if block @attributes.send(meth, *args, &block) else @attributes.send(meth, *args) end else super(*args) end end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
199 200 201 |
# File 'lib/archipelago/disco.rb', line 199 def attributes @attributes end |
Instance Method Details
#matches?(match) ⇒ Boolean
Returns whether this ServiceDescription matches the given match
.
224 225 226 227 228 229 230 231 |
# File 'lib/archipelago/disco.rb', line 224 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 |