Class: Goddess::CustomQueryContainer

Inherits:
Valkyrie::Persistence::CustomQueryContainer
  • Object
show all
Includes:
Query::MethodMissingMachinations
Defined in:
lib/goddess/custom_query_container.rb

Class Attributes collapse

Instance Method Summary collapse

Methods included from Query::MethodMissingMachinations

#model_class_for, #setup_model, #total_results

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, **opts, &block) ⇒ Object (private)



56
57
58
59
60
61
62
63
64
65
# File 'lib/goddess/custom_query_container.rb', line 56

def method_missing(method_name, *args, **opts, &block)
  return super unless services.detect { |service| service.respond_to?(method_name) }

  strategy = known_custom_queries_and_their_strategies.fetch(method_name, fallback_query_strategy)
  dispatch_method_name = "query_strategy_for_#{strategy}"

  # We want to check for private methods
  return super unless respond_to?(dispatch_method_name, true)
  send(dispatch_method_name, method_name, *args, **opts, &block)
end

Instance Attribute Details

#:known_custom_queries_and_their_strategies(: known_custom_queries_and_their_strategies) ⇒ Hash<Symbol,Symbol>

TODO:

Audit the current custom queries and assign strategies.

Valid strategies are :find_multiple

Returns:

  • (Hash<Symbol,Symbol>)

See Also:



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/goddess/custom_query_container.rb', line 13

class_attribute(:known_custom_queries_and_their_strategies,
default: {
  find_by_date_range: :find_multiple,
  find_child_collection_ids: :find_multiple,
  find_child_collections: :find_multiple,
  find_child_file_set_ids: :find_multiple,
  find_child_file_sets: :find_multiple,
  find_child_fileset_ids: :find_multiple,
  find_child_filesets: :find_multiple,
  find_child_work_ids: :find_multiple,
  find_child_works: :find_multiple,
  find_collections_by_type: :find_multiple,
  find_collections_for: :find_multiple,
  find_count_by: :count_multiple,
  find_extracted_text: :find_single,
  find_file_metadata_by: :find_single,
  find_file_metadata_by_alternate_identifier: :find_single,
  find_files: :find_multiple,
  find_ids_by_model: :find_multiple,
  find_many_by_alternate_ids: :find_multiple,
  find_many_file_metadata_by_ids: :find_multiple,
  find_many_file_metadata_by_use: :find_multiple,
  find_members_of: :find_multiple,
  find_models_by_access: :find_multiple,
  find_original_file: :find_single,
  find_parent_collection_ids: :find_multiple,
  find_parent_collections: :find_multiple,
  find_parent_work: :find_single_or_nil,
  find_parent_work_id: :find_single_or_nil,
  find_parents: :find_multiple,
  find_thumbnail: :find_single,
  find_access_control_for: :find_single
})

Instance Method Details

#servicesObject



50
51
52
# File 'lib/goddess/custom_query_container.rb', line 50

def services
  @services ||= query_service.services.map(&:custom_queries)
end