Module: Aliyun::Log::Record::Scoping::ClassMethods
- Defined in:
- lib/aliyun/log/record/scoping.rb
Instance Method Summary collapse
- #all ⇒ Object
- #current_scope ⇒ Object
- #current_scope=(scope) ⇒ Object
- #scope(name, body) ⇒ Object
- #unscoped ⇒ Object
Instance Method Details
#all ⇒ Object
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_scope ⇒ Object
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
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 |
#unscoped ⇒ Object
37 38 39 |
# File 'lib/aliyun/log/record/scoping.rb', line 37 def unscoped block_given? ? relation.scoping { yield } : relation end |