Class: Matchd::Rule::Append

Inherits:
Matchd::Rule show all
Defined in:
lib/matchd/rule/append.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) ⇒ Append

Returns a new instance of Append.



2
3
4
5
6
7
8
9
10
11
12
13
# File 'lib/matchd/rule/append.rb', line 2

def initialize(options)
  super
  opts = options.fetch("append_question")

  if opts.is_a?(Hash)
    @append_questions = Array(opts.fetch("resource_class"))
    @transaction_options = Matchd::Helpers.extract_options(%w(ttl name section), opts)
  else
    @append_questions = Array(opts)
    @transaction_options = {}
  end
end

Instance Attribute Details

#append_questionsObject (readonly)

Returns the value of attribute append_questions.



15
16
17
# File 'lib/matchd/rule/append.rb', line 15

def append_questions
  @append_questions
end

#transaction_optionsObject (readonly)

Returns the value of attribute transaction_options.



15
16
17
# File 'lib/matchd/rule/append.rb', line 15

def transaction_options
  @transaction_options
end

Instance Method Details

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



17
18
19
20
21
22
# File 'lib/matchd/rule/append.rb', line 17

def visit!(_server, _name, _resource_class, transaction)
  transaction.append_question!
  Matchd::Rule.parse_resource_class(append_questions).each do |append_resource_class|
    transaction.append!(transaction.name, append_resource_class, transaction_options)
  end
end