Class: CouchPopulator::CouchHelper

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

Class Method Summary collapse

Class Method Details

.couch_available?(couch_url) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
# File 'lib/couchpopulator/couch_helper.rb', line 12

def couch_available? (couch_url)
  # TODO this uri-thing is ugly :/
  tmp = URI.parse(couch_url)
  `curl --fail --request GET #{tmp.scheme}://#{tmp.host}:#{tmp.port} 2> /dev/null`
  return $?.exitstatus == 0
end

.create_db(url) ⇒ Object



24
25
26
# File 'lib/couchpopulator/couch_helper.rb', line 24

def create_db(url)
  !!(JSON.parse(`curl --silent --write-out %{http_code} --request PUT #{url}`))["ok"]
end

.database_exists?(db_url) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
# File 'lib/couchpopulator/couch_helper.rb', line 19

def database_exists? (db_url)
  `curl --fail --request GET #{db_url} 2> /dev/null`
  return $?.exitstatus == 0
end

.get_database_from_couchurl(url) ⇒ Object



8
9
10
# File 'lib/couchpopulator/couch_helper.rb', line 8

def get_database_from_couchurl(url)
  URI.parse(url).path
end

.get_full_couchurl(arg) ⇒ Object



4
5
6
# File 'lib/couchpopulator/couch_helper.rb', line 4

def get_full_couchurl(arg)
  arg.match(/^https?:\/\//) ? arg : URI.join('http://127.0.0.1:5984/', arg).to_s
end