consyncful 0.1.0 → 0.2.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: c489939e52bc185ec4c807d7f0d30b0347ec78d6acdc22c5469da2c78a749405
4
- data.tar.gz: 34b24e8195a6f3be6d3a0753511959fefb815e21e87f2b1cc8ad67317d4c90ed
3
+ metadata.gz: 1d8751b841c3cd74e65f5b9a11edb509972fd934b1e6d6a499851923b3d4ef18
4
+ data.tar.gz: 4d3c28b779113963c977264bfc2b6e1137743c7aacc20a593bcb7b10a78d55f7
5
5
  SHA512:
6
- metadata.gz: ab76e80b28c06aa855cf375868200226e48205a0093b70400e94ff1dcf5499bf47fb6970f5477193038028254901637c8a73759a04a15eeeb667beb054c2f5e8
7
- data.tar.gz: e3f9401264b593c4b11d1cd1fe1cbef34ad2c44ae79b727b027d84bf4980eb284e85bec8b0e3d67642f2b81cf076bb75cb9aa055b16670b6deb9b9d024c3b2b1
6
+ metadata.gz: 969f519cb526dac0f0d6c9e9f6fdc6254a1d29af6e3ba33d6e4317e2553ac8abdfd6b17f2fd3fd8115d889d20e0f126a6d93503acc9278efe2f32e21f58bc141
7
+ data.tar.gz: 6f6b6b06950ee4ffd443553b0ef77c09873d104affeb409230746ffe32a4cf204c0015368e0e2b64bf3c241c36f389ec9ac5fedb81eb150d844ff8fd8e774539
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- consyncful (0.1.0)
4
+ consyncful (0.2.0)
5
5
  contentful (>= 2.11.1, < 3.0.0)
6
6
  mongoid (>= 7.0.2, < 8.0.0)
7
7
  term-ansicolor
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."
@@ -51,7 +51,7 @@ module Consyncful
51
51
 
52
52
  def raw_file(locale)
53
53
  file_json = @item.raw.fetch('fields', {}).fetch('file', nil)
54
- file_json[locale]
54
+ file_json[locale] unless file_json.nil?
55
55
  end
56
56
 
57
57
  def reference_value?(value)
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Consyncful::Railtie < Rails::Railtie
4
+ rake_tasks do
5
+ load 'consyncful/tasks/consyncful.rake'
6
+ end
7
+ end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Consyncful
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
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.1.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-02-22 00:00:00.000000000 Z
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: