Class: Tempest::REPL::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/tempest/repl/registry.rb

Overview

Holds two IdVar rings (post + link) plus side tables that resolve a var string back to the original Post / URL. Lifetime is the current REPL session; nothing is persisted.

Instance Method Summary collapse

Constructor Details

#initializeRegistry

Returns a new instance of Registry.



9
10
11
12
13
14
# File 'lib/tempest/repl/registry.rb', line 9

def initialize
  @post_ids = Tempest::IdVar.new(range: "AA".."ZZ")
  @link_ids = Tempest::IdVar.new(range: "LA".."LZ")
  @posts = {}
  @urls = {}
end

Instance Method Details

#assign_post(post) ⇒ Object



16
17
18
19
20
# File 'lib/tempest/repl/registry.rb', line 16

def assign_post(post)
  var = @post_ids.generate(post_key(post))
  @posts[var] = post
  var
end

#assign_url(url) ⇒ Object



22
23
24
25
26
# File 'lib/tempest/repl/registry.rb', line 22

def assign_url(url)
  var = @link_ids.generate(url)
  @urls[var] = url
  var
end

#find_post(var) ⇒ Object



28
29
30
# File 'lib/tempest/repl/registry.rb', line 28

def find_post(var)
  @posts[var]
end

#find_url(var) ⇒ Object



32
33
34
# File 'lib/tempest/repl/registry.rb', line 32

def find_url(var)
  @urls[var]
end

#var_for_uri(uri) ⇒ Object

Reverse lookup: returns the var currently mapped to the given post URI, or nil if the URI has never been assigned or its slot has been recycled to a different post.



39
40
41
42
43
44
# File 'lib/tempest/repl/registry.rb', line 39

def var_for_uri(uri)
  @posts.each do |var, post|
    return var if post_key(post) == uri
  end
  nil
end