tree_delta 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: df6e2308561f7c2800ec01e8e1205db41e3fbdd2
4
- data.tar.gz: 678b3ee7309db439390356c716229f8fd9afd271
3
+ metadata.gz: 132981c95ed21fd232a44c1f93aca5477da0afa6
4
+ data.tar.gz: 591ba9d6faf95b30b565a4622e5224f6a6c6a384
5
5
  SHA512:
6
- metadata.gz: dc0433f176917897f6175fa7cba1a70b69d51d76d67cbfee924f2604005559a981c40a887d29ed23babe0515d9deaa5e9d70b541cbc810bc9adf273f66475815
7
- data.tar.gz: cabc88fd38856bbd3dc53e57b3ddf1fda5f33decafc7eb5e72e9bcbd2b678fd8002b8ed81727c59f171353d14fbe1b8b731f2c02b36e8fa7faccf9d51bf41c0b
6
+ metadata.gz: d43ea4013511758125d18b1ff31c38610d9c50f3142a58e248817fc012df0843f22d210be2b191e67ee70d4d55c726f3f3d6db28c756513cb108770c15bcd448
7
+ data.tar.gz: db22eb1b9992dd0c7da0ed491734f81905e7be29b67a67c999fa0adf0ff1d175704d913dfccd3d76d4f564e3362db31c82c0b23a2345f9464c8e7a347bc915e1
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  ## Tree Delta
2
2
 
