Class: Rummageable::Index

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

Instance Method Summary collapse

Constructor Details

#initialize(base_url, index_name, options = {}) ⇒ Index

Returns a new instance of Index.



11
12
13
14
15
16
17
# File 'lib/rummageable.rb', line 11

def initialize(base_url, index_name, options = {})
  @index_url = [base_url, index_name.sub(%r{^/}, '')].join('/')
  @logger = options[:logger] || NullLogger.instance
  @batch_size = options.fetch(:batch_size, 20)
  @retry_delay = options.fetch(:retry_delay, 2)
  @attempts = options.fetch(:attempts, 3)
end

Instance Method Details

#add(entry) ⇒ Object



19
20
21
22
23
# File 'lib/rummageable.rb', line 19

def add(entry)
  repeatedly do
    make_request(:post, documents_url, MultiJson.encode([entry]))
  end
end

#add_batch(entries) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/rummageable.rb', line 25

def add_batch(entries)
  entries.each_slice(@batch_size) do |batch|
    repeatedly do
      make_request(:post, documents_url, MultiJson.encode(batch))
    end
  end
end

#amend(link, changes) ⇒ Object



33
34
35
36
37
# File 'lib/rummageable.rb', line 33

def amend(link, changes)
  repeatedly do
    make_request(:post, documents_url(link: link), changes)
  end
end

#commitObject



52
53
54
55
56
# File 'lib/rummageable.rb', line 52

def commit
  repeatedly do
    make_request(:post, [@index_url, 'commit'].join('/'), MultiJson.encode({}))
  end
end

#delete(id, options = {}) ⇒ Object



39
40
41
42
43
44
# File 'lib/rummageable.rb', line 39

def delete(id, options = {})
  type = options[:type] || 'edition'
  repeatedly do
    make_request(:delete, documents_url(id: id, type: type))
  end
end

#delete_allObject



46
47
48
49
50
# File 'lib/rummageable.rb', line 46

def delete_all
  repeatedly do
    make_request(:delete, documents_url + '?delete_all=1')
  end
end