motion_data_wrapper 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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:storeURL, options:persistent_store_options, error:error_ptr)
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
@@ -1,3 +1,3 @@
1
1
  module MotionDataWrapper
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: motion_data_wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: