midwire_common 0.1.11 → 0.1.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +4 -0
- data/README.md +1 -1
- data/lib/midwire_common/all.rb +1 -1
- data/lib/midwire_common/hash.rb +47 -0
- data/lib/midwire_common/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dcbd766fa404dee3f40d4d338117022cfa80fa0f
|
4
|
+
data.tar.gz: 18dcf1ba51b11d5ebadf7bd7f81d5d6e1261bdd8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1dbf997be279cb4cc0756f500b05d6319a275871633f3d177aaa7520862f03ff6d64c2a17f70cc6b98588c93761597165999eaac9340a3081330a98547afeda
|
7
|
+
data.tar.gz: 94b5bf3534b408b44e791f3bad888cbded6af424f1c98ea4c26bb4676df24c733d092b6386c2a5d613b97bfd7de44811407d80e3c82657b901280f576451a004
|
data/CHANGELOG
CHANGED
data/README.md
CHANGED
data/lib/midwire_common/all.rb
CHANGED
@@ -6,6 +6,6 @@ require 'midwire_common/fixnum'
|
|
6
6
|
require 'midwire_common/float'
|
7
7
|
require 'midwire_common/hash'
|
8
8
|
require 'midwire_common/string'
|
9
|
-
require 'midwire_common/system_command'
|
9
|
+
# require 'midwire_common/system_command'
|
10
10
|
require 'midwire_common/time'
|
11
11
|
require 'midwire_common/time_tool'
|
data/lib/midwire_common/hash.rb
CHANGED
@@ -6,6 +6,53 @@ class Hash
|
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
9
|
+
def diff(other)
|
10
|
+
(self.keys + other.keys).uniq.inject({}) do |memo, key|
|
11
|
+
unless self[key] == other[key]
|
12
|
+
if self[key].kind_of?(Hash) && other[key].kind_of?(Hash)
|
13
|
+
memo[key] = self[key].diff(other[key])
|
14
|
+
else
|
15
|
+
memo[key] = [self[key], other[key]]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
memo
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def apply_diff!(changes, direction = :right)
|
23
|
+
path = [[self, changes]]
|
24
|
+
pos, local_changes = path.pop
|
25
|
+
while local_changes
|
26
|
+
local_changes.each_pair {|key, change|
|
27
|
+
if change.kind_of?(Array)
|
28
|
+
pos[key] = (direction == :right) ? change[1] : change[0]
|
29
|
+
else
|
30
|
+
path.push([pos[key], change])
|
31
|
+
end
|
32
|
+
}
|
33
|
+
pos, local_changes = path.pop
|
34
|
+
end
|
35
|
+
self
|
36
|
+
end
|
37
|
+
|
38
|
+
def apply_diff(changes, direction = :right)
|
39
|
+
cloned = self.clone
|
40
|
+
path = [[cloned, changes]]
|
41
|
+
pos, local_changes = path.pop
|
42
|
+
while local_changes
|
43
|
+
local_changes.each_pair {|key, change|
|
44
|
+
if change.kind_of?(Array)
|
45
|
+
pos[key] = (direction == :right) ? change[1] : change[0]
|
46
|
+
else
|
47
|
+
pos[key] = pos[key].clone
|
48
|
+
path.push([pos[key], change])
|
49
|
+
end
|
50
|
+
}
|
51
|
+
pos, local_changes = path.pop
|
52
|
+
end
|
53
|
+
cloned
|
54
|
+
end
|
55
|
+
|
9
56
|
# Usage { :a => 1, :b => 2, :c => 3}.except(:a) -> { :b => 2, :c => 3}
|
10
57
|
def except(*keys)
|
11
58
|
self.reject { |k,v|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: midwire_common
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Blackburn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|