Class: Fluent::Plugin::Logcheck::RuleSet

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/fluent/plugin/logcheck/rule.rb

Overview

Collection of rules of the same type from a source

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, source_path)

Initialize rule set

Parameters:

  • type (Symbol)

    Rule type

  • source_path (String)

    Source file/directory path



118
119
120
121
122
# File 'lib/fluent/plugin/logcheck/rule.rb', line 118

def initialize(type, source_path)
  @type = type
  @source_path = source_path
  @rules = T.let([], T::Array[Rule])
end

Instance Attribute Details

#rulesArray<Rule> (readonly)

Returns:



106
107
108
# File 'lib/fluent/plugin/logcheck/rule.rb', line 106

def rules
  @rules
end

#source_pathString (readonly)

Returns:

  • (String)


112
113
114
# File 'lib/fluent/plugin/logcheck/rule.rb', line 112

def source_path
  @source_path
end

#typeSymbol (readonly)

Returns:

  • (Symbol)


109
110
111
# File 'lib/fluent/plugin/logcheck/rule.rb', line 109

def type
  @type
end

Instance Method Details

#add_rule(rule)

This method returns an undefined value.

Add rule to set

Parameters:

  • rule (Rule)

    Rule to add



127
128
129
# File 'lib/fluent/plugin/logcheck/rule.rb', line 127

def add_rule(rule)
  @rules << rule
end

#empty?Boolean

Check if rule set is empty

Returns:

  • (Boolean)

    True if no rules are loaded



157
158
159
# File 'lib/fluent/plugin/logcheck/rule.rb', line 157

def empty?
  @rules.empty?
end

#match(text) ⇒ Rule?

Find first matching rule

Parameters:

  • text (String)

    Text to match against rules

Returns:

  • (Rule, nil)

    First matching rule or nil if no match



135
136
137
# File 'lib/fluent/plugin/logcheck/rule.rb', line 135

def match(text)
  @rules.find { |rule| rule.match?(text) }
end

#match_all(text) ⇒ Array<Rule>

Find all matching rules

Parameters:

  • text (String)

    Text to match against rules

Returns:

  • (Array<Rule>)

    All matching rules (empty array if no matches)



143
144
145
# File 'lib/fluent/plugin/logcheck/rule.rb', line 143

def match_all(text)
  @rules.filter { |rule| rule.match?(text) }
end

#sizeInteger

Get rule count

Returns:

  • (Integer)

    Number of rules in this set



150
151
152
# File 'lib/fluent/plugin/logcheck/rule.rb', line 150

def size
  @rules.size
end