Module: StinkingToe::Comment
- Defined in:
- lib/stinkingtoe/comment.rb
Class Method Summary collapse
- .action ⇒ Object
- .application ⇒ Object
- .clear! ⇒ Object
- .clear_job! ⇒ Object
- .connection_config ⇒ Object
- .construct_comment ⇒ Object
- .construct_inline_comment ⇒ Object
- .controller ⇒ Object
- .controller_with_namespace ⇒ Object
- .database ⇒ Object
- .db_host ⇒ Object
- .escape_sql_comment(str) ⇒ Object
- .hostname ⇒ Object
- .inline_annotations ⇒ Object
- .job ⇒ Object
- .line ⇒ Object
- .pid ⇒ Object
- .request_id ⇒ Object
- .sidekiq_job ⇒ Object
- .socket ⇒ Object
- .stinkingtoe_adapter ⇒ Object
- .stinkingtoe_adapter=(adapter) ⇒ Object
- .stinkingtoe_controller ⇒ Object
- .stinkingtoe_controller=(controller) ⇒ Object
- .stinkingtoe_job ⇒ Object
- .stinkingtoe_job=(job) ⇒ Object
- .update!(controller = nil) ⇒ Object
- .update_adapter!(adapter) ⇒ Object
- .update_job!(job) ⇒ Object
Class Method Details
.action ⇒ Object
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 |
.application ⇒ Object
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_config ⇒ Object
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_comment ⇒ Object
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_comment ⇒ Object
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 |
.controller ⇒ Object
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_namespace ⇒ Object
98 99 100 |
# File 'lib/stinkingtoe/comment.rb', line 98 def self.controller_with_namespace stinkingtoe_controller.class.name if stinkingtoe_controller end |
.database ⇒ Object
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_host ⇒ Object
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 |
.hostname ⇒ Object
135 136 137 |
# File 'lib/stinkingtoe/comment.rb', line 135 def self.hostname @cached_hostname ||= Socket.gethostname end |
.inline_annotations ⇒ Object
180 181 182 |
# File 'lib/stinkingtoe/comment.rb', line 180 def self.inline_annotations Thread.current[:stinkingtoe_inline_annotations] ||= [] end |
.job ⇒ Object
90 91 92 |
# File 'lib/stinkingtoe/comment.rb', line 90 def self.job stinkingtoe_job.class.name if stinkingtoe_job end |
.line ⇒ Object
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 |
.pid ⇒ Object
139 140 141 |
# File 'lib/stinkingtoe/comment.rb', line 139 def self.pid Process.pid end |
.request_id ⇒ Object
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_job ⇒ Object
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 |
.socket ⇒ Object
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_adapter ⇒ Object
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_controller ⇒ Object
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_job ⇒ Object
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 |