doggy 2.0.25 → 2.0.26

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: 6f8434387b7dd0a3e6cf04e576978b44d820cd84
4
- data.tar.gz: ac0362cc3d9a5b9e95374e5854801f4eca0b7892
3
+ metadata.gz: 34c9e3abbc694a088709003978294cc500338c8e
4
+ data.tar.gz: 1cc97bcb81bb1198f1bd936d1080a9ee0307b7bd
5
5
  SHA512:
6
- metadata.gz: bed0338d823b01bd8e203235d1f03c46a5ff7544bda7381d049e49bc556566538b81f66c1f6a3854f476cac09b12c3679242137529dfdc685db9c1b362bcad31
7
- data.tar.gz: aae169f9e3cc7a61851631dcb21fefe16cb48651300ed6c67fd781f3be255afea8c542aea63e75950655b73ee8d1c553c03d54cd78bea48c78f8a7939c388e6d
6
+ metadata.gz: bb54356ef11e5bc7f23cdf192f06870546390725959898294fb1d70b4a5315764ad311fb5e42467192722033de2e6b48583815f17c49993812ee479e7eb07cca
7
+ data.tar.gz: 54c8b8957a0590a66bfbd365fd00477a012032658f59e4bd069a310354312fbc626b194806519d37360f5326e5d9fd5518012a1752dad5e10fd993c224449aea
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- doggy (2.0.25)
4
+ doggy (2.0.26)
5
5
  json (~> 1.8.3)
6
6
  parallel (~> 1.6.1)
7
7
  rugged (~> 0.23.2)
@@ -28,17 +28,32 @@ module Doggy
28
28
  private
29
29
 
30
30
  def pull_by_id(id)
31
- local_resource = @local_resources.find { |l| l.id == id }
32
- if !local_resource
33
- remote_resource = [Models::Dashboard, Models::Monitor, Models::Screen].map do |klass|
34
- klass.find(id)
35
- end.compact.first
31
+ local_resources = @local_resources.find_all { |l| l.id == id }
36
32
 
37
- remote_resource.save_local
33
+ remote_resources = [Models::Dashboard, Models::Monitor, Models::Screen].map do |klass|
34
+ klass.find(id)
35
+ end.compact
36
+
37
+ if local_resources.size != remote_resources.size
38
+ normalized_remote_resources = remote_resources.map { |remote_resource| [ remote_resource.class.name, remote_resource.id ] }
39
+ normalized_local_resources = local_resources.map { |local_resource| [ local_resource.class.name, local_resource.id ] }
40
+ normalized_resource_diff = Hash[normalized_remote_resources - normalized_local_resources]
41
+
42
+ # Here we traverse `remote_resources` to find remote resource with matching class name and id.
43
+ # We cannot subtract `local_resources` from `remote_resources` because those are different kind of objects.
44
+ remote_resources_to_be_saved = normalized_resource_diff.map do |klass, id|
45
+ remote_resources.find do |rr|
46
+ rr.class.name == klass && rr.id == id
47
+ end
48
+ end
49
+
50
+ remote_resources_to_be_saved.each(&:save_local)
38
51
  else
39
- remote_resource = local_resource.class.find(local_resource.id)
40
- remote_resource.path = local_resource.path
41
- remote_resource.save_local
52
+ local_resources.each do |local_resource|
53
+ remote_resource = local_resource.class.find(local_resource.id)
54
+ remote_resource.path = local_resource.path
55
+ remote_resource.save_local
56
+ end
42
57
  end
43
58
  end
44
59
 
data/lib/doggy/model.rb CHANGED
@@ -173,7 +173,13 @@ module Doggy
173
173
  end
174
174
 
175
175
  def save_local
176
- @path ||= Doggy.object_root.join("#{ id }.json")
176
+ prefix = case self.class.name
177
+ when 'Doggy::Models::Dashboard' then 'dash'
178
+ when 'Doggy::Models::Monitor' then 'monitor'
179
+ when 'Doggy::Models::Screen' then 'screen'
180
+ end
181
+
182
+ @path ||= Doggy.object_root.join("#{prefix}-#{id}.json")
177
183
  File.open(@path, 'w') { |f| f.write(JSON.pretty_generate(to_h)) }
178
184
  end
179
185
 
data/lib/doggy/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Doggy
4
- VERSION = "2.0.25"
4
+ VERSION = "2.0.26"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: doggy
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.25
4
+ version: 2.0.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vlad Gorodetsky
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2016-06-14 00:00:00.000000000 Z
12
+ date: 2016-06-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -176,7 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
176
176
  version: '0'
177
177
  requirements: []
178
178
  rubyforge_project:
179
- rubygems_version: 2.6.4
179
+ rubygems_version: 2.6.5
180
180
  signing_key:
181
181
  specification_version: 4
182
182
  summary: Syncs DataDog dashboards, alerts, screenboards, and monitors.