Module: Tanker::ClassMethods
- Defined in:
- lib/tanker.rb
Overview
these are the class methods added when Tanker is included They’re kept to a minimum to prevent namespace pollution
Instance Attribute Summary collapse
-
#tanker_config ⇒ Object
Returns the value of attribute tanker_config.
Instance Method Summary collapse
- #search_tank(query, options = {}) ⇒ Object
- #tanker_index ⇒ Object
- #tanker_reindex(options = {}) ⇒ Object
- #tankit(name, &block) ⇒ Object
Instance Attribute Details
#tanker_config ⇒ Object
Returns the value of attribute tanker_config.
155 156 157 |
# File 'lib/tanker.rb', line 155 def tanker_config @tanker_config end |
Instance Method Details
#search_tank(query, options = {}) ⇒ Object
165 166 167 |
# File 'lib/tanker.rb', line 165 def search_tank(query, = {}) Tanker.search([self], query, ) end |
#tanker_index ⇒ Object
169 170 171 |
# File 'lib/tanker.rb', line 169 def tanker_index tanker_config.index end |
#tanker_reindex(options = {}) ⇒ Object
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/tanker.rb', line 173 def tanker_reindex( = {}) puts "Indexing #{self} model" batches = [] [:batch_size] ||= 200 records = [:scope] ? send([:scope]).all : all record_size = records.size records.each_with_index do |model_instance, idx| batch_num = idx / [:batch_size] (batches[batch_num] ||= []) << model_instance end timer = Time.now batches.each_with_index do |batch, idx| Tanker.batch_update(batch) puts "Indexed #{batch.size} records #{(idx * [:batch_size]) + batch.size}/#{record_size}" end puts "Indexed #{record_size} #{self} records in #{Time.now - timer} seconds" end |
#tankit(name, &block) ⇒ Object
157 158 159 160 161 162 163 |
# File 'lib/tanker.rb', line 157 def tankit(name, &block) if block_given? self.tanker_config = ModelConfig.new(name, block) else raise(NoBlockGiven, 'Please provide a block') end end |