Class: LcpRuby::Pages::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/lcp_ruby/pages/registry.rb

Class Method Summary collapse

Class Method Details

.all_definitionsArray<Metadata::PageDefinition>

Returns all active DB page definitions (parsed).

Returns:



22
23
24
25
26
27
28
# File 'lib/lcp_ruby/pages/registry.rb', line 22

def all_definitions
  return [] unless available?

  monitor.synchronize do
    load_all_definitions
  end
end

.available?Boolean

Whether the page_config table is ready to query.

Returns:

  • (Boolean)


51
52
53
# File 'lib/lcp_ruby/pages/registry.rb', line 51

def available?
  @available == true
end

.clear!Object

Full reset - called from LcpRuby.reset!



43
44
45
46
47
48
# File 'lib/lcp_ruby/pages/registry.rb', line 43

def clear!
  monitor.synchronize do
    @available = false
    @cache = {}
  end
end

.for_name(page_name) ⇒ Metadata::PageDefinition?

Returns cached PageDefinition for a given page name, or nil.

Parameters:

  • page_name (String)

    the page name to query

Returns:



10
11
12
13
14
15
16
17
18
# File 'lib/lcp_ruby/pages/registry.rb', line 10

def for_name(page_name)
  return nil unless available?

  key = page_name.to_s
  monitor.synchronize do
    @cache[key] = load_and_parse(key) unless @cache.key?(key)
    @cache[key]
  end
end

.mark_available!Object

Mark registry as available (called after contract validation passes).



56
57
58
59
60
# File 'lib/lcp_ruby/pages/registry.rb', line 56

def mark_available!
  @available = true
  @cache ||= {}
  @fields = LcpRuby.configuration.page_model_fields.transform_keys(&:to_s)
end

.reload!(page_name = nil) ⇒ Object

Clear cache for one page or all pages.

Parameters:

  • page_name (String, nil) (defaults to: nil)

    specific page to reload, or nil for all



32
33
34
35
36
37
38
39
40
# File 'lib/lcp_ruby/pages/registry.rb', line 32

def reload!(page_name = nil)
  monitor.synchronize do
    if page_name
      @cache.delete(page_name.to_s)
    else
      @cache = {}
    end
  end
end