Class: Deviant::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/deviant/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Client

Returns a new instance of Client.



3
4
5
# File 'lib/deviant/client.rb', line 3

def initialize(options)
  @options = options
end

Instance Method Details

#fetch(query, tags = []) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/deviant/client.rb', line 14

def fetch(query, tags = [])
  query = build_query(query)
  search do
    query { string query }
    filter :terms, tags: tags if tags.size > 0
    sort { by :date, 'desc' }
  end
end

#index(&block) ⇒ Object



23
24
25
# File 'lib/deviant/client.rb', line 23

def index(&block)
  Tire.index @options[:name], &block
end

#search(&block) ⇒ Object



27
28
29
# File 'lib/deviant/client.rb', line 27

def search(&block)
  Tire.search @options[:name], &block
end

#store(name, message, data = {}) ⇒ Object



7
8
9
10
11
12
# File 'lib/deviant/client.rb', line 7

def store(name, message, data = {})
  entry = {name: name, message: message, date: Time.now}.merge(data)
  return store_async(entry) if @options[:sidekiq][:enabled]

  index { store(entry) }
end