Class: Ruby::Rego::Memoization::Store

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby/rego/memoization.rb

Overview

Stack-based memoization store for nested scopes.

Instance Method Summary collapse

Constructor Details

#initialize ⇒ Store

Returns a new instance of Store.



31
32
33
# File 'lib/ruby/rego/memoization.rb', line 31

def initialize
  @contexts = [Context.new]
end

Instance Method Details

#context ⇒ Context

Returns:



61
62
63
# File 'lib/ruby/rego/memoization.rb', line 61

def context
  @contexts.last
end

#reset ⇒ void

This method returns an undefined value.

Reset memoized data without mutation semantics.



46
47
48
# File 'lib/ruby/rego/memoization.rb', line 46

def reset
  reset!
end

#reset! ⇒ void

This method returns an undefined value.

Reset memoized data for a new evaluation.



38
39
40
41
# File 'lib/ruby/rego/memoization.rb', line 38

def reset!
  @contexts = [Context.new]
  nil
end

#with_context ⇒ Object

Run with a fresh memoization context.

Returns:

  • (Object)


53
54
55
56
57
58
# File 'lib/ruby/rego/memoization.rb', line 53

def with_context
  @contexts << Context.new
  yield
ensure
  @contexts.pop
end