Module: ActiveRecord::Comments

Defined in:
lib/active_record/comments.rb,
lib/active_record/comments/version.rb,
lib/active_record/comments/execute_with_comments.rb

Defined Under Namespace

Modules: ExecuteWithComments

Constant Summary collapse

VERSION =
"0.8.0"
@@prepend =
false

Class Method Summary collapse

Class Method Details

.comment(comment) ⇒ Object



14
15
16
17
18
19
# File 'lib/active_record/comments.rb', line 14

def comment(comment)
  current_comments << comment
  yield
ensure
  current_comments.pop
end

.current_commentObject



35
36
37
# File 'lib/active_record/comments.rb', line 35

def current_comment
  current_comments.join(" ") if current_comments.present?
end

.current_commentsObject



31
32
33
# File 'lib/active_record/comments.rb', line 31

def current_comments
  Thread.current[:ar_comments] ||= []
end

.prepend=(prepend) ⇒ Object



10
11
12
# File 'lib/active_record/comments.rb', line 10

def prepend=prepend
  @@prepend = prepend
end

.with_comment_sql(sql) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/active_record/comments.rb', line 21

def with_comment_sql(sql)
  return sql unless comment = current_comment

  if @@prepend == true
    "/* #{comment} */ #{sql}"
  else
    "#{sql} /* #{comment} */"
  end
end