Class: Snoopit::Snoopy
- Inherits:
-
Object
- Object
- Snoopit::Snoopy
- Defined in:
- lib/snoopit/snoopy.rb
Overview
Snoops around the specified file or directory of files
Instance Attribute Summary collapse
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
-
#glob ⇒ Object
readonly
Returns the value of attribute glob.
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#sniffers ⇒ Object
readonly
Returns the value of attribute sniffers.
Instance Method Summary collapse
- #as_json(options = nil) ⇒ Object
- #dir? ⇒ Boolean
- #glob? ⇒ Boolean
-
#initialize(name, params) ⇒ Snoopy
constructor
This creates a
Snoopy
which was specified in thesnoopers.json
file in thesnoopers
section. -
#input_check? ⇒ Boolean
Ensure we have something to snoop.
-
#setup_dir(params) ⇒ Object
Get the name of the directory to snoop if specified.
-
#setup_input(params) ⇒ Object
Get the name of the file to snoop if specified.
-
#setup_sniffers(params) ⇒ Object
Create the specified sniffers.
-
#sniff(file, line_no, line) ⇒ Object
Sniff specified line which is from the named file param file [String] file
Snoopy
is sniffing param line_no [Integer] line_n0Snoopy
is sniffing param line [String] lineSnoopy
is sniffing. - #to_json(*a) ⇒ Object
Constructor Details
#initialize(name, params) ⇒ Snoopy
This creates a Snoopy
which was specified in the snoopers.json
file in the snoopers
section
11 12 13 14 15 16 17 18 |
# File 'lib/snoopit/snoopy.rb', line 11 def initialize(name, params) @name = name @output = params['output'] setup_input params setup_dir params unless params['dir'].nil? input_check? setup_sniffers params end |
Instance Attribute Details
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
6 7 8 |
# File 'lib/snoopit/snoopy.rb', line 6 def dir @dir end |
#glob ⇒ Object (readonly)
Returns the value of attribute glob.
6 7 8 |
# File 'lib/snoopit/snoopy.rb', line 6 def glob @glob end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
6 7 8 |
# File 'lib/snoopit/snoopy.rb', line 6 def input @input end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/snoopit/snoopy.rb', line 6 def name @name end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
6 7 8 |
# File 'lib/snoopit/snoopy.rb', line 6 def output @output end |
#sniffers ⇒ Object (readonly)
Returns the value of attribute sniffers.
6 7 8 |
# File 'lib/snoopit/snoopy.rb', line 6 def sniffers @sniffers end |
Instance Method Details
#as_json(options = nil) ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/snoopit/snoopy.rb', line 68 def as_json(=nil) { name: @name, input: @input, dir: @dir, glob: @glob, sniffers: @sniffers } end |
#dir? ⇒ Boolean
50 51 52 |
# File 'lib/snoopit/snoopy.rb', line 50 def dir? ! @dir.nil? end |
#glob? ⇒ Boolean
54 55 56 |
# File 'lib/snoopit/snoopy.rb', line 54 def glob? ! @glob.nil? end |
#input_check? ⇒ Boolean
Ensure we have something to snoop
34 35 36 37 38 |
# File 'lib/snoopit/snoopy.rb', line 34 def input_check? return true unless @input.nil? return true unless @dir.nil? raise ArgumentError.new('Snooper JSON must contain either an input or dir parameter') end |
#setup_dir(params) ⇒ Object
Get the name of the directory to snoop if specified
28 29 30 31 |
# File 'lib/snoopit/snoopy.rb', line 28 def setup_dir(params) @dir = params['dir']['path'] @glob = params['dir']['glob'] end |
#setup_input(params) ⇒ Object
Get the name of the file to snoop if specified
22 23 24 |
# File 'lib/snoopit/snoopy.rb', line 22 def setup_input(params) @input = params['snoop'] end |
#setup_sniffers(params) ⇒ Object
Create the specified sniffers
42 43 44 45 46 47 48 |
# File 'lib/snoopit/snoopy.rb', line 42 def setup_sniffers(params) raise ArgumentError.new('Snooper JSON missing sniffers array') if params['sniffers'].nil? @sniffers = [] params['sniffers'].each do |sniffer| @sniffers << Sniffer.new(sniffer) end end |
#sniff(file, line_no, line) ⇒ Object
Sniff specified line which is from the named file param file [String] file Snoopy
is sniffing param line_no [Integer] line_n0 Snoopy
is sniffing param line [String] line Snoopy
is sniffing
62 63 64 65 66 |
# File 'lib/snoopit/snoopy.rb', line 62 def sniff(file, line_no, line) @sniffers.each do |sniffer| sniffer.track file, line_no, line end end |
#to_json(*a) ⇒ Object
78 79 80 |
# File 'lib/snoopit/snoopy.rb', line 78 def to_json(*a) as_json.to_json(*a) end |