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,16 @@
1
+ module Yapper::Timestamps
2
+ extend MotionSupport::Concern
3
+
4
+ included do
5
+ field :updated_at, :type => Time
6
+ field :created_at, :type => Time
7
+
8
+ before_save :set_timestamps
9
+ end
10
+
11
+ def set_timestamps
12
+ now = Time.now
13
+ self.created_at = now if created_at.nil?
14
+ self.updated_at = now
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module Yapper
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,2 @@
1
+ module Yapper
2
+ end
@@ -0,0 +1,3 @@
1
+ def same_time_as(time)
2
+ lambda { |obj| time.is_a?(Time) && obj.is_a?(Time) && (time - obj) < 1.0 }
3
+ end
@@ -0,0 +1,40 @@
1
+ describe '#all' do
2
+ before do
3
+ class SelectionDocument
4
+ include Yapper::Document
5
+
6
+ field :field1
7
+ field :field2
8
+ end
9
+ class AnotherSelectionDocument
10
+ include Yapper::Document
11
+
12
+ field :field1
13
+ field :field2
14
+ end
15
+ end
16
+ before { Yapper::DB.instance.purge }
17
+ after { Object.send(:remove_const, 'SelectionDocument') }
18
+ after { Object.send(:remove_const, 'AnotherSelectionDocument') }
19
+
20
+ describe 'with no documents created' do
21
+ it 'returns []' do
22
+ SelectionDocument.all.should == []
23
+ end
24
+ end
25
+
26
+ describe 'with a few documents created with string fields' do
27
+ before do
28
+ @doc = SelectionDocument.create(:field1 => 'field1_value', :field2 => 'field2_value')
29
+ SelectionDocument.create(:field1 => 'field1_value', :field2 => 'field2_value')
30
+ SelectionDocument.create(:field1 => 'field1_value', :field2 => 'field2_other_value')
31
+ SelectionDocument.create(:field1 => 'field1_other_value', :field2 => 'field2_other_value')
32
+ AnotherSelectionDocument.create(:field1 => 'field1_value', :field2 => 'field2_value')
33
+ end
34
+
35
+ it 'returns all documents' do
36
+ SelectionDocument.all.count.should == 4
37
+ SelectionDocument.all.all? { |doc| doc.class.should == SelectionDocument }
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,87 @@
1
+ describe 'callbacks' do
2
+ before do
3
+ class CallbackDocument
4
+ include Yapper::Document
5
+
6
+ field :field_1
7
+ field :field_2
8
+
9
+ before_save :do_before_save
10
+ before_save :do_another_before_save
11
+ after_save :do_after_save
12
+ after_save :do_another_after_save
13
+
14
+ private
15
+
16
+ def do_before_save
17
+ $before_save_1 = true
18
+ end
19
+
20
+ def do_another_before_save
21
+ $before_save_2 = true
22
+ end
23
+
24
+ def do_after_save
25
+ $after_save_1 = true
26
+ end
27
+
28
+ def do_another_after_save
29
+ $after_save_2 = true
30
+ end
31
+ end
32
+ end
33
+ before { Yapper::DB.instance.purge }
34
+ after { Object.send(:remove_const, 'CallbackDocument') }
35
+
36
+ describe 'creating documents' do
37
+ it 'before and after callbacks are fired' do
38
+ CallbackDocument.create(:field_1 => 'field1',
39
+ :field_2 => 'field2')
40
+
41
+ $before_save_1.should == true
42
+ $before_save_2.should == true
43
+ $after_save_1.should == true
44
+ $after_save_2.should == true
45
+ end
46
+ end
47
+
48
+ describe 'updating documents' do
49
+ before do
50
+ @doc = CallbackDocument.create(:field_1 => 'field1')
51
+ $before_save_1 = false
52
+ $before_save_2 = false
53
+ $after_save_1 = false
54
+ $after_save_2 = false
55
+ end
56
+
57
+ it 'before and after callbacks are fired' do
58
+ @doc.field_1 = 'field1_updated'
59
+ @doc.save
60
+
61
+ $before_save_1.should == true
62
+ $before_save_2.should == true
63
+ $after_save_1.should == true
64
+ $after_save_2.should == true
65
+ end
66
+ end
67
+
68
+ describe 'on failure' do
69
+ before do
70
+ class CallbackDocument
71
+ after_save :fail
72
+
73
+ def fail
74
+ raise "fail"
75
+ end
76
+ end
77
+ end
78
+
79
+ it 'rollsback the entire update' do
80
+ lambda {
81
+ CallbackDocument.create(:field_1 => 'field1')
82
+ }.should.raise
83
+
84
+ CallbackDocument.all.count.should == 0
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,40 @@
1
+ describe 'db' do
2
+ before do
3
+ class Document
4
+ include Yapper::Document
5
+
6
+ field :field_1
7
+ field :field_2
8
+ end
9
+
10
+ class AnotherDocument
11
+ include Yapper::Document
12
+
13
+ field :field_1
14
+ field :field_2
15
+ end
16
+ end
17
+ before { Yapper::DB.instance.purge }
18
+ after { Object.send(:remove_const, 'Document') }
19
+ after { Object.send(:remove_const, 'AnotherDocument') }
20
+
21
+ it 'is thread safe' do
22
+ threads = []
23
+ threads << Thread.new { 10.times { Document.create(:field_1 => 'field') } }
24
+ threads << Thread.new { 10.times { AnotherDocument.create(:field_1 => 'field') } }
25
+ threads << Thread.new { 10.times { Document.all.each { |d| d.update_attributes(:field_1 => 'bye') } } }
26
+ threads << Thread.new { 10.times { AnotherDocument.all.each { |d| d.update_attributes(:field_1 => 'bye') } } }
27
+ threads.each(&:join)
28
+
29
+ Document.all.count.should == 10
30
+ AnotherDocument.all.count.should == 10
31
+ end
32
+
33
+ it 'can nest transactions' do
34
+ Yapper::DB.instance.execute do |txn|
35
+ Document.create(:field_1 => '1')
36
+ Document.create(:field_1 => '2')
37
+ end
38
+ Document.all.count.should == 2
39
+ end
40
+ end
@@ -0,0 +1,51 @@
1
+ describe '#find' do
2
+ before do
3
+ class SelectionDocument
4
+ include Yapper::Document
5
+
6
+ field :field1
7
+ field :field2
8
+ end
9
+ class AnotherSelectionDocument
10
+ include Yapper::Document
11
+
12
+ field :field1
13
+ field :field2
14
+ end
15
+ end
16
+ before { Yapper::DB.instance.purge }
17
+ after { Object.send(:remove_const, 'SelectionDocument') }
18
+ after { Object.send(:remove_const, 'AnotherSelectionDocument') }
19
+
20
+ describe 'with no documents created' do
21
+ it 'returns nil when looking up a document' do
22
+ SelectionDocument.find('xxx').should == nil
23
+ end
24
+ end
25
+
26
+ describe 'with a few documents created with string fields' do
27
+ before do
28
+ @doc = SelectionDocument.create(:field1 => 'field1_value', :field2 => 'field2_value')
29
+ SelectionDocument.create(:field1 => 'field1_value', :field2 => 'field2_value')
30
+ SelectionDocument.create(:field1 => 'field1_value', :field2 => 'field2_other_value')
31
+ SelectionDocument.create(:field1 => 'field1_other_value', :field2 => 'field2_other_value')
32
+ AnotherSelectionDocument.create(:field1 => 'field1_value', :field2 => 'field2_value')
33
+ end
34
+
35
+ it 'can find a document' do
36
+ SelectionDocument.find(@doc.id).field1.should == 'field1_value'
37
+ end
38
+
39
+ it 'has no changes when selecting a document' do
40
+ SelectionDocument.find(@doc.id).changes.should == {}
41
+ end
42
+
43
+ it 'returns nil when looking up a non-existant doc' do
44
+ SelectionDocument.find('xxx').should == nil
45
+ end
46
+
47
+ it 'returns nil when looking up nil' do
48
+ SelectionDocument.find(nil).should == nil
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,118 @@
1
+ describe 'Yapper persisting documents' do
2
+ before do
3
+ class Document
4
+ include Yapper::Document
5
+
6
+ field :field_1
7
+ field :field_2
8
+ end
9
+ end
10
+ before { Yapper::DB.instance.purge }
11
+ after { Object.send(:remove_const, 'Document') }
12
+
13
+ describe 'creating documents' do
14
+ it 'supports storing hashes by stringifying keys (to avoid NanoStore bug)' do
15
+ 10.times { Document.create.tap { |doc| doc.update_attributes(:field_1 => { :a => [ { :a => 10 } ] }) } }
16
+ Document.all.each { |doc| doc.field_1[:b] = 'b'; doc.save }
17
+
18
+ Document.all.each { |doc| doc.field_1.should == { 'a' => [ { 'a' => 10 } ], 'b' => 'b' } }
19
+ end
20
+
21
+ it 'supports storing Time' do
22
+ time = Time.now
23
+ Document.create(:field_1 => time)
24
+
25
+ Document.all.first.field_1.should == time
26
+ end
27
+
28
+ it 'tracks changes' do
29
+ doc = Document.new
30
+ doc.field_1 = 'field1'
31
+ doc.field_2 = 'field2'
32
+
33
+ doc.changes.should == { 'id' => doc.id,
34
+ 'field_1' => 'field1',
35
+ 'field_2' => 'field2' }
36
+ end
37
+
38
+ describe "when using #new then #save" do
39
+ it 'persists the fields' do
40
+ doc = Document.new
41
+ doc.field_1 = 'field1'
42
+ doc.field_2 = 'field2'
43
+ doc.new_record?.should == true
44
+ doc.save
45
+
46
+ doc = Document.find(doc.id)
47
+ doc.new_record?.should == false
48
+ doc.field_1.should == 'field1'
49
+ doc.field_2.should == 'field2'
50
+ end
51
+ end
52
+
53
+ describe "when using #create" do
54
+ it 'persists the fields' do
55
+ doc = Document.create(:field_1 => 'field1',
56
+ :field_2 => 'field2')
57
+
58
+ doc = Document.find(doc.id)
59
+ doc.field_1.should == 'field1'
60
+ doc.field_2.should == 'field2'
61
+ end
62
+ end
63
+ end
64
+
65
+ describe 'updating documents' do
66
+ before do
67
+ @doc = Document.create(:field_1 => 'field1')
68
+ end
69
+
70
+ it 'tracks changes' do
71
+ @doc.field_1 = 'field1_changed'
72
+
73
+ @doc.changes.should == { 'field_1' => 'field1_changed' }
74
+
75
+ @doc.save
76
+
77
+ @doc.changes.should == {}
78
+ @doc.previous_changes.should == { 'field_1' => 'field1_changed' }
79
+ end
80
+
81
+ it 'saves a false value' do
82
+ @doc.update_attributes(:field_1 => false)
83
+
84
+ @doc.reload.field_1.should == false
85
+ end
86
+
87
+ describe "when updating fields and then #save" do
88
+ it 'persists the fields' do
89
+ @doc.field_1 = 'field1_updated'
90
+ @doc.save
91
+
92
+ doc = Document.find(@doc.id)
93
+ doc.field_1.should == 'field1_updated'
94
+ end
95
+ end
96
+
97
+ describe "when using #update_attributes" do
98
+ it 'persists the fields' do
99
+ @doc.update_attributes(:field_1 => 'field1_updated')
100
+
101
+ doc = Document.find(@doc.id)
102
+ doc.field_1.should == 'field1_updated'
103
+ end
104
+ end
105
+ end
106
+
107
+ describe 'destroying documents' do
108
+ before do
109
+ @doc = Document.create(:field_1 => 'field1')
110
+ end
111
+
112
+ it 'destroys the document' do
113
+ @doc.destroy
114
+
115
+ Document.find(@doc.id).should == nil
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,174 @@
1
+ describe 'Yapper document 1:N relationship' do
2
+ before do
3
+ class ParentDocument
4
+ include Yapper::Document
5
+
6
+ field :field_1
7
+
8
+ has_many :child_documents
9
+ end
10
+ class ChildDocument
11
+ include Yapper::Document
12
+
13
+ field :field_1
14
+ field :field_2
15
+
16
+ belongs_to :parent_document
17
+ end
18
+ end
19
+ before { Yapper::DB.instance.purge }
20
+ after { ['ParentDocument', 'ChildDocument'].each { |klass| Object.send(:remove_const, klass) } }
21
+
22
+ it 'can accept nested attributes' do
23
+ @parent = ParentDocument.create(:field_1 => 'parent',
24
+ :child_documents => [
25
+ { :field_1 => 'child0' },
26
+ { :field_1 => 'child1' }
27
+ ])
28
+
29
+ @parent.field_1.should == 'parent'
30
+ @parent.child_documents.collect(&:field_1).should == ['child0', 'child1']
31
+ end
32
+
33
+ it 'can accept an nested attributes with ids' do
34
+ children = 2.times.map { |i| { :id => BSON::ObjectId.generate, :field_1 => "child#{i}" } }
35
+ @parent = ParentDocument.create(:field_1 => 'parent',
36
+ :child_documents => children)
37
+
38
+ children.each do |child|
39
+ ChildDocument.find(child[:id]).should.not == nil
40
+ end
41
+ end
42
+
43
+ it 'can accept array of initialized children' do
44
+ children = 2.times.map { |i| ChildDocument.new(:field_1 => "child#{i}") }
45
+ @parent = ParentDocument.create(:field_1 => 'parent',
46
+ :child_documents => children)
47
+
48
+ @parent.field_1.should == 'parent'
49
+ @parent.child_documents.collect(&:field_1).should == ['child0', 'child1']
50
+ end
51
+
52
+ it 'can accept array of created children' do
53
+ children = 2.times.map { |i| ChildDocument.create(:field_1 => "child#{i}") }
54
+ @parent = ParentDocument.create(:field_1 => 'parent',
55
+ :child_documents => children)
56
+
57
+ @parent.field_1.should == 'parent'
58
+ @parent.child_documents.collect(&:field_1).should == ['child0', 'child1']
59
+ end
60
+
61
+ it 'can update a child document via nested attributes' do
62
+ children = 2.times.map { |i| { :id => BSON::ObjectId.generate,
63
+ :field_1 => "child#{i}",
64
+ :field_2 => 'value' } }
65
+ @parent = ParentDocument.create(:field_1 => 'parent',
66
+ :child_documents => children)
67
+ @parent.update_attributes(:child_documents => [{ :id => children[0][:id],
68
+ :field_1 => 'updated0' },
69
+ { :id => children[1][:id],
70
+ :field_1 => 'updated1' }])
71
+
72
+ children.each_with_index do |child, i|
73
+ ChildDocument.find(child[:id]).field_1.should == "updated#{i}"
74
+ ChildDocument.find(child[:id]).field_2.should == "value"
75
+ end
76
+ end
77
+
78
+ it 'can set a parent to nil' do
79
+ child = ChildDocument.create(:field_1 => 'child_field',
80
+ :parent_document => nil)
81
+
82
+ child.field_1.should == 'child_field'
83
+ end
84
+
85
+ describe 'with a parent with many children' do
86
+ before do
87
+ @parent = ParentDocument.create(:field_1 => 'parent')
88
+ 3.times { ChildDocument.create(:parent_document => @parent) }
89
+ end
90
+
91
+ it 'the child can access the parent' do
92
+ @parent.reload
93
+
94
+ @parent.child_documents.count.should == 3
95
+ @parent.child_documents.each { |doc| doc.class.should == ChildDocument }
96
+ end
97
+
98
+ it 'the parent can access the child' do
99
+ ChildDocument.all.each { |doc| doc.parent_document.id.should == @parent.id }
100
+ end
101
+
102
+ describe 'when a child is destroyed' do
103
+ before do
104
+ @last_id = ChildDocument.all.last.id
105
+ ChildDocument.all.last.destroy
106
+ end
107
+
108
+ it 'the child is removed from the parent' do
109
+ @parent.reload
110
+
111
+ @parent.child_documents.count.should == 2
112
+ @parent.child_documents.collect(&:id).each { |id| id.should.not == @last_id }
113
+ end
114
+ end
115
+ end
116
+
117
+ describe 'with a before_save callback on the child that references the parent document' do
118
+ before do
119
+ ChildDocument.class_eval do
120
+ before_save :set_field_2
121
+
122
+ def set_field_2
123
+ self.field_2 = self.parent_document.id
124
+ end
125
+ end
126
+ end
127
+
128
+ it 'includes parent relation in the callback' do
129
+ @parent = ParentDocument.create(:field_1 => 'parent',
130
+ :child_documents => [{ :field_1 => "value" }])
131
+
132
+ @parent.child_documents.first.field_2.should == @parent.id
133
+ end
134
+ end
135
+ end
136
+
137
+ describe 'Yapper document 1:N:1 relationship' do
138
+ before do
139
+ class Parent1
140
+ include Yapper::Document
141
+
142
+ field :field_1
143
+
144
+ has_many :child_documents
145
+ end
146
+ class Parent2
147
+ include Yapper::Document
148
+
149
+ field :field_1
150
+
151
+ has_many :child_documents
152
+ end
153
+ class ChildDocument
154
+ include Yapper::Document
155
+
156
+ field :field_1
157
+
158
+ belongs_to :parent1
159
+ belongs_to :parent2
160
+ end
161
+ end
162
+ after { Yapper::DB.instance.purge }
163
+ after { ['Parent1', 'Parent2', 'ChildDocument'].each { |klass| Object.send(:remove_const, klass) } }
164
+
165
+ it 'can create child with many parents' do
166
+ parent1 = Parent1.create(:field_1 => 'parent1')
167
+ parent2 = Parent2.create(:field_1 => 'parent2')
168
+
169
+ child = ChildDocument.create(:parent1 => parent1, :parent2 => parent2)
170
+
171
+ child.parent1.field_1.should == 'parent1'
172
+ child.parent2.field_1.should == 'parent2'
173
+ end
174
+ end