ecs_compose 0.1.0.pre28 → 0.1.0.pre29

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ecs_compose/compare.rb +47 -10
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 62436596ba3a020cb588f41c9feb3c2c91327e5e
4
- data.tar.gz: 1211be0c76536e59e7b0c84393a35c863740f50d
3
+ metadata.gz: 57302424cdae84d0c6fae6f1cf6d1253bef38c96
4
+ data.tar.gz: 2695f370bd65f84d9cd89c28a1f6b32f4fd7f7fc
5
5
  SHA512:
6
- metadata.gz: d32532baf40f46b339999f47815300bda1cea9dcb5af5dfeb9428fd6ce4b40d1913c8e0dcccc1d211b010e7c7892c3b5f862fda0903742760fb3d7aba11d7d48
7
- data.tar.gz: 1998e1cefc8b7a262d7d1c7098554604fbf8037a17c27ba45a90edd69f82adaa96a1819efb2e7c38cb8fcf2690bdbb134f74283d796c220e226aed026ed5d11b
6
+ metadata.gz: 6b091ab6dcd83216f5975bcac26434ae06dc89508c6b77ab2e6168855a6e036b7d3f2151ef1b8e33967e827ba202d2a5d35f140581688aeefda8b9cd9c87397a
7
+ data.tar.gz: 17104e01a5490a75ddb6e37248f882a55a83f48162f9d32b72cbf9b73a97058f5f942ddc99106142de941ddaf312f4b2fd17fd671d032d27ab1b1bf126698972
@@ -2,22 +2,59 @@ module EcsCompose
2
2
  # Utilities for comparing ECS task definition JSON, which we need to do
3
3
  # to determine whether or not a running service needs to be deployed.
4
4
  module Compare
5
+ # :nodoc: An internal table providing a sort order for data types.
6
+ CLASS_ORDINAL = {
7
+ String => 1,
8
+ # These can all be compared against each other.
9
+ Fixnum => 2, Float => 2, Bignum => 2,
10
+ Hash => 3,
11
+ Array => 4,
12
+ FalseClass => 5,
13
+ TrueClass => 6,
14
+ NilClass => 7,
15
+ }
16
+
17
+ # Compare two legal JSON values, and do our best to always return a
18
+ # result.
19
+ def self.compare_any(a, b)
20
+ # First sort by type.
21
+ class_order =
22
+ CLASS_ORDINAL.fetch(a.class) <=> CLASS_ORDINAL.fetch(b.class)
23
+ return class_order unless class_order == 0
24
+
25
+ # Then sort by value.
26
+ case a
27
+ when Hash
28
+ # Convert the hashes to arrays, sort them to normalize hash key
29
+ # order, and compare them.
30
+ compare_any(a.to_a.sort {|a1, b1| compare_any(a1, b1) },
31
+ b.to_a.sort {|a1, b1| compare_any(a1, b1) })
32
+ when Array
33
+ # Do a full array comparison so that we can slip in our comparison
34
+ # function.
35
+ for i in 0...([a.length, b.length].max)
36
+ if i >= a.length
37
+ return -1
38
+ elsif i >= b.length
39
+ return 1
40
+ else
41
+ elem_order = compare_any(a[i], b[i])
42
+ return elem_order unless elem_order == 0
43
+ end
44
+ end
45
+ 0
46
+ else
47
+ a <=> b
48
+ end
49
+ end
5
50
 
6
51
  # Recursively sort all arrays contained in `val`, in order to normalize
7
52
  # things like environment variables in different orders.
8
53
  def self.sort_recursively(val)
9
54
  case val
10
55
  when Array
11
- val.sort_by do |item|
12
- if item.instance_of?(Hash)
13
- item.to_a.sort
14
- elsif item.instance_of?(Array)
15
- # for an array of arrays, just return 1
16
- 1
17
- else
18
- item
19
- end
20
- end.map {|item| sort_recursively(item) }
56
+ val.map {|item| sort_recursively(item) }
57
+ .sort {|a1, b1| compare_any(a1, b1) }
21
58
  when Hash
22
59
  newval = {}
23
60
  val.each do |k, v|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ecs_compose
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.pre28
4
+ version: 0.1.0.pre29
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Kidd
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-12-16 00:00:00.000000000 Z
11
+ date: 2015-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: docopt