Class: Scryer::Rule

Inherits:
Object
  • Object
show all
Defined in:
lib/scryer/rule.rb

Overview

Base class for a single detection rule. Subclasses implement #scan and return an Array of Finding. Every rule gets the parsed sexp tree (so it doesn't have to re-parse), the raw source (for snippet extraction), and the relative file path (for reporting).

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file:, source:, sexp:) ⇒ Rule

Returns a new instance of Rule.



16
17
18
19
20
# File 'lib/scryer/rule.rb', line 16

def initialize(file:, source:, sexp:)
  @file = file
  @source = source
  @sexp = sexp
end

Class Attribute Details

.categoryObject

Returns the value of attribute category.



8
9
10
# File 'lib/scryer/rule.rb', line 8

def category
  @category
end

.default_severityObject

Returns the value of attribute default_severity.



8
9
10
# File 'lib/scryer/rule.rb', line 8

def default_severity
  @default_severity
end

.rule_idObject

Returns the value of attribute rule_id.



8
9
10
# File 'lib/scryer/rule.rb', line 8

def rule_id
  @rule_id
end

.titleObject

Returns the value of attribute title.



8
9
10
# File 'lib/scryer/rule.rb', line 8

def title
  @title
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



22
23
24
# File 'lib/scryer/rule.rb', line 22

def file
  @file
end

#sexpObject (readonly)

Returns the value of attribute sexp.



22
23
24
# File 'lib/scryer/rule.rb', line 22

def sexp
  @sexp
end

#sourceObject (readonly)

Returns the value of attribute source.



22
23
24
# File 'lib/scryer/rule.rb', line 22

def source
  @source
end

Class Method Details

.inherited(subclass) ⇒ Object



10
11
12
13
# File 'lib/scryer/rule.rb', line 10

def inherited(subclass)
  super
  Scryer::RuleSet.register(subclass)
end

Instance Method Details

#scanObject

Raises:

  • (NotImplementedError)


24
25
26
# File 'lib/scryer/rule.rb', line 24

def scan
  raise NotImplementedError, "#{self.class} must implement #scan"
end