Class: Redis::DiffMatchPatch

Inherits:
Object
  • Object
show all
Defined in:
lib/redis-diff_match_patch.rb

Constant Summary collapse

VERSION =
"1.1.1"
RESOURCE_DIR =
File.dirname(__FILE__)
DIFF_SCRIPT =
File.read File.join(RESOURCE_DIR, "diff_match_patch-diff.lua")
DIFF_SHA1 =
Digest::SHA1.hexdigest DIFF_SCRIPT
PATCH_SCRIPT =
File.read File.join(RESOURCE_DIR, "diff_match_patch-patch.lua")
PATCH_SHA1 =
Digest::SHA1.hexdigest PATCH_SCRIPT
MERGE_SCRIPT =
File.read File.join(RESOURCE_DIR, "diff_match_patch-merge.lua")
MERGE_SHA1 =
Digest::SHA1.hexdigest MERGE_SCRIPT

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(redis = Redis.new) ⇒ DiffMatchPatch

Returns a new instance of DiffMatchPatch.



20
21
22
# File 'lib/redis-diff_match_patch.rb', line 20

def initialize redis = Redis.new
  @redis = redis
end

Instance Attribute Details

#redisObject (readonly)

Returns the value of attribute redis.



8
9
10
# File 'lib/redis-diff_match_patch.rb', line 8

def redis
  @redis
end

Instance Method Details

#diff(src_key, dst_key, patch_key = nil) ⇒ Object



24
25
26
# File 'lib/redis-diff_match_patch.rb', line 24

def diff src_key, dst_key, patch_key = nil
  exec DIFF_SCRIPT, DIFF_SHA1, [ src_key, dst_key, patch_key ]
end

#merge(ancestor_key, key1, key2, result_key = nil) ⇒ Object



32
33
34
# File 'lib/redis-diff_match_patch.rb', line 32

def merge ancestor_key, key1, key2, result_key = nil
  exec MERGE_SCRIPT, MERGE_SHA1, [ ancestor_key, key1, key2, result_key ]
end

#patch(src_key, patch_key, dst_key = nil) ⇒ Object



28
29
30
# File 'lib/redis-diff_match_patch.rb', line 28

def patch src_key, patch_key, dst_key = nil
  exec PATCH_SCRIPT, PATCH_SHA1, [ src_key, patch_key, dst_key ]
end