Class: DeployCouch::Repository
- Inherits:
-
Object
- Object
- DeployCouch::Repository
- Defined in:
- lib/deploy_couch/repository.rb
Constant Summary collapse
- PAGE_SIZE =
10
Instance Method Summary collapse
- #create_schema(json) ⇒ Object
- #delete_document(json) ⇒ Object
- #get_documents(map_function) ⇒ Object
- #get_documents_to_modify(map_function) ⇒ Object
- #get_schema ⇒ Object
-
#initialize(couch_config) ⇒ Repository
constructor
A new instance of Repository.
- #post_document(json) ⇒ Object
- #put_document(json) ⇒ Object
Constructor Details
#initialize(couch_config) ⇒ Repository
Returns a new instance of Repository.
6 7 8 |
# File 'lib/deploy_couch/repository.rb', line 6 def initialize(couch_config) @config = couch_config end |
Instance Method Details
#create_schema(json) ⇒ Object
65 66 67 68 |
# File 'lib/deploy_couch/repository.rb', line 65 def create_schema(json) server = Server.new(@config.hostname,@config.port) res = server.post("/#{@config.database}/",json.to_json) end |
#delete_document(json) ⇒ Object
54 55 56 57 |
# File 'lib/deploy_couch/repository.rb', line 54 def delete_document(json) server = Server.new(@config.hostname,@config.port) server.delete("/#{@config.database}/#{json['_id']}?rev=#{json['_rev']}") end |
#get_documents(map_function) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/deploy_couch/repository.rb', line 10 def get_documents(map_function) server = Server.new(@config.hostname,@config.port) no_of_records = 0 page_no = 0 finish_loading_all = false while(!finish_loading_all) response = server.post("/#{@config.database}/_temp_view?limit=#{PAGE_SIZE}&skip=#{PAGE_SIZE*page_no}",map_function) json = JSON.parse(response.body) json["rows"].each do |row| yield row end page_no += 1 no_of_records += json["rows"].count finish_loading_all = true if no_of_records >= json["total_rows"] end end |
#get_documents_to_modify(map_function) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/deploy_couch/repository.rb', line 28 def get_documents_to_modify(map_function) server = Server.new(@config.hostname,@config.port) finish_loading_all = false while(!finish_loading_all) response = server.post("/#{@config.database}/_temp_view?limit=#{PAGE_SIZE}",map_function) json = JSON.parse(response.body) json["rows"].each do |row| yield row end finish_loading_all = json["total_rows"] <= 10 end end |
#get_schema ⇒ Object
59 60 61 62 63 |
# File 'lib/deploy_couch/repository.rb', line 59 def get_schema server = Server.new(@config.hostname,@config.port) res = server.get("/#{@config.database}/schema__schema_document_key__",{:suppress_exceptions=>true}) json = JSON.parse(res.body) if res.kind_of?(Net::HTTPSuccess) end |