Class: LcpRuby::CustomFields::Registry

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

Class Method Summary collapse

Class Method Details

.available?Boolean

Whether the custom_field_definitions table is ready to query.

Returns:

  • (Boolean)


41
42
43
# File 'lib/lcp_ruby/custom_fields/registry.rb', line 41

def available?
  @available == true
end

.clear!Object

Full reset — called from LcpRuby.reset!



33
34
35
36
37
38
# File 'lib/lcp_ruby/custom_fields/registry.rb', line 33

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

.for_model(model_name) ⇒ Array

Returns custom field definitions for a given model name. Results are cached per model_name.

Parameters:

  • model_name (String)

    the model name to query

Returns:

  • (Array)

    array of definition records, ordered by position



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

def for_model(model_name)
  return [] unless available?

  key = model_name.to_s
  monitor.synchronize do
    @cache[key] ||= load_definitions(key)
  end
end

.mark_available!Object

Mark registry as available (called after building the built-in model).



46
47
48
49
# File 'lib/lcp_ruby/custom_fields/registry.rb', line 46

def mark_available!
  @available = true
  @cache ||= {}
end

.reload!(model_name = nil) ⇒ Object

Clear cache for one model or all models.

Parameters:

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

    specific model to reload, or nil for all



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

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