motion-yapper 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +20 -0
- data/.travis.yml +6 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +63 -0
- data/README.md +16 -0
- data/Rakefile +20 -0
- data/app/app_delegate.rb +5 -0
- data/lib/yapper.rb +30 -0
- data/lib/yapper/attachment.rb +48 -0
- data/lib/yapper/bson.rb +20 -0
- data/lib/yapper/config.rb +18 -0
- data/lib/yapper/db.rb +151 -0
- data/lib/yapper/document.rb +54 -0
- data/lib/yapper/document/attachment.rb +26 -0
- data/lib/yapper/document/callbacks.rb +86 -0
- data/lib/yapper/document/persistance.rb +171 -0
- data/lib/yapper/document/relation.rb +84 -0
- data/lib/yapper/document/selection.rb +100 -0
- data/lib/yapper/extensions.rb +80 -0
- data/lib/yapper/log.rb +5 -0
- data/lib/yapper/sync.rb +134 -0
- data/lib/yapper/sync/data.rb +12 -0
- data/lib/yapper/sync/event.rb +194 -0
- data/lib/yapper/sync/queue.rb +164 -0
- data/lib/yapper/timestamps.rb +16 -0
- data/lib/yapper/version.rb +3 -0
- data/lib/yapper/yapper.rb +2 -0
- data/spec/helpers/time_helper.rb +3 -0
- data/spec/integration/all_spec.rb +40 -0
- data/spec/integration/callback_spec.rb +87 -0
- data/spec/integration/db_spec.rb +40 -0
- data/spec/integration/find_spec.rb +51 -0
- data/spec/integration/persistance_spec.rb +118 -0
- data/spec/integration/relation_spec.rb +174 -0
- data/spec/integration/sync_spec.rb +42 -0
- data/spec/integration/timestamps_spec.rb +34 -0
- data/spec/integration/types_spec.rb +23 -0
- data/spec/integration/when_spec.rb +29 -0
- data/spec/integration/where_spec.rb +132 -0
- data/vendor/Podfile.lock +24 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFHTTPClient.h +641 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFHTTPClient.m +1396 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFHTTPRequestOperation.h +133 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFHTTPRequestOperation.m +327 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFImageRequestOperation.h +113 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFImageRequestOperation.m +321 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFJSONRequestOperation.h +71 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFJSONRequestOperation.m +150 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFNetworkActivityIndicatorManager.h +75 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFNetworkActivityIndicatorManager.m +157 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFNetworking.h +43 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFPropertyListRequestOperation.h +68 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFPropertyListRequestOperation.m +143 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFURLConnectionOperation.h +370 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFURLConnectionOperation.m +848 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFXMLRequestOperation.h +89 -0
- data/vendor/Pods/AFNetworking/AFNetworking/AFXMLRequestOperation.m +167 -0
- data/vendor/Pods/AFNetworking/AFNetworking/UIImageView+AFNetworking.h +78 -0
- data/vendor/Pods/AFNetworking/AFNetworking/UIImageView+AFNetworking.m +191 -0
- data/vendor/Pods/AFNetworking/LICENSE +19 -0
- data/vendor/Pods/AFNetworking/README.md +208 -0
- data/vendor/Pods/BuildHeaders/AFNetworking/AFHTTPClient.h +641 -0
- data/vendor/Pods/BuildHeaders/AFNetworking/AFHTTPRequestOperation.h +133 -0
- data/vendor/Pods/BuildHeaders/AFNetworking/AFImageRequestOperation.h +113 -0
- data/vendor/Pods/BuildHeaders/AFNetworking/AFJSONRequestOperation.h +71 -0
- data/vendor/Pods/BuildHeaders/AFNetworking/AFNetworkActivityIndicatorManager.h +75 -0
- data/vendor/Pods/BuildHeaders/AFNetworking/AFNetworking.h +43 -0
- data/vendor/Pods/BuildHeaders/AFNetworking/AFPropertyListRequestOperation.h +68 -0
- data/vendor/Pods/BuildHeaders/AFNetworking/AFURLConnectionOperation.h +370 -0
- data/vendor/Pods/BuildHeaders/AFNetworking/AFXMLRequestOperation.h +89 -0
- data/vendor/Pods/BuildHeaders/AFNetworking/UIImageView+AFNetworking.h +78 -0
- data/vendor/Pods/BuildHeaders/CocoaLumberjack/ContextFilterLogFormatter.h +65 -0
- data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDASLLogger.h +41 -0
- data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDAbstractDatabaseLogger.h +102 -0
- data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDFileLogger.h +334 -0
- data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDLog.h +601 -0
- data/vendor/Pods/BuildHeaders/CocoaLumberjack/DDTTYLogger.h +167 -0
- data/vendor/Pods/BuildHeaders/CocoaLumberjack/DispatchQueueLogFormatter.h +116 -0
- data/vendor/Pods/BuildHeaders/NSData+MD5Digest/NSData+MD5Digest.h +18 -0
- data/vendor/Pods/BuildHeaders/Reachability/Reachability.h +109 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapCache.h +90 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapCollectionKey.h +20 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabase.h +547 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseConnection.h +447 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseConnectionState.h +29 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseDefaults.h +37 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseExtension.h +15 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseExtensionConnection.h +11 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseExtensionPrivate.h +440 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseExtensionTransaction.h +11 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFilteredView.h +108 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFilteredViewConnection.h +12 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFilteredViewPrivate.h +19 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFilteredViewTransaction.h +39 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFullTextSearch.h +89 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFullTextSearchConnection.h +32 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFullTextSearchPrivate.h +69 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFullTextSearchSnippetOptions.h +79 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseFullTextSearchTransaction.h +68 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseLogging.h +158 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseManager.h +17 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabasePrivate.h +424 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseQuery.h +42 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseSecondaryIndex.h +100 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseSecondaryIndexConnection.h +33 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseSecondaryIndexPrivate.h +73 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseSecondaryIndexSetup.h +33 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseSecondaryIndexTransaction.h +58 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseStatement.h +13 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseString.h +121 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseTransaction.h +541 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseView.h +186 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewChange.h +272 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewChangePrivate.h +94 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewConnection.h +115 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewMappings.h +825 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewMappingsPrivate.h +72 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewOptions.h +56 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewPage.h +36 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewPageMetadata.h +27 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewPrivate.h +153 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewRangeOptions.h +330 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewRangeOptionsPrivate.h +17 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapDatabaseViewTransaction.h +447 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapMemoryTable.h +74 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapNull.h +17 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapSet.h +41 -0
- data/vendor/Pods/BuildHeaders/YapDatabase/YapTouch.h +15 -0
- data/vendor/Pods/CocoaLumberjack/LICENSE.txt +18 -0
- data/vendor/Pods/CocoaLumberjack/Lumberjack/DDASLLogger.h +41 -0
- data/vendor/Pods/CocoaLumberjack/Lumberjack/DDASLLogger.m +99 -0
- data/vendor/Pods/CocoaLumberjack/Lumberjack/DDAbstractDatabaseLogger.h +102 -0
- data/vendor/Pods/CocoaLumberjack/Lumberjack/DDAbstractDatabaseLogger.m +727 -0
- data/vendor/Pods/CocoaLumberjack/Lumberjack/DDFileLogger.h +334 -0
- data/vendor/Pods/CocoaLumberjack/Lumberjack/DDFileLogger.m +1353 -0
- data/vendor/Pods/CocoaLumberjack/Lumberjack/DDLog.h +601 -0
- data/vendor/Pods/CocoaLumberjack/Lumberjack/DDLog.m +1083 -0
- data/vendor/Pods/CocoaLumberjack/Lumberjack/DDTTYLogger.h +167 -0
- data/vendor/Pods/CocoaLumberjack/Lumberjack/DDTTYLogger.m +1479 -0
- data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/ContextFilterLogFormatter.h +65 -0
- data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/ContextFilterLogFormatter.m +191 -0
- data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/DispatchQueueLogFormatter.h +116 -0
- data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/DispatchQueueLogFormatter.m +251 -0
- data/vendor/Pods/CocoaLumberjack/Lumberjack/Extensions/README.txt +7 -0
- data/vendor/Pods/CocoaLumberjack/README.markdown +37 -0
- data/vendor/Pods/Headers/AFNetworking/AFHTTPClient.h +641 -0
- data/vendor/Pods/Headers/AFNetworking/AFHTTPRequestOperation.h +133 -0
- data/vendor/Pods/Headers/AFNetworking/AFImageRequestOperation.h +113 -0
- data/vendor/Pods/Headers/AFNetworking/AFJSONRequestOperation.h +71 -0
- data/vendor/Pods/Headers/AFNetworking/AFNetworkActivityIndicatorManager.h +75 -0
- data/vendor/Pods/Headers/AFNetworking/AFNetworking.h +43 -0
- data/vendor/Pods/Headers/AFNetworking/AFPropertyListRequestOperation.h +68 -0
- data/vendor/Pods/Headers/AFNetworking/AFURLConnectionOperation.h +370 -0
- data/vendor/Pods/Headers/AFNetworking/AFXMLRequestOperation.h +89 -0
- data/vendor/Pods/Headers/AFNetworking/UIImageView+AFNetworking.h +78 -0
- data/vendor/Pods/Headers/CocoaLumberjack/ContextFilterLogFormatter.h +65 -0
- data/vendor/Pods/Headers/CocoaLumberjack/DDASLLogger.h +41 -0
- data/vendor/Pods/Headers/CocoaLumberjack/DDAbstractDatabaseLogger.h +102 -0
- data/vendor/Pods/Headers/CocoaLumberjack/DDFileLogger.h +334 -0
- data/vendor/Pods/Headers/CocoaLumberjack/DDLog.h +601 -0
- data/vendor/Pods/Headers/CocoaLumberjack/DDTTYLogger.h +167 -0
- data/vendor/Pods/Headers/CocoaLumberjack/DispatchQueueLogFormatter.h +116 -0
- data/vendor/Pods/Headers/NSData+MD5Digest/NSData+MD5Digest.h +18 -0
- data/vendor/Pods/Headers/Reachability/Reachability.h +109 -0
- data/vendor/Pods/Headers/YapDatabase/YapCache.h +90 -0
- data/vendor/Pods/Headers/YapDatabase/YapCollectionKey.h +20 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabase.h +547 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseConnection.h +447 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseConnectionState.h +29 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseDefaults.h +37 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseExtension.h +15 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseExtensionConnection.h +11 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseExtensionPrivate.h +440 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseExtensionTransaction.h +11 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseFilteredView.h +108 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseFilteredViewConnection.h +12 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseFilteredViewPrivate.h +19 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseFilteredViewTransaction.h +39 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseFullTextSearch.h +89 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseFullTextSearchConnection.h +32 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseFullTextSearchPrivate.h +69 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseFullTextSearchSnippetOptions.h +79 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseFullTextSearchTransaction.h +68 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseLogging.h +158 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseManager.h +17 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabasePrivate.h +424 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseQuery.h +42 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseSecondaryIndex.h +100 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseSecondaryIndexConnection.h +33 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseSecondaryIndexPrivate.h +73 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseSecondaryIndexSetup.h +33 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseSecondaryIndexTransaction.h +58 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseStatement.h +13 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseString.h +121 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseTransaction.h +541 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseView.h +186 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewChange.h +272 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewChangePrivate.h +94 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewConnection.h +115 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewMappings.h +825 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewMappingsPrivate.h +72 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewOptions.h +56 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewPage.h +36 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewPageMetadata.h +27 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewPrivate.h +153 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewRangeOptions.h +330 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewRangeOptionsPrivate.h +17 -0
- data/vendor/Pods/Headers/YapDatabase/YapDatabaseViewTransaction.h +447 -0
- data/vendor/Pods/Headers/YapDatabase/YapMemoryTable.h +74 -0
- data/vendor/Pods/Headers/YapDatabase/YapNull.h +17 -0
- data/vendor/Pods/Headers/YapDatabase/YapSet.h +41 -0
- data/vendor/Pods/Headers/YapDatabase/YapTouch.h +15 -0
- data/vendor/Pods/Headers/____Pods-AFNetworking-prefix.h +17 -0
- data/vendor/Pods/Headers/____Pods-CocoaLumberjack-prefix.h +5 -0
- data/vendor/Pods/Headers/____Pods-NSData+MD5Digest-prefix.h +5 -0
- data/vendor/Pods/Headers/____Pods-Reachability-prefix.h +5 -0
- data/vendor/Pods/Headers/____Pods-YapDatabase-prefix.h +5 -0
- data/vendor/Pods/Headers/____Pods-environment.h +38 -0
- data/vendor/Pods/Manifest.lock +24 -0
- data/vendor/Pods/NSData+MD5Digest/NSData+MD5Digest/NSData+MD5Digest.h +18 -0
- data/vendor/Pods/NSData+MD5Digest/NSData+MD5Digest/NSData+MD5Digest.m +39 -0
- data/vendor/Pods/NSData+MD5Digest/README.md +11 -0
- data/vendor/Pods/Pods-AFNetworking-Private.xcconfig +5 -0
- data/vendor/Pods/Pods-AFNetworking-dummy.m +5 -0
- data/vendor/Pods/Pods-AFNetworking-prefix.pch +17 -0
- data/vendor/Pods/Pods-AFNetworking.xcconfig +1 -0
- data/vendor/Pods/Pods-Acknowledgements.markdown +96 -0
- data/vendor/Pods/Pods-Acknowledgements.plist +142 -0
- data/vendor/Pods/Pods-CocoaLumberjack-Private.xcconfig +5 -0
- data/vendor/Pods/Pods-CocoaLumberjack-dummy.m +5 -0
- data/vendor/Pods/Pods-CocoaLumberjack-prefix.pch +5 -0
- data/vendor/Pods/Pods-CocoaLumberjack.xcconfig +0 -0
- data/vendor/Pods/Pods-NSData+MD5Digest-Private.xcconfig +5 -0
- data/vendor/Pods/Pods-NSData+MD5Digest-dummy.m +5 -0
- data/vendor/Pods/Pods-NSData+MD5Digest-prefix.pch +5 -0
- data/vendor/Pods/Pods-NSData+MD5Digest.xcconfig +0 -0
- data/vendor/Pods/Pods-Reachability-Private.xcconfig +5 -0
- data/vendor/Pods/Pods-Reachability-dummy.m +5 -0
- data/vendor/Pods/Pods-Reachability-prefix.pch +5 -0
- data/vendor/Pods/Pods-Reachability.xcconfig +1 -0
- data/vendor/Pods/Pods-YapDatabase-Private.xcconfig +5 -0
- data/vendor/Pods/Pods-YapDatabase-dummy.m +5 -0
- data/vendor/Pods/Pods-YapDatabase-prefix.pch +5 -0
- data/vendor/Pods/Pods-YapDatabase.xcconfig +1 -0
- data/vendor/Pods/Pods-dummy.m +5 -0
- data/vendor/Pods/Pods-environment.h +38 -0
- data/vendor/Pods/Pods-resources.sh +68 -0
- data/vendor/Pods/Pods.bridgesupport +5096 -0
- data/vendor/Pods/Pods.xcconfig +5 -0
- data/vendor/Pods/Pods.xcodeproj/project.pbxproj +5536 -0
- data/vendor/Pods/Reachability/LICENCE.txt +24 -0
- data/vendor/Pods/Reachability/README.md +65 -0
- data/vendor/Pods/Reachability/Reachability.h +109 -0
- data/vendor/Pods/Reachability/Reachability.m +527 -0
- data/vendor/Pods/YapDatabase/LICENSE.txt +18 -0
- data/vendor/Pods/YapDatabase/README.md +30 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/Internal/YapDatabaseFilteredViewPrivate.h +19 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredView.h +108 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredView.m +175 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredViewConnection.h +12 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredViewConnection.m +41 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredViewTransaction.h +39 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FilteredViews/YapDatabaseFilteredViewTransaction.m +966 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/Internal/YapDatabaseFullTextSearchPrivate.h +69 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearch.h +89 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearch.m +146 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearchConnection.h +32 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearchConnection.m +298 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearchSnippetOptions.h +79 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearchSnippetOptions.m +95 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearchTransaction.h +68 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/FullTextSearch/YapDatabaseFullTextSearchTransaction.m +1352 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/Internal/YapDatabaseExtensionPrivate.h +440 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/YapDatabaseExtension.h +15 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/YapDatabaseExtension.m +58 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/YapDatabaseExtensionConnection.h +11 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/YapDatabaseExtensionConnection.m +46 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/YapDatabaseExtensionTransaction.h +11 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Protocol/YapDatabaseExtensionTransaction.m +180 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/Internal/YapDatabaseSecondaryIndexPrivate.h +73 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndex.h +100 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndex.m +149 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndexConnection.h +33 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndexConnection.m +330 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndexSetup.h +33 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndexSetup.m +184 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndexTransaction.h +58 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/SecondaryIndex/YapDatabaseSecondaryIndexTransaction.m +1166 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewChangePrivate.h +94 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewMappingsPrivate.h +72 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewPage.h +36 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewPage.mm +296 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewPageMetadata.h +27 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewPageMetadata.m +28 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewPrivate.h +153 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Internal/YapDatabaseViewRangeOptionsPrivate.h +17 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Utilities/YapDatabaseViewChange.h +272 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Utilities/YapDatabaseViewChange.m +2494 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Utilities/YapDatabaseViewMappings.h +825 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Utilities/YapDatabaseViewMappings.m +1567 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Utilities/YapDatabaseViewRangeOptions.h +330 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/Utilities/YapDatabaseViewRangeOptions.m +141 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseView.h +186 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseView.m +191 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewConnection.h +115 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewConnection.m +897 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewOptions.h +56 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewOptions.m +27 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewTransaction.h +447 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Extensions/Views/YapDatabaseViewTransaction.m +4505 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapCache.h +90 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapCache.m +453 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseConnectionState.h +29 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseConnectionState.m +48 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseDefaults.h +37 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseDefaults.m +83 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseLogging.h +158 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseLogging.m +73 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseManager.h +17 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseManager.m +56 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabasePrivate.h +424 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseStatement.h +13 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseStatement.m +26 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapDatabaseString.h +121 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapMemoryTable.h +74 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapMemoryTable.m +603 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapNull.h +17 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapNull.m +31 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapTouch.h +15 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Internal/YapTouch.m +31 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Utilities/YapCollectionKey.h +20 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Utilities/YapCollectionKey.m +194 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Utilities/YapDatabaseQuery.h +42 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Utilities/YapDatabaseQuery.m +96 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Utilities/YapSet.h +41 -0
- data/vendor/Pods/YapDatabase/YapDatabase/Utilities/YapSet.m +82 -0
- data/vendor/Pods/YapDatabase/YapDatabase/YapDatabase.h +547 -0
- data/vendor/Pods/YapDatabase/YapDatabase/YapDatabase.m +2022 -0
- data/vendor/Pods/YapDatabase/YapDatabase/YapDatabaseConnection.h +447 -0
- data/vendor/Pods/YapDatabase/YapDatabase/YapDatabaseConnection.m +3874 -0
- data/vendor/Pods/YapDatabase/YapDatabase/YapDatabaseTransaction.h +541 -0
- data/vendor/Pods/YapDatabase/YapDatabase/YapDatabaseTransaction.m +5282 -0
- data/vendor/YapDatabaseRubyMotion/YapDatabaseRubyMotion.bridgesupport +16 -0
- data/vendor/YapDatabaseRubyMotion/YapDatabaseRubyMotion.h +13 -0
- data/vendor/YapDatabaseRubyMotion/YapDatabaseRubyMotion.m +20 -0
- data/yapper.gemspec +24 -0
- metadata +458 -0
@@ -0,0 +1,80 @@
|
|
1
|
+
module Kernel
|
2
|
+
def qualified_const_get(str)
|
3
|
+
path = str.to_s.split('::')
|
4
|
+
from_root = path[0].empty?
|
5
|
+
if from_root
|
6
|
+
from_root = []
|
7
|
+
path = path[1..-1]
|
8
|
+
else
|
9
|
+
start_ns = ((Class === self)||(Module === self)) ? self : self.class
|
10
|
+
from_root = start_ns.to_s.split('::')
|
11
|
+
end
|
12
|
+
until from_root.empty?
|
13
|
+
begin
|
14
|
+
return (from_root+path).inject(Object) { |ns,name| ns.const_get(name) }
|
15
|
+
rescue NameError
|
16
|
+
from_root.delete_at(-1)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
path.inject(Object) { |ns,name| ns.const_get(name) }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class Time
|
24
|
+
def self.parse(string)
|
25
|
+
return nil if string.nil?
|
26
|
+
|
27
|
+
unless time = NSDate.dateWithString(string)
|
28
|
+
# XXX Try iso8601 date
|
29
|
+
time = NSDate.dateWithString(string.gsub('T',' ').gsub('Z', ' +0000').gsub(/([-+]\d{2}:\d{2})/,' \1'))
|
30
|
+
end
|
31
|
+
time
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_iso8601
|
35
|
+
dateFormatter = NSDateFormatter.alloc.init
|
36
|
+
locale = NSLocale.alloc.initWithLocaleIdentifier("en_US_POSIX")
|
37
|
+
dateFormatter.setLocale(locale)
|
38
|
+
dateFormatter.setDateFormat("yyyy-MM-dd'T'HH:mm:ssZZZZZ")
|
39
|
+
|
40
|
+
dateFormatter.stringFromDate(self)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class Object
|
45
|
+
def as_json
|
46
|
+
self
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class Hash
|
51
|
+
def as_json
|
52
|
+
hash = self.class.new
|
53
|
+
self.each { |k,v| hash[k] = v.as_json }
|
54
|
+
hash
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class NSDictionary
|
59
|
+
def as_json
|
60
|
+
to_hash.as_json
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
class Array
|
65
|
+
def as_json
|
66
|
+
self.map { |v| v.as_json }
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
class NSArray
|
71
|
+
def as_json
|
72
|
+
self.map { |v| v.as_json }
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
class Time
|
77
|
+
def as_json
|
78
|
+
self.to_iso8601
|
79
|
+
end
|
80
|
+
end
|
data/lib/yapper/log.rb
ADDED
data/lib/yapper/sync.rb
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
motion_require 'extensions'
|
2
|
+
motion_require 'timestamps'
|
3
|
+
|
4
|
+
module Yapper::Sync
|
5
|
+
motion_require 'sync/data'
|
6
|
+
motion_require 'sync/event'
|
7
|
+
|
8
|
+
extend MotionSupport::Concern
|
9
|
+
|
10
|
+
included do
|
11
|
+
field :_synced_at
|
12
|
+
|
13
|
+
unless self.ancestors.include?(Yapper::Timestamps)
|
14
|
+
include Yapper::Timestamps
|
15
|
+
end
|
16
|
+
|
17
|
+
cattr_accessor :always
|
18
|
+
|
19
|
+
class << self
|
20
|
+
attr_accessor :attachments
|
21
|
+
end
|
22
|
+
self.attachments = {}
|
23
|
+
end
|
24
|
+
|
25
|
+
class << self
|
26
|
+
attr_accessor :base_url
|
27
|
+
attr_accessor :data_path
|
28
|
+
attr_accessor :attachment_path
|
29
|
+
attr_accessor :access_token
|
30
|
+
attr_accessor :max_failure_count
|
31
|
+
end
|
32
|
+
self.data_path = '/api/data'
|
33
|
+
self.attachment_path = '/api/attachment'
|
34
|
+
|
35
|
+
def self.configure(options)
|
36
|
+
self.access_token = options[:access_token]
|
37
|
+
self.max_failure_count = options[:max_failure_count] || 100
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.sync
|
41
|
+
Queue.sync
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.disabled(&block)
|
45
|
+
previous_value = Thread.current[:sync_disabled]
|
46
|
+
Thread.current[:sync_disabled] = true
|
47
|
+
yield
|
48
|
+
Thread.current[:sync_disabled] = previous_value
|
49
|
+
end
|
50
|
+
|
51
|
+
module ClassMethods
|
52
|
+
def sync(options={})
|
53
|
+
self.always = options[:always] || []
|
54
|
+
end
|
55
|
+
|
56
|
+
def attachment(name, options, &block)
|
57
|
+
raise ArgumentError unless options[:on] # XXX Use a consistent approach to checking hash params
|
58
|
+
|
59
|
+
self.attachments[name] = block
|
60
|
+
field(options[:on])
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def sync_as
|
65
|
+
attrs = self.changes.deep_dup
|
66
|
+
attrs = attrs.deep_delete_if { |k,v| k.to_s =~ /^_/ }
|
67
|
+
attrs
|
68
|
+
end
|
69
|
+
|
70
|
+
def synced?
|
71
|
+
!self._synced_at.nil?
|
72
|
+
end
|
73
|
+
|
74
|
+
def sync_paused?
|
75
|
+
Queue.paused?
|
76
|
+
end
|
77
|
+
|
78
|
+
def sync
|
79
|
+
@config ||= Config.new(self)
|
80
|
+
end
|
81
|
+
|
82
|
+
def sync_op
|
83
|
+
self.was_new? ? :create : :update
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
def perform_sync(changes)
|
89
|
+
Queue.process(self.class, self.id, self.sync_op, changes) unless changes.empty?
|
90
|
+
end
|
91
|
+
|
92
|
+
def sync_changes
|
93
|
+
perform_sync(self.previous_changes.merge(always_attributes)) unless Thread.current[:sync_disabled]
|
94
|
+
end
|
95
|
+
|
96
|
+
def always_attributes
|
97
|
+
{}.tap do |attrs|
|
98
|
+
self.always.each { |field| attrs[field] = self.send(field) }
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
class Config
|
103
|
+
def initialize(instance)
|
104
|
+
@instance = instance
|
105
|
+
@root = if parent
|
106
|
+
instance.send(parent)
|
107
|
+
else
|
108
|
+
instance
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def id
|
113
|
+
@root.id
|
114
|
+
end
|
115
|
+
|
116
|
+
def model
|
117
|
+
@root.model_name.capitalize
|
118
|
+
end
|
119
|
+
|
120
|
+
def delta
|
121
|
+
delta = @root.sync_as
|
122
|
+
unless @root == @instance
|
123
|
+
delta.merge!(@instance.model_name.pluralize => [@instance.sync_as.merge(:id => @instance.id)])
|
124
|
+
end
|
125
|
+
delta
|
126
|
+
end
|
127
|
+
|
128
|
+
private
|
129
|
+
|
130
|
+
def parent
|
131
|
+
@instance.class.relations[:belongs_to].find { |r| r.find { |k,v| v[:embedded] } }.try(:keys).try(:first)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
@@ -0,0 +1,194 @@
|
|
1
|
+
module Yapper::Sync
|
2
|
+
module Event
|
3
|
+
extend self
|
4
|
+
|
5
|
+
def attach(attachment)
|
6
|
+
params = {
|
7
|
+
:attachment => attachment.metadata
|
8
|
+
}
|
9
|
+
request = http_client.multipartFormRequestWithMethod(
|
10
|
+
'POST',
|
11
|
+
path: Yapper::Sync.attachment_path,
|
12
|
+
parameters: params.as_json,
|
13
|
+
constructingBodyWithBlock: lambda { |form_data|
|
14
|
+
form_data.appendPartWithFileData(UIImageJPEGRepresentation(attachment.data, 0.8),
|
15
|
+
name: "attachment[data]",
|
16
|
+
fileName: attachment.name,
|
17
|
+
mimeType: 'image/jpg')
|
18
|
+
})
|
19
|
+
|
20
|
+
if process(request)
|
21
|
+
Yapper::Log.info "[Yapper::Sync::Event][ATTACHMENT][#{attachment.id}]"
|
22
|
+
:success
|
23
|
+
else
|
24
|
+
:failure
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def create(instance, type)
|
29
|
+
params = {
|
30
|
+
:event => {
|
31
|
+
:model => instance.sync.model,
|
32
|
+
:model_id => instance.sync.id,
|
33
|
+
:type => type,
|
34
|
+
:delta => instance.sync.delta
|
35
|
+
}
|
36
|
+
}
|
37
|
+
if instance._attachments
|
38
|
+
params.merge!(:attachments => instance._attachments)
|
39
|
+
end
|
40
|
+
|
41
|
+
request = http_client.requestWithMethod(
|
42
|
+
'POST',
|
43
|
+
:path => Yapper::Sync.data_path,
|
44
|
+
:parameters => params.as_json)
|
45
|
+
|
46
|
+
if operation = process(request)
|
47
|
+
attrs = operation.responseJSON.deep_dup
|
48
|
+
Yapper::Log.info "[Yapper::Sync::Event][POST][#{instance.model_name}] #{attrs}"
|
49
|
+
|
50
|
+
new_attrs = {}
|
51
|
+
attrs.each do |k, v|
|
52
|
+
new_attrs[k] = v if instance.respond_to?(k) && instance.send(k).nil?
|
53
|
+
end
|
54
|
+
Yapper::Sync.disabled { instance.reload.update_attributes(new_attrs) }
|
55
|
+
:success
|
56
|
+
else
|
57
|
+
:failure
|
58
|
+
end
|
59
|
+
rescue Exception => e
|
60
|
+
if e.is_a?(NSException)
|
61
|
+
Yapper::Log.error "[Yapper::Sync][CRITICAL][#{instance.model_name}] #{e.reason}: #{e.callStackSymbols}"
|
62
|
+
else
|
63
|
+
Yapper::Log.error "[Yapper::Sync][CRITICAL][#{instance.model_name}] #{e.message}: #{e.backtrace.join('::')}"
|
64
|
+
end
|
65
|
+
:critical
|
66
|
+
end
|
67
|
+
|
68
|
+
def get
|
69
|
+
request = http_client.requestWithMethod(
|
70
|
+
'GET',
|
71
|
+
path: Yapper::Sync.data_path,
|
72
|
+
parameters: { :since => Yapper::Config.get(:last_event_id) }
|
73
|
+
)
|
74
|
+
|
75
|
+
instances = []
|
76
|
+
begin
|
77
|
+
if operation = process(request)
|
78
|
+
events = compact(operation.responseJSON)
|
79
|
+
return events if events.empty?
|
80
|
+
|
81
|
+
if events.first['model'] == 'User'
|
82
|
+
instances << handle(events.shift)
|
83
|
+
end
|
84
|
+
|
85
|
+
events.each do |event|
|
86
|
+
Yapper::DB.instance.execute do |txn|
|
87
|
+
instances << handle(event)
|
88
|
+
Yapper::Config.set(:last_event_id, event['created_at'])
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
rescue Exception => e
|
93
|
+
Yapper::Log.error "[Yapper::Sync::Event][FAILURE] #{e.message}: #{e.backtrace.join('::')}"
|
94
|
+
end
|
95
|
+
|
96
|
+
instances.compact
|
97
|
+
end
|
98
|
+
|
99
|
+
private
|
100
|
+
|
101
|
+
def handle(event)
|
102
|
+
Yapper::Log.info "[Yapper::Sync::Event][GET][#{event['type']}][#{event['model']}] #{event['delta']}"
|
103
|
+
|
104
|
+
model = Object.qualified_const_get(event['model'])
|
105
|
+
instance = nil
|
106
|
+
if event['type'] == 'create'
|
107
|
+
instance = model.new(event['delta']) # XXX shouldn't need to pass in delta
|
108
|
+
else
|
109
|
+
instance = model.find(event['model_id'])
|
110
|
+
end
|
111
|
+
|
112
|
+
if instance
|
113
|
+
# XXX Return array of updates vs. overwriting entire object
|
114
|
+
Yapper::Sync.disabled { instance.update_attributes(event['delta']) }
|
115
|
+
else
|
116
|
+
Yapper::Log.error "Model instance not found!. This is not good!"
|
117
|
+
end
|
118
|
+
|
119
|
+
instance
|
120
|
+
end
|
121
|
+
|
122
|
+
def compact(events)
|
123
|
+
event_lookup = {}; compact_events = []
|
124
|
+
events.each_with_index do |event, i|
|
125
|
+
case event['type']
|
126
|
+
when 'create'
|
127
|
+
event_lookup[event['model_id']] = compact_events.count
|
128
|
+
compact_events << event
|
129
|
+
when 'update'
|
130
|
+
if index = event_lookup[event['model_id']]
|
131
|
+
create_event = compact_events[index].dup
|
132
|
+
create_event['delta'] = recursive_merge(create_event['delta'], event['delta'])
|
133
|
+
compact_events[index] = create_event
|
134
|
+
else
|
135
|
+
compact_events << event
|
136
|
+
end
|
137
|
+
else
|
138
|
+
raise "Only 'update' AND 'create' supported"
|
139
|
+
end
|
140
|
+
end
|
141
|
+
compact_events
|
142
|
+
end
|
143
|
+
|
144
|
+
def http_client
|
145
|
+
@http_client ||= begin
|
146
|
+
client = AFHTTPClient.alloc.initWithBaseURL(NSURL.URLWithString(Yapper::Sync.base_url))
|
147
|
+
client.setParameterEncoding(AFJSONParameterEncoding)
|
148
|
+
client
|
149
|
+
end
|
150
|
+
@http_client.setAuthorizationHeaderWithToken(Yapper::Sync.access_token.call)
|
151
|
+
@http_client.setDefaultHeader('DEVICEID', value: UIDevice.currentDevice.identifierForVendor.UUIDString)
|
152
|
+
end
|
153
|
+
|
154
|
+
def process(request)
|
155
|
+
operation = AFJSONRequestOperation.alloc.initWithRequest(request)
|
156
|
+
|
157
|
+
operation.start
|
158
|
+
operation.waitUntilFinished
|
159
|
+
|
160
|
+
if operation.response && operation.response.statusCode >= 200 && operation.response.statusCode < 300
|
161
|
+
operation
|
162
|
+
else
|
163
|
+
Yapper::Log.error "[Yapper::Sync::Event][FAILURE] #{operation.error.localizedDescription}"
|
164
|
+
false
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
def recursive_merge(h1, h2)
|
169
|
+
return h1 unless h1.is_a?(Array) || h1.is_a?(Hash)
|
170
|
+
|
171
|
+
result = h1.dup; h2 = h2.dup
|
172
|
+
h2.each_pair do |k,v|
|
173
|
+
tv = h1[k]
|
174
|
+
if tv.is_a?(Hash) && v.is_a?(Hash)
|
175
|
+
result[k] = recursive_merge(tv, v)
|
176
|
+
elsif tv.is_a?(Array) && v.is_a?(Array)
|
177
|
+
v = v.dup
|
178
|
+
result[k] = tv.map do |_tv|
|
179
|
+
if match = v.find { |_v| _tv.is_a?(Hash) && _v.is_a?(Hash) && _tv['id'] == _v['id'] }
|
180
|
+
v.delete(match)
|
181
|
+
recursive_merge(_tv, match)
|
182
|
+
else
|
183
|
+
_tv
|
184
|
+
end
|
185
|
+
end
|
186
|
+
result[k] += v
|
187
|
+
else
|
188
|
+
result[k] = v
|
189
|
+
end
|
190
|
+
end
|
191
|
+
result
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
@@ -0,0 +1,164 @@
|
|
1
|
+
motion_require '../document.rb'
|
2
|
+
|
3
|
+
module Yapper::Sync
|
4
|
+
class Queue
|
5
|
+
include Yapper::Document
|
6
|
+
|
7
|
+
field :sync_class
|
8
|
+
field :sync_id
|
9
|
+
field :sync_changes
|
10
|
+
field :sync_type
|
11
|
+
field :created_at, :type => Time
|
12
|
+
field :failure_count
|
13
|
+
|
14
|
+
index :created_at
|
15
|
+
|
16
|
+
@@mutex = Mutex.new
|
17
|
+
@@notify_count = 0
|
18
|
+
|
19
|
+
@@queue = NSOperationQueue.alloc.init
|
20
|
+
@@queue.name = "#{NSBundle.mainBundle.bundleIdentifier}.yapper.sync"
|
21
|
+
@@queue.MaxConcurrentOperationCount = 1
|
22
|
+
@@queue.setSuspended(true)
|
23
|
+
|
24
|
+
@@reachability ||= begin
|
25
|
+
reachability = Reachability.reachabilityForInternetConnection
|
26
|
+
reachability.reachableBlock = lambda { |reachable| self.toggle_queue }
|
27
|
+
reachability.unreachableBlock = lambda { |reachable| self.toggle_queue }
|
28
|
+
reachability.reachableOnWWAN = true
|
29
|
+
reachability.startNotifier
|
30
|
+
reachability
|
31
|
+
end
|
32
|
+
|
33
|
+
NSNotificationCenter.defaultCenter.addObserver(self,
|
34
|
+
selector: 'onBackground',
|
35
|
+
name: UIApplicationDidEnterBackgroundNotification,
|
36
|
+
object: nil)
|
37
|
+
|
38
|
+
|
39
|
+
def self.start
|
40
|
+
operation = NSBlockOperation.blockOperationWithBlock lambda {
|
41
|
+
job_started
|
42
|
+
jobs = self.where({}, :order => { :created_at => :asc })
|
43
|
+
Yapper::Log.info "[Yapper::Sync][START] Processing #{jobs.count} jobs"
|
44
|
+
jobs.each { |job| handle(job) }
|
45
|
+
@@queue.setSuspended(!@@reachability.isReachable)
|
46
|
+
job_ended
|
47
|
+
}
|
48
|
+
self.toggle_queue
|
49
|
+
@@queue.addOperation(operation)
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.onBackground
|
53
|
+
@@background_task = UIApplication.sharedApplication.beginBackgroundTaskWithExpirationHandler(nil)
|
54
|
+
operation = NSBlockOperation.blockOperationWithBlock lambda {
|
55
|
+
UIApplication.sharedApplication.endBackgroundTask(@@background_task) unless @@background_task == UIBackgroundTaskInvalid
|
56
|
+
@@background_task = UIBackgroundTaskInvalid
|
57
|
+
}
|
58
|
+
@@queue.addOperation(operation)
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.paused?
|
62
|
+
@@queue.isSuspended
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.sync
|
66
|
+
return false if self.paused?
|
67
|
+
|
68
|
+
operation = NSBlockOperation.blockOperationWithBlock lambda {
|
69
|
+
job_started
|
70
|
+
Yapper::Sync::Event.get.each { |instance| self.notification(instance, 'success') }
|
71
|
+
job_ended
|
72
|
+
}
|
73
|
+
@@queue.addOperation(operation)
|
74
|
+
|
75
|
+
true
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.process(klass, id, type, changes)
|
79
|
+
instance = klass.find(id)
|
80
|
+
self.notification(instance, 'start')
|
81
|
+
|
82
|
+
job = self.create(:sync_class => instance.class.to_s,
|
83
|
+
:sync_id => instance.id,
|
84
|
+
:sync_changes => changes,
|
85
|
+
:sync_type => type.to_s,
|
86
|
+
:created_at => Time.now.utc,
|
87
|
+
:failure_count => 0)
|
88
|
+
handle(job)
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.handle(job)
|
92
|
+
operation = NSBlockOperation.blockOperationWithBlock lambda {
|
93
|
+
job_started
|
94
|
+
instance = Object.qualified_const_get(job.sync_class).find(job.sync_id)
|
95
|
+
instance.changes = job.sync_changes
|
96
|
+
job.attempt(instance, job.sync_type)
|
97
|
+
job_ended
|
98
|
+
}
|
99
|
+
self.toggle_queue
|
100
|
+
|
101
|
+
@@queue.addOperation(operation)
|
102
|
+
nil
|
103
|
+
end
|
104
|
+
|
105
|
+
def attempt(instance, type)
|
106
|
+
case event(instance, type)
|
107
|
+
when :success
|
108
|
+
Yapper::Sync.disabled { instance.update_attributes(:_synced_at => Time.now) }
|
109
|
+
self.destroy
|
110
|
+
self.class.notification(instance, 'success')
|
111
|
+
when :failure
|
112
|
+
if self.failure_count < Yapper::Sync.max_failure_count
|
113
|
+
sleep 2 ** (self.failure_count)
|
114
|
+
self.failure_count += 1
|
115
|
+
self.save
|
116
|
+
attempt(instance, type)
|
117
|
+
self.class.notification(instance, 'retry')
|
118
|
+
else
|
119
|
+
Yapper::Log.error "[Yapper::Queue][CRITICAL] Job #{self.sync_class}:#{self.sync_id} exceeded failure threshold and has been removed"
|
120
|
+
self.destroy
|
121
|
+
self.class.notification(instance, 'failure')
|
122
|
+
end
|
123
|
+
when :critical
|
124
|
+
self.destroy
|
125
|
+
self.class.notification(instance, 'failure')
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
private
|
130
|
+
|
131
|
+
def event(instance, type)
|
132
|
+
if instance.is_a?(Yapper::Attachment)
|
133
|
+
Yapper::Sync::Event.attach(instance)
|
134
|
+
else
|
135
|
+
Yapper::Sync::Event.create(instance, type)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def self.toggle_queue
|
140
|
+
was_paused = self.paused?
|
141
|
+
@@queue.setSuspended(!@@reachability.isReachable)
|
142
|
+
if was_paused != self.paused?
|
143
|
+
NSNotificationCenter.defaultCenter.postNotificationName("yapper:sync:paused", object: true, userInfo: nil) if self.paused?
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def self.notification(instance, type)
|
148
|
+
NSNotificationCenter.defaultCenter.postNotificationName("yapper:#{instance.model_name}:sync:#{type}", object: instance , userInfo: nil)
|
149
|
+
end
|
150
|
+
|
151
|
+
def self.job_started
|
152
|
+
if @@queue.operationCount == 1
|
153
|
+
@@job_started_at = Time.now
|
154
|
+
NSNotificationCenter.defaultCenter.postNotificationName("yapper:sync:start", object: true , userInfo: nil)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def self.job_ended
|
159
|
+
if @@queue.operationCount == 1
|
160
|
+
NSNotificationCenter.defaultCenter.postNotificationName("yapper:sync:end", object: Time.now - @@job_started_at , userInfo: nil)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|