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:
'0.9.0'- LIBPATH =
::File.(::File.dirname(__FILE__)) + ::File::SEPARATOR
- PATH =
::File.dirname(LIBPATH) + ::File::SEPARATOR
Class Method Summary collapse
-
.dump(db_uri, dir) ⇒ Object
Dump all documents located at
db_uriinto 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
dirto the CouchDB database located atdb_uri. -
.put_dir(db_uri, dir) ⇒ Object
For a CouchDB database described by
db_uriand a directory,dircontaining design documents, creates design documents in the CouchDB database. -
.put_document_dir(db_uri, dir) ⇒ Object
Upload documents from
dirto 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
.dump(db_uri, dir) ⇒ Object
Dump all documents located at db_uri into the directory dir
52 53 54 55 56 57 58 59 |
# File 'lib/couch_docs.rb', line 52 def self.dump(db_uri, dir) store = Store.new(db_uri) dir = DocumentDirectory.new(dir) store. map. reject { |doc| doc['_id'] =~ /^_design/ }. each { |doc| dir.store_document(doc) } 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.
65 66 67 |
# File 'lib/couch_docs.rb', line 65 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.
73 74 75 |
# File 'lib/couch_docs.rb', line 73 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
32 33 34 35 36 |
# File 'lib/couch_docs.rb', line 32 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
19 20 21 22 |
# File 'lib/couch_docs.rb', line 19 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
41 42 43 44 45 46 47 |
# File 'lib/couch_docs.rb', line 41 def self.put_document_dir(db_uri, dir) store = Store.new(db_uri) dir = DocumentDirectory.new(dir) dir.each_document do |name, contents| Store.put!("#{db_uri}/#{name}", contents) end 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.
82 83 84 85 86 87 88 |
# File 'lib/couch_docs.rb', line 82 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
25 26 27 |
# File 'lib/couch_docs.rb', line 25 def self.upload_dir(db_uri, dir) self.put_dir(db_uri, dir) end |
.version ⇒ Object
Returns the version string for the library.
11 12 13 |
# File 'lib/couch_docs.rb', line 11 def self.version VERSION end |