Class: Autoselect::Hook

Inherits:
Object
  • Object
show all
Defined in:
lib/autoselect/hook.rb

Overview

lib/autoselect/hook.rb

Base class for multi-step levels that chain autoselects across models. The canonical example is OTU's catalogue_of_life level, which hooks into TaxonName's catalogue_of_life level to create a TaxonName first, then uses the resulting taxon_name_id to create the OTU.

Hook execution is internal (Ruby, not HTTP). The hook calls the sub-autoselect level directly, collects the yielded attributes, and passes them back to the parent level's record creation logic.

Instance Method Summary collapse

Instance Method Details

#call(term:, project_id: nil, user_id: nil, **kwargs) ⇒ Array<Hash>

Execute the hook.

Parameters:

  • term (String)
  • project_id (Integer, nil) (defaults to: nil)
  • user_id (Integer, nil) (defaults to: nil)
  • kwargs (Hash)

Returns:

  • (Array<Hash>)

    items with extension: { mode: 'hook_confirmation', ... }

Raises:

  • (NotImplementedError)


35
36
37
# File 'lib/autoselect/hook.rb', line 35

def call(term:, project_id: nil, user_id: nil, **kwargs)
  raise NotImplementedError, "#{self.class} must implement #call"
end

#hooked_autoselect_classClass

Returns the autoselect class to delegate to for the sub-request.

Returns:

  • (Class)

    the autoselect class to delegate to for the sub-request

Raises:

  • (NotImplementedError)


20
21
22
# File 'lib/autoselect/hook.rb', line 20

def hooked_autoselect_class
  raise NotImplementedError, "#{self.class} must implement #hooked_autoselect_class"
end

#hooked_levelSymbol

Returns the level key on the hooked autoselect to invoke.

Returns:

  • (Symbol)

    the level key on the hooked autoselect to invoke

Raises:

  • (NotImplementedError)


25
26
27
# File 'lib/autoselect/hook.rb', line 25

def hooked_level
  raise NotImplementedError, "#{self.class} must implement #hooked_level"
end

#yieldsSymbol

Returns the attribute this hook yields, e.g. :taxon_name_id.

Returns:

  • (Symbol)

    the attribute this hook yields, e.g. :taxon_name_id

Raises:

  • (NotImplementedError)


15
16
17
# File 'lib/autoselect/hook.rb', line 15

def yields
  raise NotImplementedError, "#{self.class} must implement #yields"
end