Module: Familia::Features::Relationships::Indexing::ClassMethods
- Defined in:
- lib/familia/features/relationships/indexing.rb
Instance Method Summary collapse
-
#indexed_by(field, index_name, context:, finder: true) ⇒ Object
Define an indexed_by relationship for fast lookups.
-
#indexing_relationships ⇒ Object
Get all indexing relationships for this class.
Instance Method Details
#indexed_by(field, index_name, context:, finder: true) ⇒ Object
Define an indexed_by relationship for fast lookups
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/familia/features/relationships/indexing.rb', line 29 def indexed_by(field, index_name, context:, finder: true) context_class = context == :global ? :global : context context_class_name = if context_class == :global 'global' else (context_class.is_a?(Class) ? context_class.name : context_class.to_s.camelize) end # Store metadata for this indexing relationship indexing_relationships << { field: field, context_class: context_class, context_class_name: context_class_name, index_name: index_name, finder: finder } # Generate finder methods on the context class if finder && context_class != :global generate_context_finder_methods(context_class, field, index_name) elsif finder && context_class == :global generate_global_finder_methods(field, index_name) end # Generate instance methods for maintaining the index generate_indexing_instance_methods(context_class_name, field, index_name) end |
#indexing_relationships ⇒ Object
Get all indexing relationships for this class
58 59 60 |
# File 'lib/familia/features/relationships/indexing.rb', line 58 def indexing_relationships @indexing_relationships ||= [] end |