Module: Aliyun::Log::Record::Scoping::ClassMethods

Defined in:
lib/aliyun/log/record/scoping.rb

Instance Method Summary collapse

Instance Method Details

#allObject



41
42
43
44
45
# File 'lib/aliyun/log/record/scoping.rb', line 41

def all
  scope = current_scope
  scope ||= relation.from(0).to(Time.now.to_i)
  scope
end

#current_scopeObject



19
20
21
# File 'lib/aliyun/log/record/scoping.rb', line 19

def current_scope
  ScopeRegistry.value_for(:current_scope, self)
end

#current_scope=(scope) ⇒ Object



23
24
25
# File 'lib/aliyun/log/record/scoping.rb', line 23

def current_scope=(scope)
  ScopeRegistry.set_value_for(:current_scope, self, scope)
end

#scope(name, body) ⇒ Object

Raises:



27
28
29
30
31
32
33
34
35
# File 'lib/aliyun/log/record/scoping.rb', line 27

def scope(name, body)
  raise ArgumentError, 'The scope body needs to be callable.' unless body.respond_to?(:call)

  singleton_class.send(:define_method, name) do |*args|
    scope = all
    scope = scope.scoping { body.call(*args) }
    scope
  end
end

#unscopedObject



37
38
39
# File 'lib/aliyun/log/record/scoping.rb', line 37

def unscoped
  block_given? ? relation.scoping { yield } : relation
end