Class: OneApm::Support::RenameRulesEngine::Rule

Inherits:
Object
  • Object
show all
Defined in:
lib/one_apm/support/rename_rules_engine/external_rename_rule.rb

Constant Summary collapse

OA_RENAME_SEPARATOR =
'/'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Rule

Returns a new instance of Rule.



56
57
58
59
60
61
62
63
# File 'lib/one_apm/support/rename_rules_engine/external_rename_rule.rb', line 56

def initialize(hash)
  @replacement = hash['replacement']
  @state = hash['state'].to_i
  @ignore = hash['ignore']
  @priority = hash['priority'].to_i
  @match_expressions = hash['match_expression'].map { |match_expression| MatchExpression::Engine.create_match_expression(match_expression) }
  @rename_rules = hash['rename'].map { |rename| Rename::Engine.create_rename_rules(rename) }
end

Instance Attribute Details

#ignoreObject

Returns the value of attribute ignore.



54
55
56
# File 'lib/one_apm/support/rename_rules_engine/external_rename_rule.rb', line 54

def ignore
  @ignore
end

#match_expressionsObject

Returns the value of attribute match_expressions.



54
55
56
# File 'lib/one_apm/support/rename_rules_engine/external_rename_rule.rb', line 54

def match_expressions
  @match_expressions
end

#priorityObject

Returns the value of attribute priority.



54
55
56
# File 'lib/one_apm/support/rename_rules_engine/external_rename_rule.rb', line 54

def priority
  @priority
end

#rename_rulesObject

Returns the value of attribute rename_rules.



54
55
56
# File 'lib/one_apm/support/rename_rules_engine/external_rename_rule.rb', line 54

def rename_rules
  @rename_rules
end

#replacementObject

Returns the value of attribute replacement.



54
55
56
# File 'lib/one_apm/support/rename_rules_engine/external_rename_rule.rb', line 54

def replacement
  @replacement
end

#stateObject

Returns the value of attribute state.



54
55
56
# File 'lib/one_apm/support/rename_rules_engine/external_rename_rule.rb', line 54

def state
  @state
end

Instance Method Details

#apply(request) ⇒ Object



75
76
77
78
79
# File 'lib/one_apm/support/rename_rules_engine/external_rename_rule.rb', line 75

def apply(request)
  rename_rules.map do |rename_rule|
    rename_rule.segment(request)
  end.join(OA_RENAME_SEPARATOR)
end

#enable?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/one_apm/support/rename_rules_engine/external_rename_rule.rb', line 71

def enable?
  !ignore && state == 0
end

#should_rename?(request) ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
68
69
# File 'lib/one_apm/support/rename_rules_engine/external_rename_rule.rb', line 65

def should_rename?(request)
  match_expressions.map do |match_expression|
    match_expression.match?(request)
  end.all?
end