Sha256: 5d802d65863fe7f2396cb091d3e9a4b8e0f842d0fcf1b1d162eed868a34f059e

Contents?: true

Size: 775 Bytes

Versions: 1

Compression:

Stored size: 775 Bytes

Contents

class CouchConsole
  def init
    puts "** initialize update"
    @commands << {
      :regexp => /^\s*update\s*([^\s]*)\s*([^\s=]*)\s*=\s*([^\s]*)\s*$/,
      :method => :update,
      :documentation => [["update id field = value", "Update (or add) the field with value in document id"]]
    }
  end
  
  def update( id, field, value )
    document = @db.get( id )
    if document.class == CouchRest::Document
      document[field] = value
      begin
        document.save
        puts "*** Update `#{id}' : #{field} = #{value}"
      rescue => e
        puts "!!! Update `#{id}' faild with message #{e.message}"
      end
    else
      puts "!!! Can't update `#{id}'"
    end
  rescue RestClient::ResourceNotFound
    puts "!!! Document `#{id}' does not exist."
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
couchc-0.1.0 lib/commands/update.rb