Class: LcpRuby::Roles::Registry

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

Class Method Summary collapse

Class Method Details

.all_role_namesArray<String>

Returns all active role names from the DB-backed role model. Results are cached until reload! is called.

Returns:

  • (Array<String>)

    sorted array of role name strings



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/lcp_ruby/roles/registry.rb', line 10

def all_role_names
  return [] unless available?

  result, operation = monitor.synchronize do
    if @cache
      [ @cache, :hit ]
    else
      @cache = load_role_names
      [ @cache, :miss ]
    end
  end
  ActiveSupport::Notifications.instrument("cache.lcp_ruby", cache: "roles", operation: operation.to_s)
  result
end

.available?Boolean

Whether the role model table is ready to query.

Returns:

  • (Boolean)


49
50
51
# File 'lib/lcp_ruby/roles/registry.rb', line 49

def available?
  @available == true
end

.clear!Object

Full reset — called from LcpRuby.reset!



41
42
43
44
45
46
# File 'lib/lcp_ruby/roles/registry.rb', line 41

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

.mark_available!Object

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



54
55
56
# File 'lib/lcp_ruby/roles/registry.rb', line 54

def mark_available!
  @available = true
end

.reload!Object

Clears the cached role names, forcing a reload on next access.



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

def reload!
  monitor.synchronize do
    @cache = nil
  end
  ActiveSupport::Notifications.instrument("cache.lcp_ruby", cache: "roles", operation: "invalidate")
end

.valid_role?(name) ⇒ Boolean

Checks whether a role name exists in the registry.

Parameters:

  • name (String)

    role name to check

Returns:

  • (Boolean)


28
29
30
# File 'lib/lcp_ruby/roles/registry.rb', line 28

def valid_role?(name)
  all_role_names.include?(name.to_s)
end