Class: Mumukit::Sync::Syncer
- Inherits:
-
Object
- Object
- Mumukit::Sync::Syncer
- Defined in:
- lib/mumukit/sync/syncer.rb
Instance Method Summary collapse
- #export!(resource) ⇒ Object
- #import!(resource) ⇒ Object
- #import_all!(id_regex = nil) ⇒ Object
-
#initialize(store, inflators = [], resource_classifier = nil) ⇒ Syncer
constructor
A new instance of Syncer.
- #locate_and_export!(*args) ⇒ Object
- #locate_and_import!(*args) ⇒ Object
- #sync_keys_matching(id_regex = nil) ⇒ Object
Constructor Details
#initialize(store, inflators = [], resource_classifier = nil) ⇒ Syncer
Returns a new instance of Syncer.
12 13 14 15 16 |
# File 'lib/mumukit/sync/syncer.rb', line 12 def initialize(store, inflators = [], resource_classifier = nil) @store = store @inflators = inflators @resource_classifier ||= proc { |kind| Mumukit::Sync.constantize(kind) } end |
Instance Method Details
#export!(resource) ⇒ Object
48 49 50 51 |
# File 'lib/mumukit/sync/syncer.rb', line 48 def export!(resource) resource_h = resource.to_resource_h @store.write_resource!(resource.sync_key, resource_h) end |
#import!(resource) ⇒ Object
38 39 40 41 42 |
# File 'lib/mumukit/sync/syncer.rb', line 38 def import!(resource) resource_h = @store.read_resource(resource.sync_key) Mumukit::Sync::Inflator.inflate_with! resource.sync_key, resource_h, @inflators resource.import_from_resource_h!(resource_h) end |
#import_all!(id_regex = nil) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/mumukit/sync/syncer.rb', line 23 def import_all!(id_regex = nil) sync_keys_matching(id_regex).each do |key| puts "Importing #{key.kind} #{key.id}" begin locate_and_import! key rescue => e puts "Ignoring #{key.id} because of import error #{e}" end end end |
#locate_and_export!(*args) ⇒ Object
44 45 46 |
# File 'lib/mumukit/sync/syncer.rb', line 44 def locate_and_export!(*args) locate(key_for(*args)).tap { |it| export! it } end |
#locate_and_import!(*args) ⇒ Object
34 35 36 |
# File 'lib/mumukit/sync/syncer.rb', line 34 def locate_and_import!(*args) locate(key_for(*args)).tap { |it| import! it } end |
#sync_keys_matching(id_regex = nil) ⇒ Object
18 19 20 21 |
# File 'lib/mumukit/sync/syncer.rb', line 18 def sync_keys_matching(id_regex = nil) id_regex ||= /.*/ @store.sync_keys.select { |key| id_regex.matches? key.id } end |