consyncful 0.2.0 → 0.3.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
  SHA256:
3
- metadata.gz: 1d8751b841c3cd74e65f5b9a11edb509972fd934b1e6d6a499851923b3d4ef18
4
- data.tar.gz: 4d3c28b779113963c977264bfc2b6e1137743c7aacc20a593bcb7b10a78d55f7
3
+ metadata.gz: 258e4fe9fbea3099f0d78615c79b1e49658841c7b706f296a1d5402115c5ed7d
4
+ data.tar.gz: 8d47ad368c228b87a1f04fc5d1c4c236c16d6d3106bae1dda6a49de0a74a9c9d
5
5
  SHA512:
6
- metadata.gz: 969f519cb526dac0f0d6c9e9f6fdc6254a1d29af6e3ba33d6e4317e2553ac8abdfd6b17f2fd3fd8115d889d20e0f126a6d93503acc9278efe2f32e21f58bc141
7
- data.tar.gz: 6f6b6b06950ee4ffd443553b0ef77c09873d104affeb409230746ffe32a4cf204c0015368e0e2b64bf3c241c36f389ec9ac5fedb81eb150d844ff8fd8e774539
6
+ metadata.gz: 18b498a8a55c814edf02fabec13c54d93a6653aae0e1e87143ea9e2d637d3eb61e6beaf045201660ad065bb745f4df97b411fa6f451bbd02858d45b1e041aa24
7
+ data.tar.gz: 841216be1a7c0149aea9e6136369cdd2bd3a1e5d9edb9854b677f98d2ef1596b7df3273370054713915fd798016578263398f24d8e23460360caa2bb5751871d
data/.rubocop.yml ADDED
@@ -0,0 +1,9 @@
1
+
2
+
3
+
4
+ Metrics/LineLength:
5
+ Max: 120
6
+
7
+ Metrics/BlockLength:
8
+ Exclude:
9
+ - spec/**/*
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.5.5
data/Gemfile CHANGED
@@ -1,6 +1,8 @@
1
- source "https://rubygems.org"
1
+ # frozen_string_literal: true
2
2
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
6
 
5
7
  # Specify your gem's dependencies in consyncful.gemspec
6
8
  gemspec
data/Gemfile.lock CHANGED
@@ -78,5 +78,3 @@ DEPENDENCIES
78
78
  rake (~> 10.0)
79
79
  rspec (~> 3.0)
80
80
 
81
- BUNDLED WITH
82
- 1.16.1
data/README.md CHANGED
@@ -90,7 +90,7 @@ To run a syncronization process run:
90
90
 
91
91
  The first time you run this it will download all the contentful content, it will then check every 15 seconds for changes to the content and update/delete records in the database when changes are made in contentful.
92
92
 
93
- If you want to delete everything and start syncronising from scratch run:
93
+ If you want to syncronise from scratch run:
94
94
 
95
95
  $ rake consyncful:refresh
96
96
 
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
- task :default => :spec
8
+ task default: :spec
data/bin/console CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "bundler/setup"
4
- require "consyncful"
4
+ require 'bundler/setup'
5
+ require 'consyncful'
5
6
 
6
7
  # You can add fixtures and/or initialization code here to make experimenting
7
8
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +11,5 @@ require "consyncful"
10
11
  # require "pry"
11
12
  # Pry.start
12
13
 
13
- require "irb"
14
+ require 'irb'
14
15
  IRB.start(__FILE__)
data/consyncful.gemspec CHANGED
@@ -1,17 +1,18 @@
1
+ # frozen_string_literal: true
1
2
 
2
- lib = File.expand_path("../lib", __FILE__)
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "consyncful/version"
5
+ require 'consyncful/version'
5
6
 
6
7
  Gem::Specification.new do |spec|
7
- spec.name = "consyncful"
8
+ spec.name = 'consyncful'
8
9
  spec.version = Consyncful::VERSION
