Class: Matchd::Rule::Respond

Inherits:
Matchd::Rule show all
Defined in:
lib/matchd/rule/respond.rb

Constant Summary

Constants inherited from Matchd::Rule

NotImplementedError, REGEXP_MATCHER, REGEXP_OPTIONS

Instance Attribute Summary collapse

Attributes inherited from Matchd::Rule

#raw

Instance Method Summary collapse

Methods inherited from Matchd::Rule

#call, #match_name, #match_resource_classes, #matches?, parse_match, parse_resource_class

Constructor Details

#initialize(options) ⇒ Respond

Returns a new instance of Respond.



2
3
4
5
# File 'lib/matchd/rule/respond.rb', line 2

def initialize(options)
  super
  @responses = options.fetch("respond")
end

Instance Attribute Details

#responsesObject (readonly)

Returns the value of attribute responses.



7
8
9
# File 'lib/matchd/rule/respond.rb', line 7

def responses
  @responses
end

Instance Method Details

#visit!(_server, _name, _resource_class, transaction) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/matchd/rule/respond.rb', line 9

def visit!(_server, _name, _resource_class, transaction)
  # Using the original Rule's resource_classes definition as a fallback, if
  # the response doesn't configure one.
  Matchd.Response(responses, @resource_classes).each do |resp|
    resp.call(transaction)
  end
end