syncify 0.1.4 → 0.1.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 612709c8c6ba1a45b4995e518df50c8b4ac0110d
4
- data.tar.gz: 34f0f19fa22c221bf957990eef8abc3e9818da72
3
+ metadata.gz: 1722af5f629f92ed4a34ede9157e902cb5d3523c
4
+ data.tar.gz: b89894af010324fb43ec9dda4376ba4c9d2543b4
5
5
  SHA512:
6
- metadata.gz: c9c7baa10434904eb55a4484b0e45978d73a495d4f63e64552a39188ab8990a936dfbb7dc9ddfeb3ad65bba13255cf5d77d0905af1c3158197ba6fd2e9d23964
7
- data.tar.gz: 1647a2b6fc6cb2a17c19cf87351536b2d11ddee55cd669c495f7dc58f3597da3cc8dcceeb625d545d2c12b2427c1f70c9717209aa24d3ff6e3fce167467f243a
6
+ metadata.gz: dd8e95679bd3ab02725da8553bbdec166aa09745682a51fe62bacd43a65124baed7aed728d59c0806843fab90552fb3765fba081589374d73179c860776061bb
7
+ data.tar.gz: 789e5dda07c8f5fb3263bf940cbf16e3dbcf83266afd76cb61fbabb8a521fc4ed500cd56d1b2508fd95bcee4db8299822b6c286c21412e741dfb383bc72f0e7e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- syncify (0.1.3)
4
+ syncify (0.1.4)
5
5
  active_interaction (~> 3.0)
6
6
  activerecord (~> 4.2)
7
7
  activerecord-import (~> 0.17)
data/README.md CHANGED
@@ -38,6 +38,19 @@ Syncify::Sync.run!(klass: Widget, id: 123, remote_database: :production)
38
38
 
39
39
  Boom! You've copied `Widget` 123 to local dev. The widget will have all the same values including its `id`, `created_at`, `updated_at`, etc values. The above example assumes that the `Widget` doesn't have any foreign keys that don't exist locally.
40
40
 
41
+ Syncify also accepts a `where` argument in the form of any valid active record `where` expression (a hash or a string). Here's the same as above, but with a `where`:
42
+
43
+ ```ruby
44
+ Syncify::Sync.run!(klass: Widget, where: { id: 123 }, remote_database: :production)
45
+ ```
46
+
47
+ Or...
48
+
49
+
50
+ ```ruby
51
+ Syncify::Sync.run!(klass: Widget, where: 'widgets.id = 123', remote_database: :production)
52
+ ```
53
+
41
54
  Now, let's say a `Widget` `belongs_to` a `Manufacturer`. Furthermore, let's say a `Manufacturer` `has_many` `Widget`s. We'll pretend we have this data in the prod database:
42
55
 
43
56
  `widgets`:
data/lib/syncify/sync.rb CHANGED
@@ -3,7 +3,8 @@
3
3
  module Syncify
4
4
  class Sync < ActiveInteraction::Base
5
5
  object :klass, class: Class
6
- integer :id
6
+ integer :id, default: nil
7
+ object :where, class: Object, default: nil
7
8
  object :association, class: Object, default: []
8
9
  object :callback, class: Proc, default: nil
9
10
 
@@ -11,12 +12,16 @@ module Syncify
11
12
 
12
13
  attr_accessor :identified_records
13
14
 
15
+ validate :id_xor_where_present?
16
+
14
17
  def execute
15
18
  puts 'Identifying records to sync...'
16
19
  @identified_records = Set[]
17
20
 
18
21
  remote do
19
- identify_associated_records(klass.find(id), normalized_associations(association))
22
+ initial_query.each do |root_record|
23
+ identify_associated_records(root_record, normalized_associations(association))
24
+ end
20
25
  end
21
26
 
22
27
  puts "Identified #{identified_records.size} records to sync."
@@ -28,6 +33,21 @@ module Syncify
28
33
 
29
34
  private
30
35
 
36
+ def initial_query
37
+ if id?
38
+ klass.where(id: id)
39
+ else
40
+ klass.where(where)
41
+ end
42
+ end
43
+
44
+ def id_xor_where_present?
45
+ unless id? ^ where?
46
+ errors.add(:id,
47
+ 'Please provide either the id argument or the where argument, but not both.')
48
+ end
49
+ end
50
+
31
51
  def print_status
32
52
  print "\rIdentified #{identified_records.size} records..."
33
53
  end
@@ -1,3 +1,3 @@
1
1
  module Syncify
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: syncify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Doug Hughes
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-08-17 00:00:00.000000000 Z
11
+ date: 2019-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler