Methods
Public Class
Public Instance
Classes and Modules
Public Class methods
# File lib/sequel/extensions/query_blocker.rb 65 def self.extended(db) 66 db.instance_exec do 67 @blocked_query_scopes ||= {} 68 end 69 end
Public Instance methods
Allow queries inside the block. Only useful if they are already blocked for the same scope. Useful for blocking queries generally, and only allowing them in specific places. Takes the same :scope option as block_queries
.
# File lib/sequel/extensions/query_blocker.rb 105 def allow_queries(opts=OPTS, &block) 106 _allow_or_block_queries(false, opts, &block) 107 end
Reject (raise an BlockedQuery
exception) if there is an attempt to execute a query/statement inside the block.
The :scope option indicates which queries are rejected inside the block:
:global |
This is the default, and rejects all queries. |
:thread |
Reject all queries in the current thread. |
:fiber |
Reject all queries in the current fiber. |
Thread |
Reject all queries in the given thread. |
Fiber |
Reject all queries in the given fiber. |
# File lib/sequel/extensions/query_blocker.rb 119 def block_queries(opts=OPTS, &block) 120 _allow_or_block_queries(true, opts, &block) 121 end
Whether queries are currently blocked.
# File lib/sequel/extensions/query_blocker.rb 93 def block_queries? 94 b = @blocked_query_scopes 95 b.fetch(Fiber.current) do 96 b.fetch(Thread.current) do 97 b.fetch(:global, false) 98 end 99 end 100 end
Check whether queries are blocked before executing them.
# File lib/sequel/extensions/query_blocker.rb 83 def log_connection_yield(sql, conn, args=nil) 84 # All database adapters should be calling this method around 85 # query execution (otherwise the queries would not get logged), 86 # ensuring the blocking is checked. Any database adapter issuing 87 # a query without calling this method is considered buggy. 88 check_blocked_queries! 89 super 90 end
If checking a connection for validity, and a BlockedQuery
exception is raised, treat it as a valid connection. You cannot check whether the connection is valid without issuing a query, and if queries are blocked, you need to assume it is valid or assume it is not. Since it most cases it will be valid, this assumes validity.
# File lib/sequel/extensions/query_blocker.rb 76 def valid_connection?(conn) 77 super 78 rescue BlockedQuery 79 true 80 end