motion/cdq/context.rb in cdq-1.0.1 vs motion/cdq/context.rb in cdq-1.0.2
- old
+ new
@@ -21,12 +21,14 @@
# return to the previous state.
#
def push(context, options = {}, &block)
@has_been_set_up = true
- unless context.is_a? NSManagedObjectContext
+ if !context.is_a?(NSManagedObjectContext)
context = create(context, options)
+ elsif options[:named]
+ assign_name(options[:named], context)
end
if block_given?
save_stack do
context = push_to_stack(context)
@@ -118,27 +120,21 @@
else
context.mergePolicy = NSMergePolicy.alloc.initWithMergeType(NSMergeByPropertyObjectTrumpMergePolicyType)
context.performBlockAndWait ->{
coordinator = @store_manager.current
context.persistentStoreCoordinator = coordinator
- #Dispatch::Queue.main.async {
+
NSNotificationCenter.defaultCenter.addObserver(self, selector:"did_finish_import:", name:NSPersistentStoreDidImportUbiquitousContentChangesNotification, object:nil)
@observed_context = context
- #}
}
end
else
context.parentContext = stack.last
end
if options[:named]
- if respond_to?(options[:named])
- raise "Cannot name a context '#{options[:named]}': conflicts with existing method"
- end
- self.class.send(:define_method, options[:named]) do
- context
- end
+ assign_name(options[:named], context)
end
context
end
# Save all passed contexts in order. If none are supplied, save all
@@ -275,9 +271,18 @@
}
end
private
+
+ def assign_name(name, context)
+ if respond_to?(name)
+ raise "Cannot name a context '#{name}': conflicts with existing method"
+ end
+ self.class.send(:define_method, name) do
+ context
+ end
+ end
def push_to_stack(value)
lstack = stack
lstack << value
self.stack = lstack