lib/rid/design_document.rb in rid-0.3.0 vs lib/rid/design_document.rb in rid-0.3.1

- old
+ new

@@ -1,5 +1,6 @@ +require 'rid/core_ext/hash' require 'rid/attachments' require 'rid/makros' require 'uri' @@ -47,11 +48,11 @@ key = filename.dup # strip extname from javascript files key.sub!(/\.js$/, '') if filename =~ /#{JAVASCRIPT_FILES.join('|')}/ - set_hash_at key, block.call(filename) + hash.update_at key, block.call(filename) end map_attachments! inject_makros! end @@ -69,24 +70,20 @@ # # The key "_attachments" has a special meaning: # the value holds base64 encoded data as well as other metadata. # This data will gets decoded and used as value for the key. # - def write(directory = nil, doc = nil, &block) + def write(&block) reduce_attachments! reject_makros! - doc ||= hash - doc.each do |key, value| - filename = directory ? File.join(directory, key) : key.dup - if value.is_a?(Hash) - write(filename, value, &block) - else - # append extname to javascript files - filename << '.js' if filename =~ /#{JAVASCRIPT_FILES.join('|')}/ - block.call(filename, value) - end + hash.flatten.each do |key, value| + filename = key.dup + # append extname to javascript files + filename << '.js' if filename =~ /#{JAVASCRIPT_FILES.join('|')}/ + + block.call(filename, value) end end # Returns a JSON string representation of the documents hash # @@ -135,38 +132,11 @@ # def url(options = {}) base_url + build_options_string(options) end - private - def hash_at(path) - current_hash = hash - - parts = path.split('/') - key = parts.pop - - parts.each do |part| - current_hash[part] ||= {} - current_hash = current_hash[part] - end - - current_hash[key] - end - - def set_hash_at(path, value) - current_hash = hash - - parts = path.split('/') - key = parts.pop - - parts.each do |part| - current_hash[part] ||= {} - current_hash = current_hash[part] - end - - current_hash[key] = value - end + private def build_options_string(options) return '' if options.empty? options_array = [] options.each do |key, value|