Class: LintFu::Blessing

Inherits:
Object
  • Object
show all
Defined in:
lib/lint_fu/blessing.rb

Constant Summary collapse

VERBOSE_BLESSING_COMMENT =
/#\s*(lint|security)\s*[-:]\s*not\s*a?n?\s*([a-z0-9 ]*?) ?(as|because|;)\s*(.*)\s*/i
BLESSING_COMMENT =
/#\s*(lint|security)\s*[-:]\s*not\s*a?n?\s*([a-z0-9 ]*?)\s*/i

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(issue_class, sexp = nil, reason = nil) ⇒ Blessing

Returns a new instance of Blessing.



8
9
10
11
# File 'lib/lint_fu/blessing.rb', line 8

def initialize(issue_class, sexp=nil, reason=nil)
  @issue_class = issue_class
  @reason = reason
end

Instance Attribute Details

#issue_classObject

Returns the value of attribute issue_class.



6
7
8
# File 'lib/lint_fu/blessing.rb', line 6

def issue_class
  @issue_class
end

#reasonObject

Returns the value of attribute reason.



6
7
8
# File 'lib/lint_fu/blessing.rb', line 6

def reason
  @reason
end

#sexpObject

Returns the value of attribute sexp.



6
7
8
# File 'lib/lint_fu/blessing.rb', line 6

def sexp
  @sexp
end

Class Method Details

.parse(comments, sexp = nil) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/lint_fu/blessing.rb', line 24

def self.parse(comments, sexp=nil)
  comments = [comments] unless comments.kind_of?(Array)
  blessings = []

  comments.each do |line|
    match = VERBOSE_BLESSING_COMMENT.match(line)
    match = BLESSING_COMMENT.match(line) unless match
    next unless match
    issue_class = match[2].downcase.split(/\s+/).join('_').camelize
    reason      = match[3]
    blessings << Blessing.new(issue_class, sexp, reason)
  end

  return blessings
end

Instance Method Details

#applies_to?(klass) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
21
22
# File 'lib/lint_fu/blessing.rb', line 13

def applies_to?(klass)
  klass = klass.class unless klass.is_a?(Class)

  while klass
    return true if klass.name.index(self.issue_class)
    klass = klass.superclass
  end

  return false
end