Class: Snoopit::Sniffer
- Inherits:
-
Object
- Object
- Snoopit::Sniffer
- Defined in:
- lib/snoopit/sniffer.rb
Instance Attribute Summary collapse
-
#after ⇒ Object
readonly
Returns the value of attribute after.
-
#before ⇒ Object
readonly
Returns the value of attribute before.
-
#comment ⇒ Object
readonly
Returns the value of attribute comment.
-
#notifiers ⇒ Object
readonly
Returns the value of attribute notifiers.
-
#pre_before ⇒ Object
readonly
Returns the value of attribute pre_before.
-
#regexp ⇒ Object
readonly
Returns the value of attribute regexp.
-
#sniffed ⇒ Object
readonly
Returns the value of attribute sniffed.
Instance Method Summary collapse
- #as_json(options = nil) ⇒ Object
-
#initialize(sniffer_params) ⇒ Sniffer
constructor
A new instance of Sniffer.
- #setup_notifiers(params) ⇒ Object
- #to_json(*a) ⇒ Object
- #track(file, line_no, line) ⇒ Object
- #tracking(line) ⇒ Object
Constructor Details
#initialize(sniffer_params) ⇒ Sniffer
Returns a new instance of Sniffer.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/snoopit/sniffer.rb', line 6 def initialize(sniffer_params) @before = sniffer_params['lines']['before'].nil? ? 2 : sniffer_params['lines']['before'] @pre_before = Register.new @before @after = sniffer_params['lines']['after'].nil? ? 2 : sniffer_params['lines']['after'] @comment = sniffer_params['comment'] @regexp = Regexp.new sniffer_params['regexp'] @notifiers = {} setup_notifiers sniffer_params @sniffed = [] end |
Instance Attribute Details
#after ⇒ Object (readonly)
Returns the value of attribute after.
4 5 6 |
# File 'lib/snoopit/sniffer.rb', line 4 def after @after end |
#before ⇒ Object (readonly)
Returns the value of attribute before.
4 5 6 |
# File 'lib/snoopit/sniffer.rb', line 4 def before @before end |
#comment ⇒ Object (readonly)
Returns the value of attribute comment.
4 5 6 |
# File 'lib/snoopit/sniffer.rb', line 4 def comment @comment end |
#notifiers ⇒ Object (readonly)
Returns the value of attribute notifiers.
4 5 6 |
# File 'lib/snoopit/sniffer.rb', line 4 def notifiers @notifiers end |
#pre_before ⇒ Object (readonly)
Returns the value of attribute pre_before.
4 5 6 |
# File 'lib/snoopit/sniffer.rb', line 4 def pre_before @pre_before end |
#regexp ⇒ Object (readonly)
Returns the value of attribute regexp.
4 5 6 |
# File 'lib/snoopit/sniffer.rb', line 4 def regexp @regexp end |
#sniffed ⇒ Object (readonly)
Returns the value of attribute sniffed.
4 5 6 |
# File 'lib/snoopit/sniffer.rb', line 4 def sniffed @sniffed end |
Instance Method Details
#as_json(options = nil) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/snoopit/sniffer.rb', line 35 def as_json(=nil) { before: @before, after: @after, comment: @comment, regexp: @regexp.to_json, sniffed: @sniffed, notifiers: @notifiers } end |
#setup_notifiers(params) ⇒ Object
17 18 19 |
# File 'lib/snoopit/sniffer.rb', line 17 def setup_notifiers(params) @notifiers = params['notify'] unless params['notify'].nil? end |
#to_json(*a) ⇒ Object
46 47 48 |
# File 'lib/snoopit/sniffer.rb', line 46 def to_json(*a) as_json.to_json(*a) end |
#track(file, line_no, line) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/snoopit/sniffer.rb', line 21 def track(file, line_no, line) matched = @regexp.match(line) do |m| @sniffed << Detected.new(@comment, @pre_before, @after, line, file, line_no) end @pre_before.push_front line if matched.nil? tracking line end |
#tracking(line) ⇒ Object
29 30 31 32 33 |
# File 'lib/snoopit/sniffer.rb', line 29 def tracking(line) @sniffed.each do |detected| detected.track line unless detected.finished? end end |