syncify 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 +4 -4
- data/.gitignore +1 -0
- data/README.md +5 -5
- data/lib/syncify/sync.rb +1 -0
- data/lib/syncify/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 732f3fd3c050a56656ad4eb272412d59528dd0ef
|
4
|
+
data.tar.gz: 6e400731043ff844d4edb694ec68f7c354a68909
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5c78f9f3b5306c79acbd67a37809166d6f296eb79dbff0183c7a6ecdeca3f0106602e1b003ebf67591208b476d727f2ccac40ae98f414568a5ccde73ba212cb
|
7
|
+
data.tar.gz: 1c54d9823b93cb12d74d4b249222182f2b090c87c7cb83044b816aed3adc6c86fcaaf94f0d9601026f581e9a4a4b276e36928da1babaef7f52049d381824fd6d
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -72,7 +72,7 @@ Running the above example will copy two records into your local database:
|
|
72
72
|
* The `Widget` with id 123 (Lubricated Stainless Steel Helical Insert)
|
73
73
|
* The `Manufacturer` with id 78 (South Seas Trading Company)
|
74
74
|
|
75
|
-
It's important to note that
|
75
|
+
It's important to note that Syncify _does not_ recursively follow associations. You'll note that not all of the the manufacturer's widgets were synced, only the one we specified.
|
76
76
|
|
77
77
|
The `association` attribute passed into the `run!` method can be any valid value that you might use when joining records with ActiveRecord. The above effectively becomes:
|
78
78
|
|
@@ -116,7 +116,7 @@ You can really go wild with the associations; well beyond what you could normall
|
|
116
116
|
|
117
117
|
### Polymorphic Associations
|
118
118
|
|
119
|
-
Syncify also works with (and across) Polymorphic associations! To sync across polymorphic associations you need to specify an association using the `
|
119
|
+
Syncify also works with (and across) Polymorphic associations! To sync across polymorphic associations you need to specify an association using the `Syncify::PolymorphicAssociation` class. This is put in place in your otherwise-normal associations.
|
120
120
|
|
121
121
|
Let's imagine that we run an online store that sells both physical and digital goods. A given invoice then might have line items that refer to either type of good.
|
122
122
|
|
@@ -150,7 +150,7 @@ Here's an example. For simplicity's sake it assumes that the database doesn't us
|
|
150
150
|
```ruby
|
151
151
|
Syncify::Sync.run!(klass: Customer,
|
152
152
|
id: 999,
|
153
|
-
association:
|
153
|
+
association: Syncify::PolymorphicAssociation.new(
|
154
154
|
:product,
|
155
155
|
DigitalProduct => {},
|
156
156
|
PhysicalProduct => {}
|
@@ -160,7 +160,7 @@ Syncify::Sync.run!(klass: Customer,
|
|
160
160
|
|
161
161
|
Assuming that line item 42's product is a `DigitalProduct`, this example would have synced the `LineItem` and its `DigitalProduct` and nothing else.
|
162
162
|
|
163
|
-
The `
|
163
|
+
The `Syncify::PolymorphicAssociation` is saying that, for the `LineItem`'s `product` polymorphic association, when the product is a `DigitalProduct`, sync it with the specified associations (in this case none). When the product is a `PhysicalProduct`, sync it with the specified associations (again, none in this case).
|
164
164
|
|
165
165
|
Now let's say that we want to sync a specific `Customer` and all of their invoices and the related products. IE: the whole kit and caboodle. Here's how you can do it:
|
166
166
|
|
@@ -169,7 +169,7 @@ Syncify::Sync.run!(klass: Customer,
|
|
169
169
|
id: 999,
|
170
170
|
association: {
|
171
171
|
invoices: {
|
172
|
-
line_items:
|
172
|
+
line_items: Syncify::PolymorphicAssociation.new(
|
173
173
|
:product,
|
174
174
|
DigitalProduct => :category,
|
175
175
|
PhysicalProduct => :distributor
|
data/lib/syncify/sync.rb
CHANGED
data/lib/syncify/version.rb
CHANGED