9
- spec.authors = ["Andy Anastasiadis-Gray", "Montgomery Anderson"]
10
- spec.email = ["andy@boost.co.nz", "montgomery@boost.co.nz"]
10
+ spec.authors = ['Andy Anastasiadis-Gray', 'Montgomery Anderson']
11
+ spec.email = ['andy@boost.co.nz', 'montgomery@boost.co.nz']
11
12
 
12
- spec.summary = %q{Contentful to local database synchronisation for Rails}
13
- # spec.homepage = "TODO: Put your gem's website or public repo URL here."
14
- spec.license = "MIT"
13
+ spec.summary = 'Contentful to local database synchronisation for Rails'
14
+ spec.homepage = 'https://github.com/boost/consyncful'
15
+ spec.license = 'MIT'
15
16
 
16
17
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
18
  # to allow pushing to a single host or delete this section to allow pushing to any host.
@@ -25,15 +26,15 @@ Gem::Specification.new do |spec|
25
26
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
27
  f.match(%r{^(test|spec|features)/})
27
28
  end
28
- spec.bindir = "exe"
29
+ spec.bindir = 'exe'
29
30
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
- spec.require_paths = ["lib"]
31
+ spec.require_paths = ['lib']
31
32
 
32
- spec.add_development_dependency "bundler", "~> 1.16"
33
- spec.add_development_dependency "rake", "~> 10.0"
34
- spec.add_development_dependency "rspec", "~> 3.0"
33
+ spec.add_development_dependency 'bundler', '~> 1.16'
34
+ spec.add_development_dependency 'rake', '~> 10.0'
35
+ spec.add_development_dependency 'rspec', '~> 3.0'
35
36
 
36
- spec.add_dependency "mongoid", [">=7.0.2", "<8.0.0"]
37
- spec.add_dependency "contentful", [">=2.11.1", "<3.0.0"]
37
+ spec.add_dependency 'contentful', ['>=2.11.1', '<3.0.0']
38
+ spec.add_dependency 'mongoid', ['>=7.0.2', '<8.0.0']
38
39
  spec.add_dependency 'term-ansicolor'
39
40
  end
data/docker-compose.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  version: '3'
2
2
  services:
3
3
  mongo:
4
- image: mongo
4
+ image: mongo:3.6
5
5
  volumes:
6
6
  - ./dev_data/mongo:/data/db
7
7
  ports:
data/lib/consyncful.rb CHANGED
@@ -1,12 +1,14 @@
1
- require "consyncful/version"
1
+ # frozen_string_literal: true
2
+
3
+ require 'consyncful/version'
2
4
 
3
5
  require 'mongoid'
4
6
  require 'contentful'
5
7
 
6
- require "consyncful/base"
7
- require "consyncful/sync"
8
+ require 'consyncful/base'
9
+ require 'consyncful/sync'
8
10
 
9
- require "consyncful/railtie" if defined?(Rails)
11
+ require 'consyncful/railtie' if defined?(Rails)
10
12
 
11
13
  module Consyncful
12
14
  class << self
@@ -32,7 +34,7 @@ module Consyncful
32
34
  DEFAULT_CLIENT_OPTIONS = {
33
35
  reuse_entries: true,
34
36
  api_url: 'cdn.contentful.com'
35
- }
37
+ }.freeze
36
38
 
37
39
  def self.client
38
40
  @client ||= begin
@@ -21,14 +21,15 @@ module Consyncful
21
21
  last || new
22
22
  end
23
23
 
24
- def self.reset
24
+ def self.fresh
25
25
  destroy_all
26
- Base.destroy_all
26
+ latest
27
27
  end
28
28
 
29
- def self.fresh
30
- reset
31
- latest
29
+ def drop_stale
30
+ stale = Base.where(:sync_id.ne => id, :sync_id.exists => true)
31
+ puts "Dropping #{stale.count} records that haven't been touched in this sync".red
32
+ stale.destroy
32
33
  end
33
34
 
34
35
  def run
@@ -39,6 +40,8 @@ module Consyncful
39
40
 
40
41
  sync_items(sync, stats)
41
42
 
43
+ drop_stale
44
+
42
45
  self.next_url = sync.next_sync_url
43
46
  self.last_run_at = Time.current
