motion_data_wrapper 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
@@ -3,11 +3,8 @@ module MotionDataWrapper
|
|
3
3
|
|
4
4
|
def managedObjectContext
|
5
5
|
@managedObjectContext ||= begin
|
6
|
-
file_path = File.join App.documents_path, "#{sqlite_store_name}.sqlite"
|
7
|
-
storeURL = NSURL.fileURLWithPath(file_path)
|
8
|
-
|
9
6
|
error_ptr = Pointer.new(:object)
|
10
|
-
unless persistentStoreCoordinator.addPersistentStoreWithType(NSSQLiteStoreType, configuration:nil, URL:
|
7
|
+
unless persistentStoreCoordinator.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: sqlite_url, options: persistent_store_options, error: error_ptr)
|
11
8
|
raise "Can't add persistent SQLite store: #{error_ptr[0].description}"
|
12
9
|
end
|
13
10
|
|
@@ -44,6 +41,21 @@ module MotionDataWrapper
|
|
44
41
|
App.name
|
45
42
|
end
|
46
43
|
|
44
|
+
def sqlite_url
|
45
|
+
if Object.const_defined?("UIApplication")
|
46
|
+
file_path = File.join App.documents_path, "#{sqlite_store_name}.sqlite"
|
47
|
+
NSURL.fileURLWithPath(file_path)
|
48
|
+
else
|
49
|
+
error_ptr = Pointer.new(:object)
|
50
|
+
unless support_dir = NSFileManager.defaultManager.URLForDirectory(NSApplicationSupportDirectory, inDomain: NSUserDomainMask, appropriateForURL: nil, create: true, error: error_ptr)
|
51
|
+
raise "error creating application support folder: #{error_ptr[0]}"
|
52
|
+
end
|
53
|
+
support_dir = support_dir.URLByAppendingPathComponent("/#{App.name}")
|
54
|
+
Dir.mkdir(support_dir.path) unless Dir.exists?(support_dir.path)
|
55
|
+
support_dir.URLByAppendingPathComponent("#{sqlite_store_name}.sqlite")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
47
59
|
def persistent_store_options
|
48
60
|
{ NSMigratePersistentStoresAutomaticallyOption => true, NSInferMappingModelAutomaticallyOption => true }
|
49
61
|
end
|