Class: GOM::Storage::ElasticSearch::CouchDB::River

Inherits:
Object
  • Object
show all
Defined in:
lib/gom/storage/elastic_search/couchdb/river.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ River

Returns a new instance of River.



5
6
7
8
# File 'lib/gom/storage/elastic_search/couchdb/river.rb', line 5

def initialize(options)
  @couch_db = options[:couch_db]
  @elastic_search = options[:elastic_search]
end

Instance Method Details

#createObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/gom/storage/elastic_search/couchdb/river.rb', line 10

def create
  Transport::JSON.request :put, "#{elastic_search_base_url}/_river/#{@elastic_search[:index_name]}/_meta",
                          :body => {
                            :type => "couchdb",
                            :couchdb => {
                              :host => @couch_db[:host],
                              :port => @couch_db[:port],
                              :db => @couch_db[:database],
                              :user => @couch_db[:username],
                              :password => @couch_db[:password]
                            },
                            :index => {
                              :index => @elastic_search[:index_name],
                              :type => @elastic_search[:index_name],
                              :bulk_size => "100",
                              :bulk_timeout => "10ms"
                            }
                          },
                          :expected_status_code => [ 200, 201 ]
end

#create_if_missingObject



31
32
33
# File 'lib/gom/storage/elastic_search/couchdb/river.rb', line 31

def create_if_missing
  create unless exists?
end

#deleteObject



35
36
37
# File 'lib/gom/storage/elastic_search/couchdb/river.rb', line 35

def delete
  Transport::JSON.request :delete, "#{elastic_search_base_url}/_river/#{@elastic_search[:index_name]}", :expected_status_code => 200
end

#delete_if_existsObject



39
40
41
# File 'lib/gom/storage/elastic_search/couchdb/river.rb', line 39

def delete_if_exists
  delete if exists?
end

#exists?Boolean

Returns:

  • (Boolean)


43
44
45
46
47
48
# File 'lib/gom/storage/elastic_search/couchdb/river.rb', line 43

def exists?
  Transport::JSON.request :get, "#{elastic_search_base_url}/_river/#{@elastic_search[:index_name]}/_meta", :expected_status_code => 200
  true
rescue Transport::UnexpectedStatusCodeError
  false
end