Class: ElasticQueue::Base

Inherits:
Object
  • Object
show all
Includes:
Percolation, Persistence
Defined in:
lib/elastic_queue/base.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Percolation

#in_queue?, #register_as_percolator_query

Class Method Details

.countObject


76
77
78
# File 'lib/elastic_queue/base.rb', line 76

def self.count
  query.count
end

.default_scope(proc) ⇒ Object


44
45
46
# File 'lib/elastic_queue/base.rb', line 44

def self.default_scope(proc)
  @default_scope = proc
end

.eager_load(includes) ⇒ Object


36
37
38
# File 'lib/elastic_queue/base.rb', line 36

def self.eager_load(includes)
  @eager_loads = includes
end

.eager_loadsObject


40
41
42
# File 'lib/elastic_queue/base.rb', line 40

def self.eager_loads
  @eager_loads
end

.filter(options) ⇒ Object


72
73
74
# File 'lib/elastic_queue/base.rb', line 72

def self.filter(options)
  query.filter(options)
end

.index_nameObject


28
29
30
# File 'lib/elastic_queue/base.rb', line 28

def self.index_name
  @index_name ||= to_s.underscore
end

.index_name=(name) ⇒ Object


32
33
34
# File 'lib/elastic_queue/base.rb', line 32

def self.index_name=(name)
  @index_name = name
end

.model_classesObject


24
25
26
# File 'lib/elastic_queue/base.rb', line 24

def self.model_classes
  model_names.map { |s| s.to_s.camelize.constantize }
end

.model_namesObject


19
20
21
22
# File 'lib/elastic_queue/base.rb', line 19

def self.model_names
  fail NotImplementedError, "No models defined in #{self.class}" unless defined?(@models)
  @models
end

.models(*models) ⇒ Object


15
16
17
# File 'lib/elastic_queue/base.rb', line 15

def self.models(*models)
  @models = models
end

.queryObject


66
67
68
69
70
# File 'lib/elastic_queue/base.rb', line 66

def self.query
  Query.new(self).tap do |q|
    q.instance_exec(&@default_scope) if @default_scope
  end
end

.scope(name, body) ⇒ Object

we want to store the scope in our scopes hash for use in chaining scopes we also define it on the class to mimic AR scopes


59
60
61
# File 'lib/elastic_queue/base.rb', line 59

def self.scope(name, body)
  @scopes.merge(name => body)
end

.scopesObject


52
53
54
# File 'lib/elastic_queue/base.rb', line 52

def self.scopes
  @scopes ||= {}
end

.search_clientObject


11
12
13
# File 'lib/elastic_queue/base.rb', line 11

def self.search_client
  @search_client ||= Elasticsearch::Client.new hosts: ElasticQueue::OPTIONS[:elasticsearch_hosts]
end

Instance Method Details

#queryObject

instance methods


81
82
83
# File 'lib/elastic_queue/base.rb', line 81

def query
  @query ||= self.class.query
end