class RailsToolViews::Registry
Stores explicit component definitions and filters discoverable catalogs.
Public Class Methods
Source
# File lib/rails_tool_views/core.rb, line 222 def initialize @components = {} @mutex = Mutex.new end
Creates an empty, process-local registry.
Public Instance Methods
# File lib/rails_tool_views/core.rb, line 240 def catalog(keys:, scope:, exposure: :agent) raise Error.new("INVALID_SCOPE", status: 403) unless scope.is_a?(Scope) raise Error.new("CATALOG_TOO_LARGE") unless keys.is_a?(Array) && keys.length.between?(1, RailsToolViews.configuration.max_catalog_components) && keys.map(&:to_s).uniq.length == keys.length keys.map { |key| fetch(key) }.select do |component| component.expose_to.include?(exposure) && component.policy&.call(Access.new(actor: scope.actor, tenant: scope.tenant, operation: :discover, props: {}, context_ref: nil)) == true end.freeze end
Returns explicitly exposed components allowed by discovery policy for scope.
Source
# File lib/rails_tool_views/core.rb, line 236 def fetch(key) @components.fetch(key.to_s) { raise Error.new("UNKNOWN_COMPONENT", status: 404) } end
Returns the named component, or raises UNKNOWN_COMPONENT.
Source
# File lib/rails_tool_views/core.rb, line 227 def register(key, **options) component = Component.new(key, **options) @mutex.synchronize do raise Error.new("DUPLICATE_COMPONENT") if @components.key?(component.key) @components[component.key] = component end component end
Registers a component; duplicate keys raise DUPLICATE_COMPONENT.