Module: CouchDocs
- Defined in:
- lib/couch_docs.rb,
lib/couch_docs/store.rb,
lib/couch_docs/command_line.rb,
lib/couch_docs/design_directory.rb,
lib/couch_docs/document_directory.rb
Defined Under Namespace
Classes: CommandLine, DesignDirectory, DocumentDirectory, Store
Constant Summary collapse
- VERSION =
:stopdoc:
'1.2.0'
- LIBPATH =
::File.(::File.dirname(__FILE__)) + ::File::SEPARATOR
- PATH =
::File.dirname(LIBPATH) + ::File::SEPARATOR
Class Method Summary collapse
-
.destructive_database_create(db_uri) ⇒ Object
Create or recreate the database located at
db_uri
. -
.dump(db_uri, dir, only = nil) ⇒ Object
Dump all documents located at
db_uri
into the directorydir
. -
.libpath(*args) ⇒ Object
Returns the library path for the module.
-
.path(*args) ⇒ Object
Returns the lpath for the module.
-
.put_design_dir(db_uri, dir) ⇒ Object
Upload design documents from
dir
to the CouchDB database located atdb_uri
. -
.put_dir(db_uri, dir) ⇒ Object
For a CouchDB database described by
db_uri
and a directory,dir
containing design documents, creates design documents in the CouchDB database. -
.put_document_dir(db_uri, dir) ⇒ Object
Upload documents from
dir
to the CouchDB database located atdb_uri
. -
.put_file(db_uri, file_path) ⇒ Object
Upload a document located at
file_path
to the CouchDB database located atdb_uri
. -
.require_all_libs_relative_to(fname, dir = nil) ⇒ Object
Utility method used to require all files ending in .rb that lie in the directory below this file that has the same name as the filename passed in.
-
.upload_dir(db_uri, dir) ⇒ Object
Alias for
put_dir
. -
.version ⇒ Object
Returns the version string for the library.
Class Method Details
.destructive_database_create(db_uri) ⇒ Object
Create or recreate the database located at db_uri
80 81 82 |
# File 'lib/couch_docs.rb', line 80 def self.destructive_database_create(db_uri) Store.put!(db_uri, "") end |
.dump(db_uri, dir, only = nil) ⇒ Object
Dump all documents located at db_uri
into the directory dir
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/couch_docs.rb', line 63 def self.dump(db_uri, dir, only=nil) null_dir = OpenStruct.new(:store_document => nil) doc_dir = (only == :design) ? null_dir : DocumentDirectory.new(dir) design_dir = (only == :doc) ? null_dir : DesignDirectory.new(dir) store = Store.new(db_uri, :only => only) store.map.each do |doc| doc.delete('_rev') (doc['_id'] =~ /^_design/ ? design_dir : doc_dir). store_document(doc) end end |
.libpath(*args) ⇒ Object
Returns the library path for the module. If any arguments are given, they will be joined to the end of the libray path using File.join
.
88 89 90 |
# File 'lib/couch_docs.rb', line 88 def self.libpath( *args ) args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten) end |
.path(*args) ⇒ Object
Returns the lpath for the module. If any arguments are given, they will be joined to the end of the path using File.join
.
96 97 98 |
# File 'lib/couch_docs.rb', line 96 def self.path( *args ) args.empty? ? PATH : ::File.join(PATH, args.flatten) end |
.put_design_dir(db_uri, dir) ⇒ Object
Upload design documents from dir
to the CouchDB database located at db_uri
34 35 36 37 38 |
# File 'lib/couch_docs.rb', line 34 def self.put_design_dir(db_uri, dir) store = Store.new(db_uri) dir = DesignDirectory.new(dir) store.put_design_documents(dir.to_hash) end |
.put_dir(db_uri, dir) ⇒ Object
For a CouchDB database described by db_uri
and a directory, dir
containing design documents, creates design documents in the CouchDB database
21 22 23 24 |
# File 'lib/couch_docs.rb', line 21 def self.put_dir(db_uri, dir) self.put_design_dir(db_uri, "#{dir}/_design") self.put_document_dir(db_uri, dir) end |
.put_document_dir(db_uri, dir) ⇒ Object
Upload documents from dir
to the CouchDB database located at db_uri
43 44 45 46 47 48 |
# File 'lib/couch_docs.rb', line 43 def self.put_document_dir(db_uri, dir) dir = DocumentDirectory.new(dir) dir.each_document do |name, contents| Store.put!("#{db_uri}/#{name}", contents) end end |
.put_file(db_uri, file_path) ⇒ Object
Upload a document located at file_path
to the CouchDB database located at db_uri
54 55 56 57 58 |
# File 'lib/couch_docs.rb', line 54 def self.put_file(db_uri, file_path) contents = JSON.parse(File.read(file_path)) name = File.basename(file_path, ".json") Store.put!("#{db_uri}/#{name}", contents) end |
.require_all_libs_relative_to(fname, dir = nil) ⇒ Object
Utility method used to require all files ending in .rb that lie in the directory below this file that has the same name as the filename passed in. Optionally, a specific directory name can be passed in such that the filename does not have to be equivalent to the directory.
105 106 107 108 109 110 111 |
# File 'lib/couch_docs.rb', line 105 def self.require_all_libs_relative_to( fname, dir = nil ) dir ||= ::File.basename(fname, '.*') search_me = ::File.( ::File.join(::File.dirname(fname), dir, '**', '*.rb')) Dir.glob(search_me).sort.each {|rb| require rb} end |
.upload_dir(db_uri, dir) ⇒ Object
Alias for put_dir
27 28 29 |
# File 'lib/couch_docs.rb', line 27 def self.upload_dir(db_uri, dir) self.put_dir(db_uri, dir) end |
.version ⇒ Object
Returns the version string for the library.
13 14 15 |
# File 'lib/couch_docs.rb', line 13 def self.version VERSION end |