consyncful 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/consyncful.gemspec +2 -2
- data/lib/consyncful/item_mapper.rb +1 -1
- data/lib/consyncful/railtie.rb +7 -0
- data/lib/consyncful/sync.rb +10 -1
- data/lib/consyncful/tasks/consyncful.rake +30 -0
- data/lib/consyncful/version.rb +1 -1
- data/lib/consyncful.rb +2 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d8751b841c3cd74e65f5b9a11edb509972fd934b1e6d6a499851923b3d4ef18
|
4
|
+
data.tar.gz: 4d3c28b779113963c977264bfc2b6e1137743c7aacc20a593bcb7b10a78d55f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 969f519cb526dac0f0d6c9e9f6fdc6254a1d29af6e3ba33d6e4317e2553ac8abdfd6b17f2fd3fd8115d889d20e0f126a6d93503acc9278efe2f32e21f58bc141
|
7
|
+
data.tar.gz: 6f6b6b06950ee4ffd443553b0ef77c09873d104affeb409230746ffe32a4cf204c0015368e0e2b64bf3c241c36f389ec9ac5fedb81eb150d844ff8fd8e774539
|
data/Gemfile.lock
CHANGED
data/consyncful.gemspec
CHANGED
@@ -6,8 +6,8 @@ require "consyncful/version"
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "consyncful"
|
8
8
|
spec.version = Consyncful::VERSION
|
9
|
-
spec.authors = ["Andy Anastasiadis-Gray"]
|
10
|
-
spec.email = ["andy@boost.co.nz"]
|
9
|
+
spec.authors = ["Andy Anastasiadis-Gray", "Montgomery Anderson"]
|
10
|
+
spec.email = ["andy@boost.co.nz", "montgomery@boost.co.nz"]
|
11
11
|
|
12
12
|
spec.summary = %q{Contentful to local database synchronisation for Rails}
|
13
13
|
# spec.homepage = "TODO: Put your gem's website or public repo URL here."
|
data/lib/consyncful/sync.rb
CHANGED
@@ -11,7 +11,6 @@ end
|
|
11
11
|
module Consyncful
|
12
12
|
class Sync
|
13
13
|
include Mongoid::Document
|
14
|
-
# include ActionView::Helpers::DateHelper
|
15
14
|
|
16
15
|
DEFAULT_LOCALE = 'en-NZ'
|
17
16
|
|
@@ -94,6 +93,8 @@ module Consyncful
|
|
94
93
|
instance = find_or_initialize_item(item)
|
95
94
|
update_stats(instance, stats)
|
96
95
|
|
96
|
+
reset_fields(instance)
|
97
|
+
|
97
98
|
item.mapped_fields(DEFAULT_LOCALE).each do |field, value|
|
98
99
|
instance[field] = value
|
99
100
|
end
|
@@ -116,5 +117,13 @@ module Consyncful
|
|
116
117
|
def model_class(type)
|
117
118
|
Base.model_map[type] || Base
|
118
119
|
end
|
120
|
+
|
121
|
+
def reset_fields(instance)
|
122
|
+
instance.attributes.each do |field_name, _value|
|
123
|
+
next if field_name.in? %w[_id _type]
|
124
|
+
|
125
|
+
instance[field_name] = nil
|
126
|
+
end
|
127
|
+
end
|
119
128
|
end
|
120
129
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
namespace :consyncful do
|
4
|
+
task update: [:environment] do
|
5
|
+
Consyncful::Sync.latest.run
|
6
|
+
end
|
7
|
+
|
8
|
+
task refresh: [:environment] do
|
9
|
+
Consyncful::Sync.fresh.run
|
10
|
+
end
|
11
|
+
|
12
|
+
task :sync, [:seconds] => [:environment, :update_model_names] do |task, args|
|
13
|
+
seconds = args[:seconds].to_i
|
14
|
+
seconds = 15 if seconds.zero?
|
15
|
+
loop do
|
16
|
+
Consyncful::Sync.latest.run
|
17
|
+
sleep(seconds)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
task update_model_names: [:environment] do
|
22
|
+
Rails.application.eager_load!
|
23
|
+
puts 'Updating model names:'.blue
|
24
|
+
Consyncful::Base.model_map.each do |contentful_name, constant|
|
25
|
+
puts "#{contentful_name}: #{constant}".yellow
|
26
|
+
Consyncful::Base.where(contentful_type: contentful_name).update_all(_type: constant.to_s)
|
27
|
+
end
|
28
|
+
Consyncful::Base.where(:contentful_type.nin => Consyncful::Base.model_map.keys).update_all(_type: 'Consyncful::Base')
|
29
|
+
end
|
30
|
+
end
|
data/lib/consyncful/version.rb
CHANGED
data/lib/consyncful.rb
CHANGED
@@ -6,6 +6,8 @@ require 'contentful'
|
|
6
6
|
require "consyncful/base"
|
7
7
|
require "consyncful/sync"
|
8
8
|
|
9
|
+
require "consyncful/railtie" if defined?(Rails)
|
10
|
+
|
9
11
|
module Consyncful
|
10
12
|
class << self
|
11
13
|
attr_accessor :configuration
|
@@ -36,7 +38,6 @@ module Consyncful
|
|
36
38
|
@client ||= begin
|
37
39
|
options = Consyncful.configuration.contentful_client_options
|
38
40
|
options.reverse_merge!(DEFAULT_CLIENT_OPTIONS)
|
39
|
-
|
40
41
|
Contentful::Client.new(options)
|
41
42
|
end
|
42
43
|
end
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: consyncful
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Anastasiadis-Gray
|
8
|
+
- Montgomery Anderson
|
8
9
|
autorequire:
|
9
10
|
bindir: exe
|
10
11
|
cert_chain: []
|
11
|
-
date: 2019-
|
12
|
+
date: 2019-03-19 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: bundler
|
@@ -109,6 +110,7 @@ dependencies:
|
|
109
110
|
description:
|
110
111
|
email:
|
111
112
|
- andy@boost.co.nz
|
113
|
+
- montgomery@boost.co.nz
|
112
114
|
executables: []
|
113
115
|
extensions: []
|
114
116
|
extra_rdoc_files: []
|
@@ -129,8 +131,10 @@ files:
|
|
129
131
|
- lib/consyncful.rb
|
130
132
|
- lib/consyncful/base.rb
|
131
133
|
- lib/consyncful/item_mapper.rb
|
134
|
+
- lib/consyncful/railtie.rb
|
132
135
|
- lib/consyncful/stats.rb
|
133
136
|
- lib/consyncful/sync.rb
|
137
|
+
- lib/consyncful/tasks/consyncful.rake
|
134
138
|
- lib/consyncful/version.rb
|
135
139
|
homepage:
|
136
140
|
licenses:
|