Class: Agentlog::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/agentlog/context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:, method:, controller:, action:, format:, params:) ⇒ Context

Returns a new instance of Context.



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

def initialize(path:, method:, controller:, action:, format:, params:)
  @path = path
  @method = method
  @controller = controller
  @action = action
  @format = format
  @params = params
  @jobs = []
  @sql_groups = Hash.new { |hash, key| hash[key] = { count: 0, duration: 0.0 } }
end

Instance Attribute Details

#actionObject

Returns the value of attribute action.



6
7
8
# File 'lib/agentlog/context.rb', line 6

def action
  @action
end

#controllerObject

Returns the value of attribute controller.



6
7
8
# File 'lib/agentlog/context.rb', line 6

def controller
  @controller
end

#formatObject

Returns the value of attribute format.



6
7
8
# File 'lib/agentlog/context.rb', line 6

def format
  @format
end

#jobsObject (readonly)

Returns the value of attribute jobs.



5
6
7
# File 'lib/agentlog/context.rb', line 5

def jobs
  @jobs
end

#methodObject

Returns the value of attribute method.



6
7
8
# File 'lib/agentlog/context.rb', line 6

def method
  @method
end

#paramsObject (readonly)

Returns the value of attribute params.



5
6
7
# File 'lib/agentlog/context.rb', line 5

def params
  @params
end

#pathObject

Returns the value of attribute path.



6
7
8
# File 'lib/agentlog/context.rb', line 6

def path
  @path
end

#sql_groupsObject (readonly)

Returns the value of attribute sql_groups.



5
6
7
# File 'lib/agentlog/context.rb', line 5

def sql_groups
  @sql_groups
end

#started_atObject

Returns the value of attribute started_at.



6
7
8
# File 'lib/agentlog/context.rb', line 6

def started_at
  @started_at
end

Instance Method Details

#add_job(job:) ⇒ Object



29
30
31
# File 'lib/agentlog/context.rb', line 29

def add_job(job:)
  jobs << job
end

#add_sql(name:, duration_ms:) ⇒ Object



24
25
26
27
# File 'lib/agentlog/context.rb', line 24

def add_sql(name:, duration_ms:)
  sql_groups[name][:count] += 1
  sql_groups[name][:duration] += duration_ms
end