Module: DataMapper::Migrations::CouchAdapter

Defined in:
lib/couchdb_adapter/migrations.rb

Instance Method Summary collapse

Instance Method Details

#create_model_storage(repository, model) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/couchdb_adapter/migrations.rb', line 4

def create_model_storage(repository, model)
  uri = "/#{self.escaped_db_name}/_design/#{model.base_model.to_s}"
  view = Net::HTTP::Put.new(uri)
  view['content-type'] = "application/json"
  views = model.views.reject {|key, value| value.nil?}
  view.body = { :views => views }.to_json
  request do |http|
    http.request(view)
  end
end

#destroy_model_storage(repository, model) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/couchdb_adapter/migrations.rb', line 15

def destroy_model_storage(repository, model)
  uri = "/#{self.escaped_db_name}/_design/#{model.base_model.to_s}"
  response = http_get(uri)
  unless response['error']
    uri += "?rev=#{response["_rev"]}"
    http_delete(uri)
  end
end