Module: StinkingToe::Comment

Defined in:
lib/stinkingtoe/comment.rb

Class Method Summary collapse

Class Method Details

.actionObject



102
103
104
# File 'lib/stinkingtoe/comment.rb', line 102

def self.action
  stinkingtoe_controller.action_name if stinkingtoe_controller.respond_to? :action_name
end

.applicationObject



80
81
82
83
84
85
86
87
88
# File 'lib/stinkingtoe/comment.rb', line 80

def self.application
  if defined?(Rails.application)
    StinkingToe.application_name ||= Rails.application.class.name.split("::").first
  else
    StinkingToe.application_name ||= "rails"
  end

  StinkingToe.application_name
end

.clear!Object



47
48
49
# File 'lib/stinkingtoe/comment.rb', line 47

def self.clear!
  self.stinkingtoe_controller = nil
end

.clear_job!Object



51
52
53
# File 'lib/stinkingtoe/comment.rb', line 51

def self.clear_job!
  self.stinkingtoe_job = nil
end

.connection_configObject



168
169
170
171
# File 'lib/stinkingtoe/comment.rb', line 168

def self.connection_config
  return if stinkingtoe_adapter.pool.nil?
  stinkingtoe_adapter.pool.spec.config
end

.construct_commentObject



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/stinkingtoe/comment.rb', line 22

def self.construct_comment
  ret = String.new
  self.components.each do |c|
    component_value = self.send(c)
    if component_value.present?
      ret << "#{c}:#{component_value},"
    end
  end
  ret.chop!
  ret = self.escape_sql_comment(ret)
  ret
end

.construct_inline_commentObject



35
36
37
38
# File 'lib/stinkingtoe/comment.rb', line 35

def self.construct_inline_comment
  return nil if inline_annotations.none?
  escape_sql_comment(inline_annotations.join)
end

.controllerObject



94
95
96
# File 'lib/stinkingtoe/comment.rb', line 94

def self.controller
  stinkingtoe_controller.controller_name if stinkingtoe_controller.respond_to? :controller_name
end

.controller_with_namespaceObject



98
99
100
# File 'lib/stinkingtoe/comment.rb', line 98

def self.controller_with_namespace
  stinkingtoe_controller.class.name if stinkingtoe_controller
end

.databaseObject



161
162
163
164
165
# File 'lib/stinkingtoe/comment.rb', line 161

def self.database
  if self.connection_config.present?
    self.connection_config[:database]
  end
end

.db_hostObject



155
156
157
158
159
# File 'lib/stinkingtoe/comment.rb', line 155

def self.db_host
  if self.connection_config.present?
    self.connection_config[:host]
  end
end

.escape_sql_comment(str) ⇒ Object



40
41
42
43
44
45
# File 'lib/stinkingtoe/comment.rb', line 40

def self.escape_sql_comment(str)
  while str.include?('/*') || str.include?('*/')
    str = str.gsub('/*', '').gsub('*/', '')
  end
  str
end

.hostnameObject



135
136
137
# File 'lib/stinkingtoe/comment.rb', line 135

def self.hostname
  @cached_hostname ||= Socket.gethostname
end

.inline_annotationsObject



180
181
182
# File 'lib/stinkingtoe/comment.rb', line 180

def self.inline_annotations
  Thread.current[:stinkingtoe_inline_annotations] ||= []
end

.jobObject



90
91
92
# File 'lib/stinkingtoe/comment.rb', line 90

def self.job
  stinkingtoe_job.class.name if stinkingtoe_job
end

.lineObject



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/stinkingtoe/comment.rb', line 112

def self.line
  StinkingToe::Comment.lines_to_ignore ||= DEFAULT_LINES_TO_IGNORE_REGEX

  last_line = caller_locations.detect do |loc|
    !loc.path.match?(StinkingToe::Comment.lines_to_ignore)
  end
  if last_line
    last_line = last_line.to_s

    root = if defined?(Rails) && Rails.respond_to?(:root)
      Rails.root.to_s
    elsif defined?(RAILS_ROOT)
      RAILS_ROOT
    else
      ""
    end
    if last_line.start_with? root
      last_line = last_line[root.length..-1]
    end
    last_line
  end
end

.pidObject



139
140
141
# File 'lib/stinkingtoe/comment.rb', line 139

def self.pid
  Process.pid
end

.request_idObject



143
144
145
146
147
# File 'lib/stinkingtoe/comment.rb', line 143

def self.request_id
  if stinkingtoe_controller.respond_to?(:request) && stinkingtoe_controller.request.respond_to?(:uuid)
    stinkingtoe_controller.request.uuid
  end
end

.sidekiq_jobObject



106
107
108
# File 'lib/stinkingtoe/comment.rb', line 106

def self.sidekiq_job
  stinkingtoe_job["class"] if stinkingtoe_job && stinkingtoe_job.respond_to?(:[])
end

.socketObject



149
150
151
152
153
# File 'lib/stinkingtoe/comment.rb', line 149

def self.socket
  if self.connection_config.present?
    self.connection_config[:socket]
  end
end

.stinkingtoe_adapterObject



76
77
78
# File 'lib/stinkingtoe/comment.rb', line 76

def self.stinkingtoe_adapter
  Thread.current[:stinkingtoe_adapter]
end

.stinkingtoe_adapter=(adapter) ⇒ Object



72
73
74
# File 'lib/stinkingtoe/comment.rb', line 72

def self.stinkingtoe_adapter=(adapter)
  Thread.current[:stinkingtoe_adapter] = adapter
end

.stinkingtoe_controllerObject



60
61
62
# File 'lib/stinkingtoe/comment.rb', line 60

def self.stinkingtoe_controller
  Thread.current[:stinkingtoe_controller]
end

.stinkingtoe_controller=(controller) ⇒ Object



56
57
58
# File 'lib/stinkingtoe/comment.rb', line 56

def self.stinkingtoe_controller=(controller)
  Thread.current[:stinkingtoe_controller] = controller
end

.stinkingtoe_jobObject



68
69
70
# File 'lib/stinkingtoe/comment.rb', line 68

def self.stinkingtoe_job
  Thread.current[:stinkingtoe_job]
end

.stinkingtoe_job=(job) ⇒ Object



64
65
66
# File 'lib/stinkingtoe/comment.rb', line 64

def self.stinkingtoe_job=(job)
  Thread.current[:stinkingtoe_job] = job
end

.update!(controller = nil) ⇒ Object



10
11
12
# File 'lib/stinkingtoe/comment.rb', line 10

def self.update!(controller = nil)
  self.stinkingtoe_controller = controller
end

.update_adapter!(adapter) ⇒ Object



18
19
20
# File 'lib/stinkingtoe/comment.rb', line 18

def self.update_adapter!(adapter)
  self.stinkingtoe_adapter = adapter
end

.update_job!(job) ⇒ Object



14
15
16
# File 'lib/stinkingtoe/comment.rb', line 14

def self.update_job!(job)
  self.stinkingtoe_job = job
end