Class: Liminal::PredicateRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/liminal/predicate_registry.rb

Overview

Immutable registry of declarative dry predicate handlers.

Defined Under Namespace

Classes: Entry, UnsupportedValue

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entries = {}) ⇒ PredicateRegistry

Returns a new instance of PredicateRegistry.



190
191
192
193
# File 'lib/liminal/predicate_registry.rb', line 190

def initialize(entries = {})
  @entries = entries.freeze
  freeze
end

Class Method Details

.defaultPredicateRegistry

Return the immutable registry containing all built-in predicates.

Returns:



26
27
28
# File 'lib/liminal/predicate_registry.rb', line 26

def default
  @default ||= build_default.freeze
end

Instance Method Details

#entry(name) ⇒ Entry?

Look up a predicate entry. Intended for compiler adapters.

Parameters:

  • name (String, Symbol)

Returns:



213
214
215
# File 'lib/liminal/predicate_registry.rb', line 213

def entry(name)
  @entries[name.to_sym]
end

#with(name, replace: false) {|arguments, context| ... } ⇒ PredicateRegistry

Return a new registry containing name without mutating this registry.

Parameters:

  • name (String, Symbol)

    dry predicate name

  • replace (Boolean) (defaults to: false)

    explicitly replace an existing registration

Yield Parameters:

  • arguments (Array)

    semantic arguments without input placeholders

  • context (PredicateContext)

    canonical path and active dialect

Yield Returns:

  • (Hash)

    OpenAPI Schema Object fragment

Returns:

Raises:

  • (ArgumentError)


203
204
205
206
207
# File 'lib/liminal/predicate_registry.rb', line 203

def with(name, replace: false, &handler)
  raise ArgumentError, "a predicate handler block is required" unless handler

  add(name, handler, replace: replace, internal: false)
end