Module: NdSync::Remote::ClassMethods
- Defined in:
- lib/nd_sync/remote.rb
Instance Method Summary collapse
- #post_batch(locals) ⇒ Object
- #receive(locals) ⇒ Object
- #to_batch(collection) ⇒ Object
- #to_transmit ⇒ Object
Instance Method Details
#post_batch(locals) ⇒ Object
26 27 28 |
# File 'lib/nd_sync/remote.rb', line 26 def post_batch(locals) post(:batch, {}, to_batch(transcribe_all(locals))) end |
#receive(locals) ⇒ Object
20 21 22 23 24 |
# File 'lib/nd_sync/remote.rb', line 20 def receive(locals) JSON.parse(post_batch(locals).body).each_with_index do |remote_hash, idx| locals[idx].transmitted_to new(remote_hash) end end |
#to_batch(collection) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/nd_sync/remote.rb', line 30 def to_batch(collection) Jbuilder.encode do |json| json.set! collection_name do json.array! collection do |item| item.to_batch json end end end end |
#to_transmit ⇒ Object
16 17 18 |
# File 'lib/nd_sync/remote.rb', line 16 def to_transmit find(:all, params: { sync_pending: true }).to_a end |