motion-yapper 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (348) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +20 -0
  3. data/.travis.yml +6 -0
  4. data/Gemfile +5 -0
  5. data/Gemfile.lock +63 -0
  6. data/README.md +16 -0
  7. data/Rakefile +20 -0
  8. data/app/app_delegate.rb +5 -0
  9. data/lib/yapper.rb +30 -0
  10. data/lib/yapper/attachment.rb +48 -0
  11. data/lib/yapper/bson.rb +20 -0
  12. data/lib/yapper/config.rb +18 -0
  13. data/lib/yapper/db.rb +151 -0
  14. data/lib/yapper/document.rb +54 -0
  15. data/lib/yapper/document/attachment.rb +26 -0
  16. data/lib/yapper/document/callbacks.rb +86 -0
  17. data/lib/yapper/document/persistance.rb +171 -0
  18. data/lib/yapper/document/relation.rb +84 -0
  19. data/lib/yapper/document/selection.rb +100 -0
  20. data/lib/yapper/extensions.rb +80 -0
  21. data/lib/yapper/log.rb +5 -0
  22. data/lib/yapper/sync.rb +134 -0
  23. data/lib/yapper/sync/data.rb +12 -0
  24. data/lib/yapper/sync/event.rb +194 -0
  25. data/lib/yapper/sync/queue.rb +164 -0
  26. data/lib/yapper/timestamps.rb +16 -0
  27. data/lib/yapper/version.rb +3 -0
  28. data/lib/yapper/yapper.rb +2 -0
  29. data/spec/helpers/time_helper.rb +3 -0
  30. data/spec/integration/all_spec.rb +40 -0
  31. data/spec/integration/callback_spec.rb +87 -0
  32. data/spec/integration/db_spec.rb +40 -0
  33. data/spec/integration/find_spec.rb +51 -0
  34. data/spec/integration/persistance_spec.rb +118 -0
  35. data/spec/integration/relation_spec.rb +174 -0
  36. data/spec/integration/sync_spec.rb +42 -0
  37. data/spec/integration/timestamps_spec.rb +34 -0
  38. data/spec/integration/types_spec.rb +23 -0
  39. data/spec/integration/when_spec.rb +29 -0
  40. data/spec/integration/where_spec.rb +132 -0
  41. data/vendor/Podfile.lock +24 -0
  42. data/vendor/Pods/AFNetworking/AFNetworking/AFHTTPClient.h +641 -0
  43. data/vendor/Pods/AFNetworking/AFNetworking/AFHTTPClient.m +1396 -0
  44. data/vendor/Pods/AFNetworking/AFNetworking/AFHTTPRequestOperation.h +133 -0
  45. data/vendor/Pods/AFNetworking/AFNetworking/AFHTTPRequestOperation.m +327 -0
  46. data/vendor/Pods/AFNetworking/AFNetworking/AFImageRequestOperation.h +113 -0
  47. data/vendor/Pods/AFNetworking/AFNetworking/AFImageRequestOperation.m +321 -0
  48. data/vendor/Pods/AFNetworking/AFNetworking/AFJSONRequestOperation.h +71 -0
  49. data/vendor/Pods/AFNetworking/AFNetworking/AFJSONRequestOperation.m +150 -0
  50. data/vendor/Pods/AFNetworking/AFNetworking/AFNetworkActivityIndicatorManager.h +75 -0
  51. data/vendor/Pods/AFNetworking/AFNetworking/AFNetworkActivityIndicatorManager.m +157 -0
  52. data/vendor/Pods/AFNetworking/AFNetworking/AFNetworking.h +43 -0
  53. data/vendor/Pods/AFNetworking/AFNetworking/AFPropertyListRequestOperation.h +68 -0
  54. data/vendor/Pods/AFNetworking/AFNetworking/AFPropertyListRequestOperation.m +143 -0
  55. data/vendor/Pods/AFNetworking/AFNetworking/AFURLConnectionOperation.h +370 -0
  56. data/vendor/Pods/AFNetworking/AFNetworking/AFURLConnectionOperation.m +848 -0
  57. data/vendor/Pods/AFNetworking/AFNetworking/AFXMLRequestOperation.h +89 -0
  58. data/vendor/Pods/AFNetworking/AFNetworking/AFXMLRequestOperation.m +167 -0
  59. data/vendor/Pods/AFNetworking/AFNetworking/UIImageView+AFNetworking.h +78 -0
  60. data/vendor/Pods/AFNetworking/AFNetworking/UIImageView+AFNetworking.m +191 -0
  61. data/vendor/Pods/AFNetworking/LICENSE +19 -0
  62. data/vendor/Pods/AFNetworking/README.md +208 -0
  63. data/vendor/Pods/BuildHeaders/AFNetworking/AFHTTPClient.h +641 -0
  64. data/vendor/Pods/BuildHeaders/AFNetworking/AFHTTPRequestOperation.h +133 -0
  65. data/vendor/Pods/BuildHeaders/AFNetworking/AFImageRequestOperation.h +113 -0
  66. data/vendor/Pods/BuildHeaders/AFNetworking/AFJSONRequestOperation.h +71 -0
  67. data/vendor/Pods/BuildHeaders/AFNetworking/AFNetworkActivityIndicatorManager.h +75 -0
  68. data/vendor/Pods/BuildHeaders/AFNetworking/AFNetworking.h +43 -0
  69. data/vendor/Pods/BuildHeaders/AFNetworking/AFPropertyListRequestOperation.h +68 -0
  70. data/vendor/Pods/BuildHeaders/AFNetworking/AFURLConnectionOperation.h +370 -0
  71. data/vendor/Pods/BuildHeaders/AFNetworking/AFXMLRequestOperation.h +89 -0
  72. data/vendor/Pods/BuildHeaders/AFNetworking/UIImageView+AFNetworking.h +78 -0
  73. data/vendor/Pods/BuildHeaders/CocoaLumberjack/ContextFilterLogFormatter.h +65 -0
  74. data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDASLLogger.h +41 -0
  75. data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDAbstractDatabaseLogger.h +102 -0
  76. data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDFileLogger.h +334 -0
  77. data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDLog.h +601 -0
  78. data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDTTYLogger.h +167 -0
  79. data/vendor/Pods/BuildHeaders/CocoaLumberjack/DispatchQueueLogFormatter.h +116 -0
  80. data/vendor/Pods/BuildHeaders/NSData+MD5Digest/NSData+MD5Digest.h +18 -0
  81. data/vendor/Pods/BuildHeaders/Reachability/Reachability.h +109 -0
  82. data/vendor/Pods/BuildHeaders/YapDatabase/YapCache.h +90 -0
  83. data/vendor/Pods/BuildHeaders/YapDatabase/YapCollectionKey.h +20 -0
  84. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabase.h +547 -0
  85. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseConnection.h +447 -0
  86. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseConnectionState.h +29 -0
  87. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseDefaults.h +37 -0
  88. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseExtension.h +15 -0
  89. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseExtensionConnection.h +11 -0
  90. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseExtensionPrivate.h +440 -0
  91. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseExtensionTransaction.h +11 -0
  92. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFilteredView.h +108 -0
  93. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFilteredViewConnection.h +12 -0
  94. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFilteredViewPrivate.h +19 -0
  95. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFilteredViewTransaction.h +39 -0
  96. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFullTextSearch.h +89 -0
  97. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFullTextSearchConnection.h +32 -0
  98. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFullTextSearchPrivate.h +69 -0
  99. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFullTextSearchSnippetOptions.h +79 -0
  100. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFullTextSearchTransaction.h +68 -0
  101. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseLogging.h +158 -0
  102. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseManager.h +17 -0
  103. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabasePrivate.h +424 -0
  104. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseQuery.h +42 -0
  105. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseSecondaryIndex.h +100 -0
  106. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseSecondaryIndexConnection.h +33 -0
  107. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseSecondaryIndexPrivate.h +73 -0
  108. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseSecondaryIndexSetup.h +33 -0
  109. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseSecondaryIndexTransaction.h +58 -0
  110. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseStatement.h +13 -0
  111. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseString.h +121 -0
  112. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseTransaction.h +541 -0
  113. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseView.h +186 -0
  114. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewChange.h +272 -0
  115. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewChangePrivate.h +94 -0
  116. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewConnection.h +115 -0
  117. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewMappings.h +825 -0
  118. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewMappingsPrivate.h +72 -0
  119. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewOptions.h +56 -0
  120. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewPage.h +36 -0
  121. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewPageMetadata.h +27 -0
  122. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewPrivate.h +153 -0
  123. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewRangeOptions.h +330 -0
  124. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewRangeOptionsPrivate.h +17 -0
  125. data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewTransaction.h +447 -0
  126. data/vendor/Pods/BuildHeaders/YapDatabase/YapMemoryTable.h +74 -0
  127. data/vendor/Pods/BuildHeaders/YapDatabase/YapNull.h +17 -0
  128. data/vendor/Pods/BuildHeaders/YapDatabase/YapSet.h +41 -0
  129. data/vendor/Pods/BuildHeaders/YapDatabase/YapTouch.h +15 -0
  130. data/vendor/Pods/CocoaLumberjack/LICENSE.txt +18 -0
  131. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDASLLogger.h +41 -0
  132. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDASLLogger.m +99 -0
  133. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDAbstractDatabaseLogger.h +102 -0
  134. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDAbstractDatabaseLogger.m +727 -0
  135. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDFileLogger.h +334 -0
  136. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDFileLogger.m +1353 -0
  137. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDLog.h +601 -0
  138. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDLog.m +1083 -0
  139. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDTTYLogger.h +167 -0
  140. data/vendor/Pods/CocoaLumberjack/Lumberjack/DDTTYLogger.m +1479 -0
  141. data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/ContextFilterLogFormatter.h +65 -0
  142. data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/ContextFilterLogFormatter.m +191 -0
  143. data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/DispatchQueueLogFormatter.h +116 -0
  144. data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/DispatchQueueLogFormatter.m +251 -0
  145. data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/README.txt +7 -0
  146. data/vendor/Pods/CocoaLumberjack/README.markdown +37 -0
  147. data/vendor/Pods/Headers/AFNetworking/AFHTTPClient.h +641 -0
  148. data/vendor/Pods/Headers/AFNetworking/AFHTTPRequestOperation.h +133 -0
  149. data/vendor/Pods/Headers/AFNetworking/AFImageRequestOperation.h +113 -0
  150. data/vendor/Pods/Headers/AFNetworking/AFJSONRequestOperation.h +71 -0
  151. data/vendor/Pods/Headers/AFNetworking/AFNetworkActivityIndicatorManager.h +75 -0
  152. data/vendor/Pods/Headers/AFNetworking/AFNetworking.h +43 -0
  153. data/vendor/Pods/Headers/AFNetworking/AFPropertyListRequestOperation.h +68 -0
  154. data/vendor/Pods/Headers/AFNetworking/AFURLConnectionOperation.h +370 -0
  155. data/vendor/Pods/Headers/AFNetworking/AFXMLRequestOperation.h +89 -0
  156. data/vendor/Pods/Headers/AFNetworking/UIImageView+AFNetworking.h +78 -0
  157. data/vendor/Pods/Headers/CocoaLumberjack/ContextFilterLogFormatter.h +65 -0
  158. data/vendor/Pods/Headers/CocoaLumberjack/DDASLLogger.h +41 -0
  159. data/vendor/Pods/Headers/CocoaLumberjack/DDAbstractDatabaseLogger.h +102 -0
  160. data/vendor/Pods/Headers/CocoaLumberjack/DDFileLogger.h +334 -0
  161. data/vendor/Pods/Headers/CocoaLumberjack/DDLog.h +601 -0
  162. data/vendor/Pods/Headers/CocoaLumberjack/DDTTYLogger.h +167 -0
  163. data/vendor/Pods/Headers/CocoaLumberjack/DispatchQueueLogFormatter.h +116 -0
  164. data/vendor/Pods/Headers/NSData+MD5Digest/NSData+MD5Digest.h +18 -0
  165. data/vendor/Pods/Headers/Reachability/Reachability.h +109 -0
  166. data/vendor/Pods/Headers/YapDatabase/YapCache.h +90 -0
  167. data/vendor/Pods/Headers/YapDatabase/YapCollectionKey.h +20 -0
  168. data/vendor/Pods/Headers/YapDatabase/YapDatabase.h +547 -0
  169. data/vendor/Pods/Headers/YapDatabase/YapDatabaseConnection.h +447 -0
  170. data/vendor/Pods/Headers/YapDatabase/YapDatabaseConnectionState.h +29 -0
  171. data/vendor/Pods/Headers/YapDatabase/YapDatabaseDefaults.h +37 -0
  172. data/vendor/Pods/Headers/YapDatabase/YapDatabaseExtension.h +15 -0
  173. data/vendor/Pods/Headers/YapDatabase/YapDatabaseExtensionConnection.h +11 -0
  174. data/vendor/Pods/Headers/YapDatabase/YapDatabaseExtensionPrivate.h +440 -0
  175. data/vendor/Pods/Headers/YapDatabase/YapDatabaseExtensionTransaction.h +11 -0
  176. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFilteredView.h +108 -0
  177. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFilteredViewConnection.h +12 -0
  178. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFilteredViewPrivate.h +19 -0
  179. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFilteredViewTransaction.h +39 -0
  180. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFullTextSearch.h +89 -0
  181. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFullTextSearchConnection.h +32 -0
  182. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFullTextSearchPrivate.h +69 -0
  183. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFullTextSearchSnippetOptions.h +79 -0
  184. data/vendor/Pods/Headers/YapDatabase/YapDatabaseFullTextSearchTransaction.h +68 -0
  185. data/vendor/Pods/Headers/YapDatabase/YapDatabaseLogging.h +158 -0
  186. data/vendor/Pods/Headers/YapDatabase/YapDatabaseManager.h +17 -0
  187. data/vendor/Pods/Headers/YapDatabase/YapDatabasePrivate.h +424 -0
  188. data/vendor/Pods/Headers/YapDatabase/YapDatabaseQuery.h +42 -0
  189. data/vendor/Pods/Headers/YapDatabase/YapDatabaseSecondaryIndex.h +100 -0
  190. data/vendor/Pods/Headers/YapDatabase/YapDatabaseSecondaryIndexConnection.h +33 -0
  191. data/vendor/Pods/Headers/YapDatabase/YapDatabaseSecondaryIndexPrivate.h +73 -0
  192. data/vendor/Pods/Headers/YapDatabase/YapDatabaseSecondaryIndexSetup.h +33 -0
  193. data/vendor/Pods/Headers/YapDatabase/YapDatabaseSecondaryIndexTransaction.h +58 -0
  194. data/vendor/Pods/Headers/YapDatabase/YapDatabaseStatement.h +13 -0
  195. data/vendor/Pods/Headers/YapDatabase/YapDatabaseString.h +121 -0
  196. data/vendor/Pods/Headers/YapDatabase/YapDatabaseTransaction.h +541 -0
  197. data/vendor/Pods/Headers/YapDatabase/YapDatabaseView.h +186 -0
  198. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewChange.h +272 -0
  199. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewChangePrivate.h +94 -0
  200. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewConnection.h +115 -0
  201. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewMappings.h +825 -0
  202. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewMappingsPrivate.h +72 -0
  203. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewOptions.h +56 -0
  204. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewPage.h +36 -0
  205. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewPageMetadata.h +27 -0
  206. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewPrivate.h +153 -0
  207. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewRangeOptions.h +330 -0
  208. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewRangeOptionsPrivate.h +17 -0
  209. data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewTransaction.h +447 -0
  210. data/vendor/Pods/Headers/YapDatabase/YapMemoryTable.h +74 -0
  211. data/vendor/Pods/Headers/YapDatabase/YapNull.h +17 -0
  212. data/vendor/Pods/Headers/YapDatabase/YapSet.h +41 -0
  213. data/vendor/Pods/Headers/YapDatabase/YapTouch.h +15 -0
  214. data/vendor/Pods/Headers/____Pods-AFNetworking-prefix.h +17 -0
  215. data/vendor/Pods/Headers/____Pods-CocoaLumberjack-prefix.h +5 -0
  216. data/vendor/Pods/Headers/____Pods-NSData+MD5Digest-prefix.h +5 -0
  217. data/vendor/Pods/Headers/____Pods-Reachability-prefix.h +5 -0
  218. data/vendor/Pods/Headers/____Pods-YapDatabase-prefix.h +5 -0
  219. data/vendor/Pods/Headers/____Pods-environment.h +38 -0
  220. data/vendor/Pods/Manifest.lock +24 -0
  221. data/vendor/Pods/NSData+MD5Digest/NSData+MD5Digest/NSData+MD5Digest.h +18 -0
  222. data/vendor/Pods/NSData+MD5Digest/NSData+MD5Digest/NSData+MD5Digest.m +39 -0
  223. data/vendor/Pods/NSData+MD5Digest/README.md +11 -0
  224. data/vendor/Pods/Pods-AFNetworking-Private.xcconfig +5 -0
  225. data/vendor/Pods/Pods-AFNetworking-dummy.m +5 -0
  226. data/vendor/Pods/Pods-AFNetworking-prefix.pch +17 -0
  227. data/vendor/Pods/Pods-AFNetworking.xcconfig +1 -0
  228. data/vendor/Pods/Pods-Acknowledgements.markdown +96 -0
  229. data/vendor/Pods/Pods-Acknowledgements.plist +142 -0
  230. data/vendor/Pods/Pods-CocoaLumberjack-Private.xcconfig +5 -0
  231. data/vendor/Pods/Pods-CocoaLumberjack-dummy.m +5 -0
  232. data/vendor/Pods/Pods-CocoaLumberjack-prefix.pch +5 -0
  233. data/vendor/Pods/Pods-CocoaLumberjack.xcconfig +0 -0
  234. data/vendor/Pods/Pods-NSData+MD5Digest-Private.xcconfig +5 -0
  235. data/vendor/Pods/Pods-NSData+MD5Digest-dummy.m +5 -0
  236. data/vendor/Pods/Pods-NSData+MD5Digest-prefix.pch +5 -0
  237. data/vendor/Pods/Pods-NSData+MD5Digest.xcconfig +0 -0
  238. data/vendor/Pods/Pods-Reachability-Private.xcconfig +5 -0
  239. data/vendor/Pods/Pods-Reachability-dummy.m +5 -0
  240. data/vendor/Pods/Pods-Reachability-prefix.pch +5 -0
  241. data/vendor/Pods/Pods-Reachability.xcconfig +1 -0
  242. data/vendor/Pods/Pods-YapDatabase-Private.xcconfig +5 -0
  243. data/vendor/Pods/Pods-YapDatabase-dummy.m +5 -0
  244. data/vendor/Pods/Pods-YapDatabase-prefix.pch +5 -0
  245. data/vendor/Pods/Pods-YapDatabase.xcconfig +1 -0
  246. data/vendor/Pods/Pods-dummy.m +5 -0
  247. data/vendor/Pods/Pods-environment.h +38 -0
  248. data/vendor/Pods/Pods-resources.sh +68 -0
  249. data/vendor/Pods/Pods.bridgesupport +5096 -0
  250. data/vendor/Pods/Pods.xcconfig +5 -0
  251. data/vendor/Pods/Pods.xcodeproj/project.pbxproj +5536 -0
  252. data/vendor/Pods/Reachability/LICENCE.txt +24 -0
  253. data/vendor/Pods/Reachability/README.md +65 -0
  254. data/vendor/Pods/Reachability/Reachability.h +109 -0
  255. data/vendor/Pods/Reachability/Reachability.m +527 -0
  256. data/vendor/Pods/YapDatabase/LICENSE.txt +18 -0
  257. data/vendor/Pods/YapDatabase/README.md +30 -0
  258. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/Internal/YapDatabaseFilteredViewPrivate.h +19 -0
  259. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredView.h +108 -0
  260. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredView.m +175 -0
  261. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredViewConnection.h +12 -0
  262. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredViewConnection.m +41 -0
  263. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredViewTransaction.h +39 -0
  264. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredViewTransaction.m +966 -0
  265. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/Internal/YapDatabaseFullTextSearchPrivate.h +69 -0
  266. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearch.h +89 -0
  267. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearch.m +146 -0
  268. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearchConnection.h +32 -0
  269. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearchConnection.m +298 -0
  270. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearchSnippetOptions.h +79 -0
  271. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearchSnippetOptions.m +95 -0
  272. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearchTransaction.h +68 -0
  273. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearchTransaction.m +1352 -0
  274. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/Internal/YapDatabaseExtensionPrivate.h +440 -0
  275. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/YapDatabaseExtension.h +15 -0
  276. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/YapDatabaseExtension.m +58 -0
  277. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/YapDatabaseExtensionConnection.h +11 -0
  278. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/YapDatabaseExtensionConnection.m +46 -0
  279. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/YapDatabaseExtensionTransaction.h +11 -0
  280. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/YapDatabaseExtensionTransaction.m +180 -0
  281. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/Internal/YapDatabaseSecondaryIndexPrivate.h +73 -0
  282. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndex.h +100 -0
  283. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndex.m +149 -0
  284. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndexConnection.h +33 -0
  285. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndexConnection.m +330 -0
  286. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndexSetup.h +33 -0
  287. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndexSetup.m +184 -0
  288. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndexTransaction.h +58 -0
  289. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndexTransaction.m +1166 -0
  290. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewChangePrivate.h +94 -0
  291. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewMappingsPrivate.h +72 -0
  292. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewPage.h +36 -0
  293. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewPage.mm +296 -0
  294. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewPageMetadata.h +27 -0
  295. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewPageMetadata.m +28 -0
  296. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewPrivate.h +153 -0
  297. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewRangeOptionsPrivate.h +17 -0
  298. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Utilities/YapDatabaseViewChange.h +272 -0
  299. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Utilities/YapDatabaseViewChange.m +2494 -0
  300. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Utilities/YapDatabaseViewMappings.h +825 -0
  301. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Utilities/YapDatabaseViewMappings.m +1567 -0
  302. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Utilities/YapDatabaseViewRangeOptions.h +330 -0
  303. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Utilities/YapDatabaseViewRangeOptions.m +141 -0
  304. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseView.h +186 -0
  305. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseView.m +191 -0
  306. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewConnection.h +115 -0
  307. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewConnection.m +897 -0
  308. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewOptions.h +56 -0
  309. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewOptions.m +27 -0
  310. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewTransaction.h +447 -0
  311. data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewTransaction.m +4505 -0
  312. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapCache.h +90 -0
  313. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapCache.m +453 -0
  314. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseConnectionState.h +29 -0
  315. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseConnectionState.m +48 -0
  316. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseDefaults.h +37 -0
  317. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseDefaults.m +83 -0
  318. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseLogging.h +158 -0
  319. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseLogging.m +73 -0
  320. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseManager.h +17 -0
  321. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseManager.m +56 -0
  322. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabasePrivate.h +424 -0
  323. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseStatement.h +13 -0
  324. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseStatement.m +26 -0
  325. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseString.h +121 -0
  326. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapMemoryTable.h +74 -0
  327. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapMemoryTable.m +603 -0
  328. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapNull.h +17 -0
  329. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapNull.m +31 -0
  330. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapTouch.h +15 -0
  331. data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapTouch.m +31 -0
  332. data/vendor/Pods/YapDatabase/YapDatabase/Utilities/YapCollectionKey.h +20 -0
  333. data/vendor/Pods/YapDatabase/YapDatabase/Utilities/YapCollectionKey.m +194 -0
  334. data/vendor/Pods/YapDatabase/YapDatabase/Utilities/YapDatabaseQuery.h +42 -0
  335. data/vendor/Pods/YapDatabase/YapDatabase/Utilities/YapDatabaseQuery.m +96 -0
  336. data/vendor/Pods/YapDatabase/YapDatabase/Utilities/YapSet.h +41 -0
  337. data/vendor/Pods/YapDatabase/YapDatabase/Utilities/YapSet.m +82 -0
  338. data/vendor/Pods/YapDatabase/YapDatabase/YapDatabase.h +547 -0
  339. data/vendor/Pods/YapDatabase/YapDatabase/YapDatabase.m +2022 -0
  340. data/vendor/Pods/YapDatabase/YapDatabase/YapDatabaseConnection.h +447 -0
  341. data/vendor/Pods/YapDatabase/YapDatabase/YapDatabaseConnection.m +3874 -0
  342. data/vendor/Pods/YapDatabase/YapDatabase/YapDatabaseTransaction.h +541 -0
  343. data/vendor/Pods/YapDatabase/YapDatabase/YapDatabaseTransaction.m +5282 -0
  344. data/vendor/YapDatabaseRubyMotion/YapDatabaseRubyMotion.bridgesupport +16 -0
  345. data/vendor/YapDatabaseRubyMotion/YapDatabaseRubyMotion.h +13 -0
  346. data/vendor/YapDatabaseRubyMotion/YapDatabaseRubyMotion.m +20 -0
  347. data/yapper.gemspec +24 -0
  348. metadata +458 -0
