Module: ActiveStash::Search::ClassMethods

Defined in:
lib/active_stash/search.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cipherstash_metricsObject



183
184
185
# File 'lib/active_stash/search.rb', line 183

def cipherstash_metrics
  @cipherstash_metrics ||= CipherStash::Client::Metrics::Null.new
end

#collection_nameObject

TODO: All of this can probably now get wrapped into the collection proxy

Name of the Stash collection Defaults to the name of the table



179
180
181
# File 'lib/active_stash/search.rb', line 179

def collection_name
  @collection_name || table_name
end

Instance Method Details

#collection(reload = false) ⇒ Object

Object representing the underlying CipherStash collection



170
171
172
173
# File 'lib/active_stash/search.rb', line 170

def collection(reload = false)
  return @collection if @collection && !reload
  @collection = CollectionProxy.new(self)
end

#is_stash_model?Boolean

TODO: Make this universal

Returns:

  • (Boolean)


137
138
139
# File 'lib/active_stash/search.rb', line 137

def is_stash_model?
  true
end

#query(*args, &block) ⇒ Object

Perform a query using the CipherStash collection indexes



151
152
153
# File 'lib/active_stash/search.rb', line 151

def query(*args, &block)
  ::ActiveStash::Relation.new(current_scope || self).query(*args, &block)
end

#reindexObject

Reindex all records into CipherStash



156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/active_stash/search.rb', line 156

def reindex
  records = find_each.lazy.map do |r|
    if r.stash_id.nil?
      r.update_columns(stash_id: SecureRandom.uuid)
    end
    { id: r.stash_id, record: r.attributes }
  end

  collection.streaming_upsert(records)

  true
end

#stash_index(*args, &block) ⇒ Object



141
142
143
144
145
146
147
148
# File 'lib/active_stash/search.rb', line 141

def stash_index(*args, &block)
  return if @finalized_config
  dsl = IndexDSL.new(self)
  dsl.instance_eval(&block)
  @finalized_config = dsl.finalize!
  @finalized_config.register_callbacks
  @indexes = @finalized_config.indexes
end

#stash_indexesObject

:nodoc:



187
188
189
# File 'lib/active_stash/search.rb', line 187

def stash_indexes # :nodoc:
  @indexes
end