Class: RelaxDB::ViewUploader
- Inherits:
-
Object
- Object
- RelaxDB::ViewUploader
- Defined in:
- lib/relaxdb/view_uploader.rb
Class Method Summary collapse
- .extract(lines) ⇒ Object
-
.upload(filename) ⇒ Object
Methods must start and finish on different lines The function declaration must start at the beginning of a line As ‘-’ is used as a delimiter, the view name may not contain ‘-’ Exepcted function declaration form is function funcname-functype(doc) { For example function Users_followers-map(doc) {.
Class Method Details
.extract(lines) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/relaxdb/view_uploader.rb', line 24 def extract(lines) # Index of function declaration matches m = [] 0.upto(lines.size-1) do |p| line = lines[p] m << p if line =~ /^function[^\{]+\{/ end # Add one beyond the last line number as the final terminator m << lines.size 0.upto(m.size-2) do |i| declr = lines[m[i]] declr =~ /(\w)+-(\w)+/ declr.sub!($&, '') view_name, type = $&.split('-') func = lines[m[i]...m[i+1]].join yield view_name, type, func end end |
.upload(filename) ⇒ Object
Methods must start and finish on different lines The function declaration must start at the beginning of a line As ‘-’ is used as a delimiter, the view name may not contain ‘-’ Exepcted function declaration form is
function funcname-functype(doc) {
For example
function Users_followers-map(doc) {
15 16 17 18 19 20 21 22 |
# File 'lib/relaxdb/view_uploader.rb', line 15 def upload(filename) lines = File.readlines(filename) dd = RelaxDB::DesignDocument.get(RelaxDB.dd) extract(lines) do |vn, t, f| dd.add_view(vn, t, f) end dd.save end |