Class: NewRelic::Agent::RulesEngine::Rule

Inherits:
Object
  • Object
show all
Defined in:
lib/new_relic/agent/rules_engine.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Rule

Returns a new instance of Rule.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/new_relic/agent/rules_engine.rb', line 33

def initialize(options)
  if !options['match_expression']
    raise ArgumentError.new('missing required match_expression')
  end
  if !options['replacement'] && !options['ignore']
    raise ArgumentError.new('must specify replacement when ignore is false')
  end

  @match_expression = Regexp.new(options['match_expression'])
  @replacement      = options['replacement']
  @ignore           = options['ignore'] || false
  @eval_order       = options['eval_order'] || 0
  @replace_all      = options['replace_all'] || false
  @each_segment     = options['each_segment'] || false
  @terminate_chain  = options['terminate_chain'] || false
end

Instance Attribute Details

#each_segmentObject (readonly)

Returns the value of attribute each_segment.



30
31
32
# File 'lib/new_relic/agent/rules_engine.rb', line 30

def each_segment
  @each_segment
end

#eval_orderObject (readonly)

Returns the value of attribute eval_order.



30
31
32
# File 'lib/new_relic/agent/rules_engine.rb', line 30

def eval_order
  @eval_order
end

#ignoreObject (readonly)

Returns the value of attribute ignore.



30
31
32
# File 'lib/new_relic/agent/rules_engine.rb', line 30

def ignore
  @ignore
end

#match_expressionObject (readonly)

Returns the value of attribute match_expression.



30
31
32
# File 'lib/new_relic/agent/rules_engine.rb', line 30

def match_expression
  @match_expression
end

#replace_allObject (readonly)

Returns the value of attribute replace_all.



30
31
32
# File 'lib/new_relic/agent/rules_engine.rb', line 30

def replace_all
  @replace_all
end

#replacementObject (readonly)

Returns the value of attribute replacement.



30
31
32
# File 'lib/new_relic/agent/rules_engine.rb', line 30

def replacement
  @replacement
end

#terminate_chainObject (readonly)

Returns the value of attribute terminate_chain.



30
31
32
# File 'lib/new_relic/agent/rules_engine.rb', line 30

def terminate_chain
  @terminate_chain
end

Instance Method Details

#<=>(other) ⇒ Object



66
67
68
# File 'lib/new_relic/agent/rules_engine.rb', line 66

def <=>(other)
  eval_order <=> other.eval_order
end

#apply(string) ⇒ Object



50
51
52
53
54
# File 'lib/new_relic/agent/rules_engine.rb', line 50

def apply(string)
  method = @replace_all ? :gsub : :sub
  result = string.send(method, @match_expression, @replacement)
  [result, result != string]
end

#map_to_list(list) ⇒ Object



56
57
58
59
60
61
62
63
64
# File 'lib/new_relic/agent/rules_engine.rb', line 56

def map_to_list(list)
  matched = false
  result = list.map do |string|
    str_result, str_match = apply(string)
    matched ||= str_match
    str_result
  end
  [result, matched]
end