Class: Igniter::Store::Protocol::Handlers::AccessPathHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/igniter/store/protocol/handlers/access_path_handler.rb

Constant Summary collapse

REQUIRED =
%i[name store fields].freeze

Instance Method Summary collapse

Constructor Details

#initialize(store) ⇒ AccessPathHandler

Returns a new instance of AccessPathHandler.



10
# File 'lib/igniter/store/protocol/handlers/access_path_handler.rb', line 10

def initialize(store) = @store = store

Instance Method Details

#call(descriptor) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/igniter/store/protocol/handlers/access_path_handler.rb', line 12

def call(descriptor)
  missing = REQUIRED.select { |f| descriptor[f].nil? }
  return Receipt.rejection("Missing required fields: #{missing.join(", ")}", kind: :access_path) if missing.any?

  name       = descriptor[:name].to_sym
  store_name = descriptor[:store].to_sym
  unique     = descriptor.fetch(:unique, true)

  @store.register_path(
    AccessPath.new(
      store:     store_name,
      lookup:    :primary_key,
      scope:     name,
      filters:   {},
      cache_ttl: descriptor[:cache_ttl],
      consumers: []
    )
  )

  warnings = unique ? [] : ["unique: false — non-unique access paths are recorded but not enforced by the engine"]
  Receipt.accepted(kind: :access_path, name: name, warnings: warnings)
end