Class: Ixtlan::Remote::Sync
- Inherits:
-
Object
- Object
- Ixtlan::Remote::Sync
- Defined in:
- lib/ixtlan/remote/sync.rb
Constant Summary collapse
- SECONDS_IN_DAY =
60 * 60 * 24
- NANOSECONDS_IN_DAY =
SECONDS_IN_DAY * 1000 * 1000 * 1000
Class Method Summary collapse
Instance Method Summary collapse
-
#do_it(set = clazzes.keys) ⇒ Object
load the last changed records.
-
#initialize(restserver) ⇒ Sync
constructor
A new instance of Sync.
- #register(clazz, &block) ⇒ Object
- #to_log ⇒ Object (also: #to_s)
Constructor Details
#initialize(restserver) ⇒ Sync
Returns a new instance of Sync.
29 30 31 |
# File 'lib/ixtlan/remote/sync.rb', line 29 def initialize(restserver) @restserver = restserver end |
Class Method Details
.do_it(clazz = nil) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/ixtlan/remote/sync.rb', line 61 def self.do_it( clazz = nil ) if clazz new.do_it( clazz ) else new.do_it end end |
Instance Method Details
#do_it(set = clazzes.keys) ⇒ Object
load the last changed records
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/ixtlan/remote/sync.rb', line 70 def do_it(set = clazzes.keys) @last_result = [] set = [set] unless set.is_a? Array # use only regstered classes !! set = set - (set - clazzes.keys) set.to_a.each do |clazz| summary = Summary.new(clazz) @last_result << summary @restserver.retrieve(clazz, :last_changes, :updated_at => last_update(clazz)).each do |item| if item.save summary.inc_count else summary.inc_failures(item.errors) end end b = clazzes[clazz] b.call summary if b end to_log end |
#register(clazz, &block) ⇒ Object
38 39 40 |
# File 'lib/ixtlan/remote/sync.rb', line 38 def register(clazz, &block) clazzes[clazz] = block unless clazzes.key?(clazz) end |
#to_log ⇒ Object Also known as: to_s
93 94 95 96 97 98 99 |
# File 'lib/ixtlan/remote/sync.rb', line 93 def to_log if @last_result @last_result.collect { |r| r.to_log }.join("\n\t") else "no results yet" end end |