Module: Familia::Features::Relationships::Indexing::ModelClassMethods
- Defined in:
- lib/familia/features/relationships/indexing.rb
Overview
Indexing::ModelClassMethods
Instance Method Summary collapse
-
#ensure_index_field(scope_class, index_name, field_type) ⇒ Object
Ensure proper DataType field is declared for index Similar to ensure_collection_field in participation system.
-
#indexing_relationships ⇒ Object
Get all indexing relationships for this class.
-
#multi_index(field, index_name, within: :class, query: true) ⇒ Object
Define an indexed_by relationship for fast lookups.
-
#unique_index(field, index_name, within: nil, query: true) ⇒ Object
Define a unique index lookup (1:1 mapping).
Instance Method Details
#ensure_index_field(scope_class, index_name, field_type) ⇒ Object
Ensure proper DataType field is declared for index Similar to ensure_collection_field in participation system
142 143 144 145 146 |
# File 'lib/familia/features/relationships/indexing.rb', line 142 def ensure_index_field(scope_class, index_name, field_type) return if scope_class.method_defined?(index_name) || scope_class.respond_to?(index_name) scope_class.send(field_type, index_name) end |
#indexing_relationships ⇒ Object
Get all indexing relationships for this class
136 137 138 |
# File 'lib/familia/features/relationships/indexing.rb', line 136 def indexing_relationships @indexing_relationships ||= [] end |
#multi_index(field, index_name, within: :class, query: true) ⇒ Object
Define an indexed_by relationship for fast lookups
Define a multi-value index (1:many mapping)
101 102 103 104 105 106 107 108 109 |
# File 'lib/familia/features/relationships/indexing.rb', line 101 def multi_index(field, index_name, within: :class, query: true) MultiIndexGenerators.setup( indexed_class: self, field: field, index_name: index_name, within: within, query: query, ) end |
#unique_index(field, index_name, within: nil, query: true) ⇒ Object
Define a unique index lookup (1:1 mapping)
125 126 127 128 129 130 131 132 133 |
# File 'lib/familia/features/relationships/indexing.rb', line 125 def unique_index(field, index_name, within: nil, query: true) UniqueIndexGenerators.setup( indexed_class: self, field: field, index_name: index_name, within: within, query: query, ) end |