cartomodel 0.1.0 → 0.1.1

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: b5c3063fdba6f802ecad416c4028764171507277
4
- data.tar.gz: 385944e4e94f45ffbb272a0898ca5af535ae520b
3
+ metadata.gz: def3abed8f01159d97c5a7b1db53e41928c59a36
4
+ data.tar.gz: 128b0d8c6ed6bd34c91322d44a428855b1d8f090
5
5
  SHA512:
6
- metadata.gz: 74e38bac4b0d5f436958b391b288478ba730bfbaf205fbfbe8664d47b4d093c469c6f996c16c5454dab799ac549b0ce56a55c263a62e4b831be97d17f022042f
7
- data.tar.gz: 09262f7ccb56f3785daae85436f72a7ba6242affc83448e2699871d9b17237a5f3bfb413a771222fae306e3f0b22288912d3fac950d57cc957e0aabbdd09b0cc
6
+ metadata.gz: ab911b7e60230402d01e33000b2d365d92bf882be676e982bfa5f6aa616abe5414ef32e82d642a82db3180b9ea96ec9191456a507b98462fc63e3d1211815a29
7
+ data.tar.gz: 8cc73daab626fe6b3bc2fe500efc2357915c0dfd1c352165709d672ace31bba262e1b4ae7a639e44abeab493068fcb9235c5d19903f2568c21978d22121f9fb4
data/README.md CHANGED
@@ -36,4 +36,14 @@ class AddCartomodelColumnsYourModel < ActiveRecord::Migration
36
36
  add_column :indicator_configs, :sync_state, :integer
37
37
  end
38
38
  end
39
- ```
39
+ ```
40
+
41
+ # Sync
42
+
43
+ If CartoDB, for some reason, fails to save your data, you can retry later using a rake task:
44
+
45
+ ```
46
+ rake cartomodel:sync
47
+ ```
48
+
49
+ Currently the task prints no output on progress or success
data/Rakefile CHANGED
@@ -4,6 +4,8 @@ rescue LoadError
4
4
  puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
5
  end
6
6
 
7
+ import "tasks/sync.rake"
8
+
7
9
  task :default => [:spec]
8
10
  desc 'run Rspec specs'
9
11
  task :spec do
@@ -2,6 +2,7 @@ module Cartomodel
2
2
  module Model
3
3
  module Synchronizable
4
4
  extend ActiveSupport::Concern
5
+ extend ActiveSupport::DescendantsTracker
5
6
 
6
7
  STATE_UNSYNCED = 0
7
8
  STATE_SYNCED = 1
@@ -0,0 +1,32 @@
1
+ module Cartomodel
2
+ class Synchronizer
3
+ def self.sync_all
4
+ self.get_failed_synced_instances.each do |object|
5
+ object.class.skip_callback(:create, :before, :create_on_cartodb)
6
+ object.class.skip_callback(:update, :before, :update_on_cartodb)
7
+
8
+ begin
9
+ if object.cartodb_id then
10
+ object.update_on_cartodb
11
+ else
12
+ object.create_on_cartodb
13
+ end
14
+ object.save
15
+ ensure
16
+ object.class.set_callback(:create, :before, :create_on_cartodb)
17
+ object.class.set_callback(:update, :before, :update_on_cartodb)
18
+ end
19
+ end
20
+ end
21
+
22
+ def self.get_failed_synced_instances
23
+ result = []
24
+ ActiveRecord::Base.descendants.each do |active_record_descendant|
25
+ next if active_record_descendant.included_modules.exclude? Cartomodel::Model::Synchronizable or !ActiveRecord::Base.connection.column_exists? active_record_descendant.table_name, :sync_state
26
+ result.concat active_record_descendant.where(sync_state: Cartomodel::Model::Synchronizable::STATE_FAILED)
27
+ end
28
+ result
29
+ end
30
+ end
31
+ end
32
+
@@ -1,3 +1,3 @@
1
1
  module Cartomodel
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/cartomodel.rb CHANGED
@@ -3,6 +3,7 @@ require 'active_record'
3
3
  require 'cartomodel/version'
4
4
  require 'cartomodel/models/synchronizable'
5
5
  require 'cartomodel/query_generator'
6
+ require 'cartomodel/synchronizer'
6
7
  require 'cartowrap'
7
8
 
8
9
  module Cartomodel
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cartomodel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tiago Garcia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-25 00:00:00.000000000 Z
11
+ date: 2016-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -135,6 +135,7 @@ files:
135
135
  - lib/cartomodel/errors.rb
136
136
  - lib/cartomodel/models/synchronizable.rb
137
137
  - lib/cartomodel/query_generator.rb
138
+ - lib/cartomodel/synchronizer.rb
138
139
  - lib/cartomodel/version.rb
139
140
  homepage: http://vizzuality.com
140
141
  licenses: