Sha256: 9ae7af7a2f2ba268d677d2cc4131698e51a792bb43c1896f93d93d59fc70c9c3
Contents?: true
Size: 1006 Bytes
Versions: 47
Compression:
Stored size: 1006 Bytes
Contents
module ApiClient module Mixins module Scoping attr_accessor :default_scopes # Default scoping def always(&block) default_scopes.push(block) if block end def default_scopes @default_scopes || [] end # Scoping def scope(options = {}) scope_in_thread || Scope.new(self).params(options) end # Allow wrapping singleton methods in a scope # Store the handler in a thread-local variable for thread safety def scoped(scope) Thread.current[scope_thread_attribute_name] ||= [] Thread.current[scope_thread_attribute_name].push scope begin yield ensure Thread.current[scope_thread_attribute_name] = nil end end def scope_thread_attribute_name "#{self.name}_scope" end def scope_in_thread if found = Thread.current[scope_thread_attribute_name] found.last end end end end end
Version data entries
47 entries across 47 versions & 1 rubygems