3
+ [![Build Status](https://travis-ci.org/whichdigital/tree_delta.svg?branch=master)](https://travis-ci.org/whichdigital/tree_delta)
4
+
3
5
  Calculates the minimum set of operations that transform one tree into another.
4
6
 
5
7
  ## Overview
@@ -49,7 +51,7 @@ value object for a node. This is where you'd store the node's attributes.
49
51
  You must first define a node class with the following methods:
50
52
 
51
53
  ```ruby
52
- #id
54
+ #identity
53
55
  Returns an identifier that uniquely identifies the node across trees.
54
56
 
55
57
  #parent
@@ -100,7 +102,7 @@ An operation is a simple object that describes a transformation.
100
102
 
101
103
  It can contain up to five pieces of information, as shown here:
102
104
 
103
- | | type | id | value | parent | position |
105
+ | | type | identity | value | parent | position |
104
106
  | --------:|:--------:|:--------:|:--------:|:--------:|:--------:|
105
107
  | create | ✓ | ✓ | ✓ | ✓ | ✓ |
106
108
  | update | ✓ | ✓ | ✓ | | |
@@ -114,7 +116,7 @@ Here is an example:
114
116
  operation.type
115
117
  #=> :create
116
118
 
117
- operation.id
119
+ operation.identity
118
120
  #=> "foo"
119
121
 
120
122
  operation.value
@@ -11,9 +11,9 @@ class TreeDelta::Intermediate
11
11
  additions.each do |node|
12
12
  y.yield TreeDelta::Operation.new(
13
13
  type: :create,
14
- id: node.id,
14
+ identity: node.identity,
15
15
  value: node.value,
16
- parent: parent_id(node),
16
+ parent: parent_identity(node),
17
17
  position: position(node)
18
18
  )
19
19
  end
@@ -25,7 +25,7 @@ class TreeDelta::Intermediate
25
25
  updated_nodes.each do |node|
26
26
  y.yield TreeDelta::Operation.new(
27
27
  type: :update,
28
- id: node.id,
28
+ identity: node.identity,
29
29
  value: node.value,
30
30
  )
31
31
  end
@@ -36,8 +36,8 @@ class TreeDelta::Intermediate
36
36
  Enumerator.new do |y|
37
37
  normalised_deletions.each do |node|
38
38
  y.yield TreeDelta::Operation.new(
39
- type: :delete,
40
- id: node.id
39
+ type: :delete,
40
+ identity: node.identity
41
41
  )
42
42
  end
43
43
  end
@@ -48,8 +48,8 @@ class TreeDelta::Intermediate
48
48
  moves.each do |node|
49
49
  unless previous_root?(node)
50
50
  y.yield TreeDelta::Operation.new(
51
- type: :detach,
52
- id: node.id
51
+ type: :detach,
52
+ identity: node.identity
53
53
  )
54
54
  end
55
55
  end
@@ -62,8 +62,8 @@ class TreeDelta::Intermediate
62
62
  unless root?(node)
63
63
  y.yield TreeDelta::Operation.new(
64
64
  type: :attach,
65
- id: node.id,
66
- parent: parent_id(node),
65
+ identity: node.identity,
66
+ parent: parent_identity(node),
67
67
  position: position(node)
68
68
  )
69
69
  end
@@ -106,11 +106,11 @@ class TreeDelta::Intermediate
106
106
  end
107
107
 
108
108
  def subtract(a, b)
109
- a.reject { |e| b.any? { |f| e.id == f.id } }
109
+ a.reject { |e| b.any? { |f| e.identity == f.identity } }
110
110
  end
111
111
 
112
- def parent_id(node)
113
- node && node.parent ? node.parent.id : nil
112
+ def parent_identity(node)
113
+ node && node.parent ? node.parent.identity : nil
114
114
  end
115
115
 
116
116
  def position(node)
@@ -128,11 +128,11 @@ class TreeDelta::Intermediate
128
128
 
129
129
  def changed_parent?(from_node)
130
130
  to_node = to_node_for(from_node)
131
- to_node && parent_id(to_node) != parent_id(from_node)
131
+ to_node && parent_identity(to_node) != parent_identity(from_node)
132
132
  end
133
133
 
134
134
  def normalised_position_changes
135
- groups = position_changes.group_by { |n| parent_id(n) }
135
+ groups = position_changes.group_by { |n| parent_identity(n) }
136
136
 
137
137
  groups.map do |_, nodes|
138
138
  TreeDelta::Normaliser.normalise_position_changes(nodes)
@@ -148,16 +148,16 @@ class TreeDelta::Intermediate
148
148
  to_node = to_node_for(from_node)
149
149
 
150
150
  to_node &&
151
- parent_id(from_node) == parent_id(to_node) &&
151
+ parent_identity(from_node) == parent_identity(to_node) &&
152
152
  position(from_node) != position(to_node)
153
153
  end
154
154
 
155
155
  def from_node_for(to_node)
156
- from_nodes.detect { |n| n.id == to_node.id }
156
+ from_nodes.detect { |n| n.identity == to_node.identity }
157
157
  end
158
158
 
159
159
  def to_node_for(from_node)
160
- to_nodes.detect { |n| n.id == from_node.id }
160
+ to_nodes.detect { |n| n.identity == from_node.identity }
161
161
  end
162
162
 
163
163
  def root?(to_node)
@@ -1,20 +1,20 @@
1
1
  class TreeDelta::Operation
2
2
 
3
- attr_reader :type, :id, :value, :parent, :position
3
+ attr_reader :type, :identity, :value, :parent, :position
4
4
 
5
- def initialize(type:, id:, value: nil, parent: nil, position: nil)
5
+ def initialize(type:, identity:, value: nil, parent: nil, position: nil)
6
6
  @type = type
7
- @id = id
7
+ @identity = identity
8
8
  @value = value if value
9
9
  @parent = parent if parent
10
10
  @position = position if position
11
11
  end
12
12
 
13
13
  def ==(other)
14
- @type == other.type &&
15
- @id == other.id &&
16
- @value == other.value &&
17
- @parent == other.parent &&
14
+ @type == other.type &&
15
+ @identity == other.identity &&
16
+ @value == other.value &&
17
+ @parent == other.parent &&
18
18
  @position == other.position
19
19
  end
20
20
 
@@ -3,7 +3,7 @@ module TreeDelta::Sorter
3
3
  sorted_array = []
4
4
 
5
5
  enumerator.each do |object|
6
- element = array.detect { |e| e.id == object.id }
6
+ element = array.detect { |e| e.identity == object.identity }
7
7
  sorted_array << element if element
8
8
  end
9
9
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tree_delta
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Patuzzo
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-03-03 00:00:00.000000000 Z
13
+ date: 2015-07-20 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake