Class: Squiggle::LogLine
- Inherits:
-
Object
- Object
- Squiggle::LogLine
- Defined in:
- lib/squiggle/log_line.rb
Constant Summary collapse
- @@domain_parser =
DomainParser.new(File.dirname(__FILE__) + "/../../lib/effective_tld_names.dat")
Instance Attribute Summary collapse
-
#bytes ⇒ Object
Returns the value of attribute bytes.
-
#cache_sibling ⇒ Object
Returns the value of attribute cache_sibling.
-
#cache_status ⇒ Object
Returns the value of attribute cache_status.
-
#cached ⇒ Object
(also: #cached?)
Returns the value of attribute cached.
-
#client_ip ⇒ Object
Returns the value of attribute client_ip.
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#http_resp_code ⇒ Object
Returns the value of attribute http_resp_code.
-
#mime_type ⇒ Object
Returns the value of attribute mime_type.
-
#original_line ⇒ Object
Returns the value of attribute original_line.
-
#pageview ⇒ Object
(also: #pageview?)
Returns the value of attribute pageview.
-
#uri ⇒ Object
Returns the value of attribute uri.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #copy_line ⇒ Object
-
#cost ⇒ Object
Returns the cost for this line as a float TODO: Make the logserver an event machine and use EM::Deferrable here??.
-
#initialize {|_self| ... } ⇒ LogLine
constructor
A new instance of LogLine.
- #invalid? ⇒ Boolean
- #valid? ⇒ Boolean
Constructor Details
#initialize {|_self| ... } ⇒ LogLine
Returns a new instance of LogLine.
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/squiggle/log_line.rb', line 26 def initialize @errors = {} @invalid = false # Set defaults self.pageview = false self.cached = false yield self if block_given? class << @errors def to_s self.map { |(k,v)| "#{k} => #{v}" }.join(", ") end end end |
Instance Attribute Details
#bytes ⇒ Object
Returns the value of attribute bytes.
9 10 11 |
# File 'lib/squiggle/log_line.rb', line 9 def bytes @bytes end |
#cache_sibling ⇒ Object
Returns the value of attribute cache_sibling.
11 12 13 |
# File 'lib/squiggle/log_line.rb', line 11 def cache_sibling @cache_sibling end |
#cache_status ⇒ Object
Returns the value of attribute cache_status.
10 11 12 |
# File 'lib/squiggle/log_line.rb', line 10 def cache_status @cache_status end |
#cached ⇒ Object Also known as: cached?
Returns the value of attribute cached.
12 13 14 |
# File 'lib/squiggle/log_line.rb', line 12 def cached @cached end |
#client_ip ⇒ Object
Returns the value of attribute client_ip.
13 14 15 |
# File 'lib/squiggle/log_line.rb', line 13 def client_ip @client_ip end |
#created_at ⇒ Object
Returns the value of attribute created_at.
14 15 16 |
# File 'lib/squiggle/log_line.rb', line 14 def created_at @created_at end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
21 22 23 |
# File 'lib/squiggle/log_line.rb', line 21 def errors @errors end |
#http_resp_code ⇒ Object
Returns the value of attribute http_resp_code.
15 16 17 |
# File 'lib/squiggle/log_line.rb', line 15 def http_resp_code @http_resp_code end |
#mime_type ⇒ Object
Returns the value of attribute mime_type.
16 17 18 |
# File 'lib/squiggle/log_line.rb', line 16 def mime_type @mime_type end |
#original_line ⇒ Object
Returns the value of attribute original_line.
20 21 22 |
# File 'lib/squiggle/log_line.rb', line 20 def original_line @original_line end |
#pageview ⇒ Object Also known as: pageview?
Returns the value of attribute pageview.
17 18 19 |
# File 'lib/squiggle/log_line.rb', line 17 def pageview @pageview end |
#uri ⇒ Object
Returns the value of attribute uri.
18 19 20 |
# File 'lib/squiggle/log_line.rb', line 18 def uri @uri end |
#username ⇒ Object
Returns the value of attribute username.
19 20 21 |
# File 'lib/squiggle/log_line.rb', line 19 def username @username end |
Instance Method Details
#copy_line ⇒ Object
98 99 100 101 |
# File 'lib/squiggle/log_line.rb', line 98 def copy_line arr = [ bytes, cached, client_ip, created_at, uri.toplevel, uri.host, http_resp_code, mime_type, (pageview ? 1 : 0), uri.path, uri.scheme, username ] arr.map { |entry| "\"#{entry}\"" }.join(",") end |
#cost ⇒ Object
Returns the cost for this line as a float TODO: Make the logserver an event machine and use EM::Deferrable here??
93 94 95 96 |
# File 'lib/squiggle/log_line.rb', line 93 def cost pc = PolicyClient.new(self) pc.cost end |
#invalid? ⇒ Boolean
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/squiggle/log_line.rb', line 40 def invalid? # TODO: Run more checks and log if a check fails return true if @invalid if @uri.nil? @errors[:uri] = "Missing URL FROM #{@original_line}" return true end unless http_resp_code =~ /\A[+-]?\d+\Z/ @errors[:http_resp_code] = "Invalid HTTP Response Code" return true end if http_resp_code && http_resp_code.to_i == 407 @errors[:http_resp_code] = "407 code is ignored so setting to invalid" return true end end |
#valid? ⇒ Boolean
57 58 59 |
# File 'lib/squiggle/log_line.rb', line 57 def valid? !invalid? end |