Module: Sequel::Database::SQLComments
- Defined in:
- lib/sequel/extensions/sql_comments.rb
Defined Under Namespace
Modules: DatasetSQLComments
Instance Attribute Summary collapse
-
#comment_hashes ⇒ Object
readonly
A map of threads to comment hashes, used for correctly setting comments for all queries inside #with_comments blocks.
Class Method Summary collapse
Instance Method Summary collapse
-
#with_comments(comment_hash) ⇒ Object
Store the comment hash and use it to create comments inside the block.
Instance Attribute Details
#comment_hashes ⇒ Object (readonly)
A map of threads to comment hashes, used for correctly setting comments for all queries inside #with_comments blocks.
146 147 148 |
# File 'lib/sequel/extensions/sql_comments.rb', line 146 def comment_hashes @comment_hashes end |
Class Method Details
.extended(db) ⇒ Object
139 140 141 142 |
# File 'lib/sequel/extensions/sql_comments.rb', line 139 def self.extended(db) db.instance_variable_set(:@comment_hashes, {}) db.extend_datasets DatasetSQLComments end |
Instance Method Details
#with_comments(comment_hash) ⇒ Object
Store the comment hash and use it to create comments inside the block
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/sequel/extensions/sql_comments.rb', line 149 def with_comments(comment_hash) hashes = @comment_hashes t = Sequel.current new_hash = if hash = Sequel.synchronize{hashes[t]} hash.merge(comment_hash) else comment_hash.dup end yield Sequel.synchronize{hashes[t] = new_hash} ensure if hash Sequel.synchronize{hashes[t] = hash} else t && Sequel.synchronize{hashes.delete(t)} end end |