@@ -0,0 +1,13 @@
1
+ #import <Foundation/Foundation.h>
2
+ #import "sqlite3.h"
3
+
4
+ /**
5
+ * Simple wrapper class to facilitate storing sqlite3_stmt items as objects (primarily in YapCache).
6
+ **/
7
+ @interface YapDatabaseStatement : NSObject
8
+
9
+ - (id)initWithStatement:(sqlite3_stmt *)stmt;
10
+
11
+ @property (nonatomic, assign, readonly) sqlite3_stmt *stmt;
12
+
13
+ @end
@@ -0,0 +1,26 @@
1
+ #import "YapDatabaseStatement.h"
2
+ #import "YapDatabasePrivate.h"
3
+
4
+
5
+ @implementation YapDatabaseStatement
6
+ {
7
+ sqlite3_stmt *stmt;
8
+ }
9
+
10
+ @synthesize stmt = stmt;
11
+
12
+ - (id)initWithStatement:(sqlite3_stmt *)inStmt
13
+ {
14
+ if ((self = [super init]))
15
+ {
16
+ stmt = inStmt;
17
+ }
18
+ return self;
19
+ }
20
+
21
+ - (void)dealloc
22
+ {
23
+ sqlite_finalize_null(&stmt);
24
+ }
25
+
26
+ @end
@@ -0,0 +1,121 @@
1
+ /**
2
+ * There are a LOT of conversions from NSString to char array.
3
+ * This happens in almost every method, where we bind text to prepared sqlite3 statements.
4
+ *
5
+ * It is inefficient to use [key UTF8String] for these situations.
6
+ * The Apple documentation is very explicit concerning the UTF8String method:
7
+ *
8
+ * > The returned C string is automatically freed just as a returned object would be released;
9
+ * > you should copy the C string if [you need] to store it outside of the
10
+ * > autorelease context in which the C string is created.
11
+ *
12
+ * In other words, the UTF8String method does a malloc for character buffer, copies the characters,
13
+ * and autoreleases the buffer (just like an autoreleased NSData instance).
14
+ *
15
+ * Thus we suffer a bunch of malloc's if we use UTF8String.
16
+ *
17
+ * Considering that almost all keys are likely to be relatively small,
18
+ * a much faster technique is to use the stack instead of the heap (with obvious precautions, see below).
19
+ *
20
+ * Note: This technique ONLY applies to key names and collection names.
21
+ * It does NOT apply to object/primitiveData or metadata. Those are binded to sqlite3 statements using binary blobs.
22
+ **/
23
+
24
+
25
+ /**
26
+ * We must be cautious and conservative so as to avoid stack overflow.
27
+ * This is possibe if really huge key names or collection names are used.
28
+ *
29
+ * The number below represents the largest amount of memory (in bytes) that will be allocated on the stack per string.
30
+ **/
31
+ #define YapDatabaseStringMaxStackLength (1024 * 4)
32
+
33
+ /**
34
+ * Struct designed to be allocated on the stack.
35
+ * You then use the inline functions below to "setup" and "teardown" the struct.
36
+ * For example:
37
+ *
38
+ * > YapDatabaseString myKeyChar;
39
+ * > MakeYapDatabaseString(&myKeyChar, myNSStringKey);
40
+ * > ...
41
+ * > sqlite3_bind_text(statement, position, myKeyChar.str, myKeyChar.length, SQLITE_STATIC);
42
+ * > ...
43
+ * > sqlite3_clear_bindings(statement);
44
+ * > sqlite3_reset(statement);
45
+ * > FreeYapDatabaseString(&myKeyChar);
46
+ *
47
+ * There are 2 "public" fields:
48
+ * str - Pointer to the char[] string.
49
+ * length - Represents the length (in bytes) of the char[] str (excluding the NULL termination byte, as usual).
50
+ *
51
+ * The other 2 "private" fields are for internal use:
52
+ * strStack - If the string doesn't exceed YapDatabaseStringMaxStackLength,
53
+ * then the bytes are copied here (onto stack storage), and str actually points to strStack.
54
+ * strHeap - If the string exceeds YapDatabaseStringMaxStackLength,
55
+ * the space is allocated on the heap, strHeap holds the pointer, and str has the same pointer.
56
+ *
57
+ * Thus the "setup" and "teardown" methods below will automatically switch to heap storage (just like UTF8String),
58
+ * if the key/collection name is too long, and performance will be equivalent.
59
+ * But in the common case of short key/collection names, we can skip the more expensive heap allocation/deallocation.
60
+ **/
61
+ struct YapDatabaseString {
62
+ int length;
63
+ char strStack[YapDatabaseStringMaxStackLength];
64
+ char *strHeap;
65
+ char *str; // Pointer to either strStack or strHeap
66
+ };
67
+ typedef struct YapDatabaseString YapDatabaseString;
68
+
69
+ /**
70
+ * Initializes the YapDatabaseString structure.
71
+ * It will automatically use heap storage if the given NSString is too long.
72
+ *
73
+ * This method should always be balanced with a call to FreeYapDatabaseString.
74
+ **/
75
+ NS_INLINE void MakeYapDatabaseString(YapDatabaseString *dbStr, NSString *nsStr)
76
+ {
77
+ if (nsStr)
78
+ {
79
+ // We convert to int because the sqlite3_bind_text() function expects an int parameter.
80
+ // So we can change it to int here, or we can cast everywhere throughout the project.
81
+
82
+ dbStr->length = (int)[nsStr lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
83
+
84
+ if ((dbStr->length + 1) <= YapDatabaseStringMaxStackLength)
85
+ {
86
+ dbStr->strHeap = NULL;
87
+ dbStr->str = dbStr->strStack;
88
+ }
89
+ else
90
+ {
91
+ dbStr->strHeap = (char *)malloc((dbStr->length + 1));
92
+ dbStr->str = dbStr->strHeap;
93
+ }
94
+
95
+ [nsStr getCString:dbStr->str maxLength:(dbStr->length + 1) encoding:NSUTF8StringEncoding];
96
+ }
97
+ else
98
+ {
99
+ dbStr->length = 0;
100
+ dbStr->strHeap = NULL;
101
+ dbStr->str = NULL;
102
+ }
103
+ }
104
+
105
+ /**
106
+ * If heap storage was needed (because the string length exceeded YapDatabaseStringMaxStackLength),
107
+ * this method frees the heap allocated memory.
108
+ *
109
+ * In the common case of stack storage, strHeap will be NULL, and this method is essentially a no-op.
110
+ *
111
+ * This method should be invoked AFTER sqlite3_clear_bindings (assuming SQLITE_STATIC is used).
112
+ **/
113
+ NS_INLINE void FreeYapDatabaseString(YapDatabaseString *dbStr)
114
+ {
115
+ if (dbStr->strHeap)
116
+ {
117
+ free(dbStr->strHeap);
118
+ dbStr->strHeap = NULL;
119
+ dbStr->str = NULL;
120
+ }
121
+ }
@@ -0,0 +1,74 @@
1
+ #import <Foundation/Foundation.h>
2
+
3
+ @class YapMemoryTableTransaction;
4
+
5
+
6
+ /**
7
+ * A "memory table" is a dictionary that supports versioning.
8
+ * There may be multiple values for a single key, with each value associated with a different snapshot.
9
+ *
10
+ * The memory table is accessed via a YapMemoryTableTransaction instance,
11
+ * which is itself associated with a particular timestamp. Thus the transaction is able to properly identify
12
+ * which version is appropriate for itself.
13
+ **/
14
+ @interface YapMemoryTable : NSObject
15
+
16
+ /**
17
+ * Initializes a memory table.
18
+ *
19
+ * The keyClass is used for debugging, to ensure the proper key type is always used when accessing the table.
20
+ * The keyClass is used within NSAssert statements that typically get compiled out for release builds.
21
+ **/
22
+ - (id)initWithKeyClass:(Class)keyClass;
23
+
24
+ /**
25
+ * Creates and returns a new connection associated with the shared cache.
26
+ **/
27
+ - (YapMemoryTableTransaction *)newReadTransactionWithSnapshot:(uint64_t)snapshot;
28
+ - (YapMemoryTableTransaction *)newReadWriteTransactionWithSnapshot:(uint64_t)snapshot;
29
+
30
+ /**
31
+ * Invoked automatically by YapDatabase architecture.
32
+ **/
33
+ - (void)asyncCheckpoint:(int64_t)minSnapshot;
34
+
35
+ @end
36
+
37
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
38
+ #pragma mark -
39
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
40
+
41
+ @interface YapMemoryTableTransaction : NSObject
42
+
43
+ @property (nonatomic, readonly) uint64_t snapshot;
44
+ @property (nonatomic, readonly) BOOL isReadWriteTransaction;
45
+
46
+ - (id)objectForKey:(id)key;
47
+
48
+ - (void)enumerateKeysWithBlock:(void (^)(id key, BOOL *stop))block;
49
+
50
+ - (void)enumerateKeysAndObjectsWithBlock:(void (^)(id key, id obj, BOOL *stop))block;
51
+
52
+ //
53
+ // For ReadWrite transactions:
54
+
55
+ - (void)setObject:(id)object forKey:(id)key;
56
+
57
+ - (void)removeObjectForKey:(id)key;
58
+ - (void)removeObjectsForKeys:(NSArray *)keys;
59
+
60
+ - (void)removeAllObjects;
61
+
62
+ //
63
+ // Batch access / modifications
64
+
65
+ - (void)accessWithBlock:(dispatch_block_t)block;
66
+ - (void)modifyWithBlock:(dispatch_block_t)block;
67
+
68
+ //
69
+ // Transaction state
70
+
71
+ - (void)commit;
72
+ - (void)rollback;
73
+
74
+ @end
@@ -0,0 +1,603 @@
1
+ #import "YapMemoryTable.h"
2
+
3
+
4
+ /**
5
+ * There may be multiple simulatneous database transactions, each using different atomic snapshots.
6
+ * In other words, the value in the database at snapshot A may be different than at snapshot B.
7
+ * Each value is correct, and depends entirely on the snapshot being used by the transaction.
8
+ *
9
+ * This presents a unique property of the table:
10
+ * - the table may store multiple values for a single key.
11
+ * - the stored values are associated with a snapshot
12
+ *
13
+ * This class represents a single stored value and its associated snapshot.
14
+ * It is one value contained within a linked-list of possibly multiple values for the same key.
15
+ * The linked-list remains sorted, with the most recent value at the front of the linked-list.
16
+ **/
17
+ @interface YapMemoryTableValue : NSObject {
18
+ @public
19
+ YapMemoryTableValue *olderValue;
20
+
21
+ uint64_t snapshot;
22
+ id object;
23
+ }
24
+
25
+ @end
26
+
27
+ @implementation YapMemoryTableValue
28
+
29
+ - (NSString *)description
30
+ {
31
+ return [NSString stringWithFormat:@"<YapMemoryTableValue[%p]: snapshot(%llu), olderValue(%p), object(%@)>",
32
+ self, snapshot, olderValue, object];
33
+ }
34
+
35
+ @end
36
+
37
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
38
+ #pragma mark -
39
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
40
+
41
+ @interface YapMemoryTable () {
42
+ @public
43
+
44
+ Class keyClass;
45
+
46
+ NSMutableDictionary *dict;
47
+
48
+ dispatch_queue_t queue;
49
+ void *IsOnQueueKey;
50
+
51
+ NSMutableArray *snapshots;
52
+ NSMutableArray *changes;
53
+ NSLock *lock;
54
+ }
55
+ @end
56
+
57
+ @interface YapMemoryTableTransaction () {
58
+ @public
59
+
60
+ __unsafe_unretained YapMemoryTable *table;
61
+
62
+ uint64_t snapshot;
63
+ BOOL isReadWriteTransaction;
64
+
65
+ NSMutableSet *changedKeys;
66
+ }
67
+ @end
68
+
69
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
70
+ #pragma mark -
71
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
72
+
73
+ @implementation YapMemoryTable
74
+
75
+ - (id)initWithKeyClass:(Class)inKeyClass
76
+ {
77
+ if ((self = [super init]))
78
+ {
79
+ keyClass = inKeyClass;
80
+
81
+ dict = [[NSMutableDictionary alloc] init];
82
+ queue = dispatch_queue_create("YapMemoryTable", DISPATCH_QUEUE_CONCURRENT);
83
+
84
+ IsOnQueueKey = &IsOnQueueKey;
85
+ dispatch_queue_set_specific(queue, IsOnQueueKey, IsOnQueueKey, NULL);
86
+
87
+ snapshots = [[NSMutableArray alloc] init];
88
+ changes = [[NSMutableArray alloc] init];
89
+ lock = [[NSLock alloc] init];
90
+ }
91
+ return self;
92
+ }
93
+ - (YapMemoryTableTransaction *)newReadTransactionWithSnapshot:(uint64_t)snapshot
94
+ {
95
+ YapMemoryTableTransaction *transaction = [[YapMemoryTableTransaction alloc] init];
96
+ transaction->table = self;
97
+ transaction->snapshot = snapshot;
98
+ transaction->isReadWriteTransaction = NO;
99
+
100
+ return transaction;
101
+ }
102
+
103
+ - (YapMemoryTableTransaction *)newReadWriteTransactionWithSnapshot:(uint64_t)snapshot
104
+ {
105
+ YapMemoryTableTransaction *transaction = [[YapMemoryTableTransaction alloc] init];
106
+ transaction->table = self;
107
+ transaction->snapshot = snapshot;
108
+ transaction->isReadWriteTransaction = YES;
109
+
110
+ return transaction;
111
+ }
112
+
113
+ - (void)asyncCheckpoint:(int64_t)minSnapshot
114
+ {
115
+ dispatch_barrier_async(queue, ^{ @autoreleasepool {
116
+
117
+ while (YES) // using manual return
118
+ {
119
+ int64_t snapshot = 0;
120
+ NSSet *changedKeys = nil;
121
+
122
+ [lock lock];
123
+
124
+ if ([snapshots count] > 0)
125
+ {
126
+ snapshot = [[snapshots objectAtIndex:0] unsignedLongLongValue];
127
+
128
+ if (snapshot < minSnapshot)
129
+ {
130
+ changedKeys = [changes objectAtIndex:0];
131
+
132
+ [snapshots removeObjectAtIndex:0];
133
+ [changes removeObjectAtIndex:0];
134
+ }
135
+ }
136
+
137
+ [lock unlock];
138
+
139
+ if (changedKeys == nil)
140
+ {
141
+ return; // Done
142
+ }
143
+
144
+ for (id key in changedKeys)
145
+ {
146
+ BOOL hasObject = NO;
147
+
148
+ __unsafe_unretained YapMemoryTableValue *prvValue = nil;
149
+ __unsafe_unretained YapMemoryTableValue *value = [dict objectForKey:key];
150
+
151
+ while (value && value->snapshot >= minSnapshot)
152
+ {
153
+ if (hasObject == NO)
154
+ hasObject = (value->object != nil);
155
+
156
+ prvValue = value;
157
+ value = value->olderValue;
158
+ }
159
+
160
+ if (value)
161
+ {
162
+ if (prvValue)
163
+ {
164
+ // The 'value' is not the latest value
165
+
166
+ if (!hasObject)
167
+ {
168
+ // All values >= minSnapshot represent a deletion.
169
+ // So we can just dump all values.
170
+
171
+ [dict removeObjectForKey:key];
172
+ }
173
+ else
174
+ {
175
+ // There are values >= minSnapshot in the table.
176
+ // So the stay in the dict.
177
+ // But everything older than minSnapshot can go.
178
+
179
+ prvValue->olderValue = nil;
180
+ }
181
+ }
182
+ else
183
+ {
184
+ // The 'value' is the latest value
185
+
186
+ if (value->object == nil)
187
+ {
188
+ // The 'value' is the latest value.
189
+ // And 'value' represents a deletion.
190
+ // So we can just dump all values.
191
+
192
+ [dict removeObjectForKey:key];
193
+ }
194
+ else
195
+ {
196
+ // The 'value' is the latest value.
197
+ // So it stays in the dict.
198
+ // But everything after it can go (if there is anything).
199
+
200
+ value->olderValue = nil;
201
+ }
202
+ }
203
+
204
+ } // end: if (value)
205
+
206
+ } // end: for (id key in changedKeys)
207
+
208
+ } // end: while (YES)
209
+ }});
210
+ }
211
+
212
+ - (void)asyncRollback:(int64_t)snapshot withChanges:(NSSet *)changedKeys
213
+ {
214
+ dispatch_barrier_async(queue, ^{ @autoreleasepool {
215
+
216
+ for (id key in changedKeys)
217
+ {
218
+ __unsafe_unretained YapMemoryTableValue *value = [dict objectForKey:key];
219
+
220
+ if (value && value->snapshot == snapshot)
221
+ {
222
+ if (value->olderValue == nil)
223
+ {
224
+ [dict removeObjectForKey:key];
225
+ }
226
+ else
227
+ {
228
+ [dict setObject:value->olderValue forKey:key];
229
+ }
230
+ }
231
+ }
232
+ }});
233
+ }
234
+
235
+ @end
236
+
237
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
238
+ #pragma mark -
239
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
240
+
241
+ @implementation YapMemoryTableTransaction
242
+
243
+ @synthesize snapshot = snapshot;
244
+ @synthesize isReadWriteTransaction = isReadWriteTransaction;
245
+
246
+ - (id)objectForKey:(id)key
247
+ {
248
+ NSAssert([key isKindOfClass:table->keyClass],
249
+ @"Unexpected key class. Expected %@, passed %@", table->keyClass, [key class]);
250
+
251
+ __block id result = nil;
252
+
253
+ dispatch_block_t block = ^{
254
+
255
+ __unsafe_unretained YapMemoryTableValue *value = [table->dict objectForKey:key];
256
+
257
+ while (value)
258
+ {
259
+ if (value->snapshot <= snapshot)
260
+ {
261
+ result = value->object;
262
+ break;
263
+ }
264
+ else
265
+ {
266
+ value = value->olderValue;
267
+ }
268
+ }
269
+ };
270
+
271
+ if (dispatch_get_specific(table->IsOnQueueKey))
272
+ block();
273
+ else
274
+ dispatch_sync(table->queue, block);
275
+
276
+ return result;
277
+ }
278
+
279
+ - (void)enumerateKeysWithBlock:(void (^)(id key, BOOL *stop))userBlock
280
+ {
281
+ dispatch_block_t block = ^{ @autoreleasepool {
282
+
283
+ [table->dict enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
284
+
285
+ __unsafe_unretained YapMemoryTableValue *value = [table->dict objectForKey:key];
286
+ while (value)
287
+ {
288
+ if (value->snapshot <= snapshot)
289
+ {
290
+ if (value->object)
291
+ {
292
+ userBlock(key, stop);
293
+ }
294
+ break;
295
+ }
296
+ else
297
+ {
298
+ value = value->olderValue;
299
+ }
300
+ }
301
+ }];
302
+ }};
303
+
304
+ if (dispatch_get_specific(table->IsOnQueueKey))
305
+ block();
306
+ else
307
+ dispatch_sync(table->queue, block);
308
+ }
309
+
310
+ - (void)enumerateKeysAndObjectsWithBlock:(void (^)(id key, id obj, BOOL *stop))userBlock
311
+ {
312
+ dispatch_block_t block = ^{ @autoreleasepool {
313
+
314
+ [table->dict enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
315
+
316
+ __unsafe_unretained YapMemoryTableValue *value = [table->dict objectForKey:key];
317
+ while (value)
318
+ {
319
+ if (value->snapshot <= snapshot)
320
+ {
321
+ if (value->object)
322
+ {
323
+ userBlock(key, value->object, stop);
324
+ }
325
+ break;
326
+ }
327
+ else
328
+ {
329
+ value = value->olderValue;
330
+ }
331
+ }
332
+ }];
333
+ }};
334
+
335
+ if (dispatch_get_specific(table->IsOnQueueKey))
336
+ block();
337
+ else
338
+ dispatch_sync(table->queue, block);
339
+ }
340
+
341
+ - (void)setObject:(id)object forKey:(id)key
342
+ {
343
+ NSAssert([key isKindOfClass:table->keyClass],
344
+ @"Unexpected key class. Expected %@, passed %@", table->keyClass, [key class]);
345
+
346
+ if (!isReadWriteTransaction) {
347
+ NSAssert(NO, @"Cannot modify table in read-only transaction.");
348
+ return;
349
+ }
350
+
351
+ if (changedKeys == nil)
352
+ changedKeys = [[NSMutableSet alloc] init];
353
+
354
+ dispatch_block_t block = ^{
355
+
356
+ __unsafe_unretained YapMemoryTableValue *value = [table->dict objectForKey:key];
357
+
358
+ if (value && value->snapshot == snapshot)
359
+ {
360
+ // We've already updated this key during this transaction.
361
+
362
+ value->object = object;
363
+ }
364
+ else
365
+ {
366
+ // First update for this key during this transaction.
367
+
368
+ YapMemoryTableValue *newValue = [[YapMemoryTableValue alloc] init];
369
+ newValue->olderValue = value;
370
+ newValue->object = object;
371
+ newValue->snapshot = snapshot;
372
+
373
+ [table->dict setObject:newValue forKey:key];
374
+
375
+ [changedKeys addObject:key];
376
+ }
377
+ };
378
+
379
+ if (dispatch_get_specific(table->IsOnQueueKey))
380
+ block();
381
+ else
382
+ dispatch_barrier_sync(table->queue, block);
383
+ }
384
+
385
+ - (void)removeObjectForKey:(id)key
386
+ {
387
+ NSAssert([key isKindOfClass:table->keyClass],
388
+ @"Unexpected key class. Expected %@, passed %@", table->keyClass, [key class]);
389
+
390
+ if (!isReadWriteTransaction) {
391
+ NSAssert(NO, @"Cannot modify table in read-only transaction.");
392
+ return;
393
+ }
394
+
395
+ if (changedKeys == nil)
396
+ changedKeys = [[NSMutableSet alloc] init];
397
+
398
+ dispatch_block_t block = ^{
399
+
400
+ __unsafe_unretained YapMemoryTableValue *value = [table->dict objectForKey:key];
401
+
402
+ if (value)
403
+ {
404
+ if (value->snapshot == snapshot)
405
+ {
406
+ // We've already updated this key during this transaction.
407
+
408
+ if (value->olderValue == nil)
409
+ {
410
+ // Removing a previously set value within this transaction.
411
+ // And there are no other values outside this transaction.
412
+
413
+ [table->dict removeObjectForKey:key];
414
+
415
+ [changedKeys removeObject:key];
416
+ }
417
+ else
418
+ {
419
+ // Updating a previously set value within this transaction.
420
+ // But there are other values for older snapshots.
421
+
422
+ value->object = nil;
423
+ }
424
+ }
425
+ else
426
+ {
427
+ // First update for this key during this transaction.
428
+
429
+ YapMemoryTableValue *newValue = [[YapMemoryTableValue alloc] init];
430
+ newValue->olderValue = value;
431
+ newValue->object = nil;
432
+ newValue->snapshot = snapshot;
433
+
434
+ [table->dict setObject:newValue forKey:key];
435
+
436
+ [changedKeys addObject:key];
437
+ }
438
+ }
439
+ };
440
+
441
+ if (dispatch_get_specific(table->IsOnQueueKey))
442
+ block();
443
+ else
444
+ dispatch_barrier_sync(table->queue, block);
445
+ }
446
+
447
+ - (void)removeObjectsForKeys:(NSArray *)keys
448
+ {
449
+ if (!isReadWriteTransaction) {
450
+ NSAssert(NO, @"Cannot modify table in read-only transaction.");
451
+ return;
452
+ }
453
+
454
+ if (changedKeys == nil)
455
+ changedKeys = [[NSMutableSet alloc] init];
456
+
457
+ dispatch_block_t block = ^{ @autoreleasepool {
458
+
459
+ for (id key in keys)
460
+ {
461
+ NSAssert([key isKindOfClass:table->keyClass],
462
+ @"Unexpected key class. Expected %@, passed %@", table->keyClass, [key class]);
463
+
464
+ __unsafe_unretained YapMemoryTableValue *value = [table->dict objectForKey:key];
465
+
466
+ if (value)
467
+ {
468
+ if (value->snapshot == snapshot)
469
+ {
470
+ // We've already updated this key during this transaction.
471
+
472
+ if (value->olderValue == nil)
473
+ {
474
+ // Removing a previously set value within this transaction.
475
+ // And there are no other values outside this transaction.
476
+
477
+ [table->dict removeObjectForKey:key];
478
+
479
+ [changedKeys removeObject:key];
480
+ }
481
+ else
482
+ {
483
+ // Updating a previously set value within this transaction.
484
+ // But there are other values for older snapshots.
485
+
486
+ value->object = nil;
487
+ }
488
+ }
489
+ else
490
+ {
491
+ // First update for this key during this transaction.
492
+
493
+ YapMemoryTableValue *newValue = [[YapMemoryTableValue alloc] init];
494
+ newValue->olderValue = value;
495
+ newValue->object = nil;
496
+ newValue->snapshot = snapshot;
497
+
498
+ [table->dict setObject:newValue forKey:key];
499
+
500
+ [changedKeys addObject:key];
501
+ }
502
+ }
503
+ }
504
+ }};
505
+
506
+ if (dispatch_get_specific(table->IsOnQueueKey))
507
+ block();
508
+ else
509
+ dispatch_barrier_sync(table->queue, block);
510
+ }
511
+
512
+ - (void)removeAllObjects
513
+ {
514
+ NSAssert(isReadWriteTransaction, @"Cannot modify table in read-only transaction.");
515
+
516
+ if (changedKeys == nil)
517
+ changedKeys = [[NSMutableSet alloc] init];
518
+
519
+ dispatch_block_t block = ^{ @autoreleasepool {
520
+
521
+ // Grab all keys
522
+ NSArray *keys = [table->dict allKeys];
523
+
524
+ // Mark all keys as changed
525
+ [changedKeys addObjectsFromArray:keys];
526
+
527
+ // Now enumerate all the keys, and update accordingly
528
+ for (id key in keys)
529
+ {
530
+ __unsafe_unretained YapMemoryTableValue *value = [table->dict objectForKey:key];
531
+
532
+ if (value->snapshot == snapshot)
533
+ {
534
+ // We've already updated this key during this transaction.
535
+
536
+ if (value->olderValue == nil)
537
+ {
538
+ // Removing a previously set value within this transaction.
539
+ // And there are no other values outside this transaction.
540
+
541
+ [table->dict removeObjectForKey:key];
542
+ [changedKeys removeObject:key];
543
+ }
544
+ else
545
+ {
546
+ // Updating a previously set value within this transaction.
547
+ // But there are other values for older snapshots.
548
+
549
+ value->object = nil;
550
+ }
551
+ }
552
+ else
553
+ {
554
+ // First update for this key during this transaction.
555
+
556
+ YapMemoryTableValue *newValue = [[YapMemoryTableValue alloc] init];
557
+ newValue->olderValue = value;
558
+ newValue->object = nil;
559
+ newValue->snapshot = snapshot;
560
+
561
+ [table->dict setObject:newValue forKey:key];
562
+ }
563
+ }
564
+ }};
565
+
566
+ if (dispatch_get_specific(table->IsOnQueueKey))
567
+ block();
568
+ else
569
+ dispatch_barrier_sync(table->queue, block);
570
+ }
571
+
572
+ - (void)accessWithBlock:(dispatch_block_t)block
573
+ {
574
+ dispatch_sync(table->queue, block);
575
+ }
576
+
577
+ - (void)modifyWithBlock:(dispatch_block_t)block
578
+ {
579
+ dispatch_barrier_sync(table->queue, block);
580
+ }
581
+
582
+ - (void)commit
583
+ {
584
+ if (isReadWriteTransaction && [changedKeys count] > 0)
585
+ {
586
+ [table->lock lock];
587
+ {
588
+ [table->snapshots addObject:@(snapshot)];
589
+ [table->changes addObject:changedKeys];
590
+ }
591
+ [table->lock unlock];
592
+ }
593
+ }
594
+
595
+ - (void)rollback
596
+ {
597
+ if (isReadWriteTransaction && [changedKeys count] > 0)
598
+ {
599
+ [table asyncRollback:snapshot withChanges:changedKeys];
600
+ }
601
+ }
602
+
603
+ @end