44
47
  save
@@ -49,6 +52,7 @@ module Consyncful
49
52
 
50
53
  def load_all_models
51
54
  return unless defined? Rails
55
+
52
56
  Rails.application.eager_load!
53
57
  end
54
58
 
@@ -99,6 +103,8 @@ module Consyncful
99
103
  instance[field] = value
100
104
  end
101
105
 
106
+ instance[:sync_id] = id
107
+
102
108
  instance.save
103
109
  end
104
110
 
@@ -9,7 +9,7 @@ namespace :consyncful do
9
9
  Consyncful::Sync.fresh.run
10
10
  end
11
11
 
12
- task :sync, [:seconds] => [:environment, :update_model_names] do |task, args|
12
+ task :sync, [:seconds] => %i[environment update_model_names] do |_task, args|
13
13
  seconds = args[:seconds].to_i
14
14
  seconds = 15 if seconds.zero?
15
15
  loop do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Consyncful
2
- VERSION = "0.2.0"
4
+ VERSION = '0.3.0'
3
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: consyncful
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Anastasiadis-Gray
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2019-03-19 00:00:00.000000000 Z
12
+ date: 2019-07-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -54,45 +54,45 @@ dependencies:
54
54
  - !ruby/object:Gem::Version
55
55
  version: '3.0'
56
56
  - !ruby/object:Gem::Dependency
57
- name: mongoid
57
+ name: contentful
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - ">="
61
61
  - !ruby/object:Gem::Version
62
- version: 7.0.2
62
+ version: 2.11.1
63
63
  - - "<"
64
64
  - !ruby/object:Gem::Version
65
- version: 8.0.0
65
+ version: 3.0.0
66
66
  type: :runtime
67
67
  prerelease: false
68
68
  version_requirements: !ruby/object:Gem::Requirement
69
69
  requirements:
70
70
  - - ">="
71
71
  - !ruby/object:Gem::Version
72
- version: 7.0.2
72
+ version: 2.11.1
73
73
  - - "<"
74
74
  - !ruby/object:Gem::Version
75
- version: 8.0.0
75
+ version: 3.0.0
76
76
  - !ruby/object:Gem::Dependency
77
- name: contentful
77
+ name: mongoid
78
78
  requirement: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: 2.11.1
82
+ version: 7.0.2
83
83
  - - "<"
84
84
  - !ruby/object:Gem::Version
85
- version: 3.0.0
85
+ version: 8.0.0
86
86
  type: :runtime
87
87
  prerelease: false
88
88
  version_requirements: !ruby/object:Gem::Requirement
89
89
  requirements:
90
90
  - - ">="
91
91
  - !ruby/object:Gem::Version
92
- version: 2.11.1
92
+ version: 7.0.2
93
93
  - - "<"
94
94
  - !ruby/object:Gem::Version
95
- version: 3.0.0
95
+ version: 8.0.0
96
96
  - !ruby/object:Gem::Dependency
97
97
  name: term-ansicolor
98
98
  requirement: !ruby/object:Gem::Requirement
@@ -117,6 +117,8 @@ extra_rdoc_files: []
117
117
  files:
118
118
  - ".gitignore"
119
119
  - ".rspec"
120
+ - ".rubocop.yml"
121
+ - ".ruby-version"
120
122
  - ".travis.yml"
121
123
  - Gemfile
122
124
  - Gemfile.lock
@@ -136,7 +138,7 @@ files:
136
138
  - lib/consyncful/sync.rb
137
139
  - lib/consyncful/tasks/consyncful.rake
138
140
  - lib/consyncful/version.rb
139
- homepage:
141
+ homepage: https://github.com/boost/consyncful
140
142
  licenses:
141
143
  - MIT
142
144
  metadata: {}
@@ -156,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
158
  version: '0'
157
159
  requirements: []
158
160
  rubyforge_project:
159
- rubygems_version: 2.7.6
161
+ rubygems_version: 2.7.6.2
160
162
  signing_key:
161
163
  specification_version: 4
162
164
  summary: Contentful to local database synchronisation for Rails