Class: NewRelic::Agent::AttributeFilterRule

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute_name, destinations, is_include) ⇒ AttributeFilterRule

Returns a new instance of AttributeFilterRule.



275
276
277
278
279
280
# File 'lib/new_relic/agent/attribute_filter.rb', line 275

def initialize(attribute_name, destinations, is_include)
  @attribute_name = attribute_name.sub(/\*$/, '')
  @wildcard = attribute_name.end_with?('*')
  @is_include = is_include
  @destinations = is_include ? destinations : ~destinations
end

Instance Attribute Details

#attribute_nameObject (readonly)

Returns the value of attribute attribute_name.



273
274
275
# File 'lib/new_relic/agent/attribute_filter.rb', line 273

def attribute_name
  @attribute_name
end

#destinationsObject (readonly)

Returns the value of attribute destinations.



273
274
275
# File 'lib/new_relic/agent/attribute_filter.rb', line 273

def destinations
  @destinations
end

#is_includeObject (readonly)

Returns the value of attribute is_include.



273
274
275
# File 'lib/new_relic/agent/attribute_filter.rb', line 273

def is_include
  @is_include
end

#wildcardObject (readonly)

Returns the value of attribute wildcard.



273
274
275
# File 'lib/new_relic/agent/attribute_filter.rb', line 273

def wildcard
  @wildcard
end

Instance Method Details

#<=>(other) ⇒ Object

Rules are sorted from least specific to most specific

All else being the same, wildcards are considered less specific All else being the same, include rules are less specific than excludes



286
287
288
289
290
291
292
293
294
295
296
297
298
299
# File 'lib/new_relic/agent/attribute_filter.rb', line 286

def <=>(other)
  name_cmp = @attribute_name <=> other.attribute_name
  return name_cmp unless name_cmp == 0

  if wildcard != other.wildcard
    return wildcard ? -1 : 1
  end

  if is_include != other.is_include
    return is_include ? -1 : 1
  end

  return 0
end

#empty?Boolean

Returns:

  • (Boolean)


309
310
311
312
313
314
315
# File 'lib/new_relic/agent/attribute_filter.rb', line 309

def empty?
  if is_include
    @destinations == AttributeFilter::DST_NONE
  else
    @destinations == AttributeFilter::DST_ALL
  end
end

#match?(name) ⇒ Boolean

Returns:

  • (Boolean)


301
302
303
304
305
306
307
# File 'lib/new_relic/agent/attribute_filter.rb', line 301

def match?(name)
  if wildcard
    name.start_with?(@attribute_name)
  else
    @attribute_name == name
  end
end