module ApiClient::Mixins::Scoping

Attributes

default_scopes[RW]

Public Instance Methods

always(&block) click to toggle source

Default scoping

# File lib/api_client/mixins/scoping.rb, line 10
def always(&block)
  default_scopes.push(block) if block
end
scope(options = {}) click to toggle source

Scoping

# File lib/api_client/mixins/scoping.rb, line 19
def scope(options = {})
  scope_in_thread || Scope.new(self).params(options)
end
scope_in_thread() click to toggle source
# File lib/api_client/mixins/scoping.rb, line 39
def scope_in_thread
  if found = Thread.current[scope_thread_attribute_name]
    found.last
  end
end
scope_thread_attribute_name() click to toggle source
# File lib/api_client/mixins/scoping.rb, line 35
def scope_thread_attribute_name
  "#{self.name}_scope"
end
scoped(scope) { || ... } click to toggle source

Allow wrapping singleton methods in a scope Store the handler in a thread-local variable for thread safety

# File lib/api_client/mixins/scoping.rb, line 25
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