Class: Rummageable::Index
- Inherits:
-
Object
- Object
- Rummageable::Index
- Defined in:
- lib/rummageable.rb
Instance Method Summary collapse
- #add(entry) ⇒ Object
- #add_batch(entries) ⇒ Object
- #amend(link, changes) ⇒ Object
- #commit ⇒ Object
- #delete(id, options = {}) ⇒ Object
- #delete_all ⇒ Object
-
#initialize(base_url, index_name, options = {}) ⇒ Index
constructor
A new instance of Index.
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, = {}) @index_url = [base_url, index_name.sub(%r{^/}, '')].join('/') @logger = [:logger] || NullLogger.instance @batch_size = .fetch(:batch_size, 20) @retry_delay = .fetch(:retry_delay, 2) @attempts = .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 |
#commit ⇒ Object
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, = {}) type = [:type] || 'edition' repeatedly do make_request(:delete, documents_url(id: id, type: type)) end end |
#delete_all ⇒ Object
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 |