parse-stack-async 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 94d9c71af58dc061d67d03bfdfaa7db2be5bbef6
4
+ data.tar.gz: d1c020f62f64081b9d277513143b1b26ae493c62
5
+ SHA512:
6
+ metadata.gz: 5f41fd7996bdcb6c1b73076de5d0ed15b629b8be2b42f2863f060ed24d69c41e5f34ec40e330b63dab6fb95edb4689f563dba77fdb87aa3d3bbfad2aadded68e
7
+ data.tar.gz: 06b0c10fa6455fd154157268391ba14dc0e76a4b7f8653248894adba98817b2c7fc64fc86bf968c91e952b60962a7be5c6e868d3f0436f59960cfcff876b272c
data/.gitignore ADDED
@@ -0,0 +1,44 @@
1
+ .DS_Store
2
+ *.gem
3
+ *.rbc
4
+ /.config
5
+ /coverage/
6
+ /InstalledFiles
7
+ /pkg/
8
+ /spec/reports/
9
+ /spec/examples.txt
10
+ /test/tmp/
11
+ /test/version_tmp/
12
+ /tmp/
13
+
14
+ ## Specific to RubyMotion:
15
+ .dat*
16
+ .repl_history
17
+ build/
18
+
19
+ ## Documentation cache and generated files:
20
+ /.yardoc/
21
+ /_yardoc/
22
+ /doc/
23
+ /rdoc/
24
+
25
+ ## Environment normalization:
26
+ /.bundle/
27
+ /vendor/bundle
28
+ /lib/bundler/man/
29
+
30
+ # for a library or gem, you might want to ignore these files since the code is
31
+ # intended to run in multiple environments; otherwise, check them in:
32
+ # Gemfile.lock
33
+ # .ruby-version
34
+ # .ruby-gemset
35
+
36
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
37
+ .rvmrc
38
+ bin/.env
39
+ bin/config.json
40
+ .byebug_history
41
+ /.env
42
+ /node_modules
43
+ /bin/parse-dashboard-config.json
44
+ logs
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in parse-stack-async.gemspec
4
+ gemspec
5
+
6
+ group :test, :development do
7
+ gem 'dotenv'
8
+ gem 'rake'
9
+ gem 'byebug'
10
+ gem 'minitest'
11
+ gem 'pry'
12
+ gem 'pry-stack_explorer'
13
+ gem 'pry-nav'
14
+ gem 'yard'
15
+ gem 'redcarpet'
16
+ gem 'thin'
17
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,126 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ parse-stack-async (0.1.0)
5
+ parse-stack (~> 1, >= 1.6)
6
+ sucker_punch (~> 2)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actionpack (5.0.1)
12
+ actionview (= 5.0.1)
13
+ activesupport (= 5.0.1)
14
+ rack (~> 2.0)
15
+ rack-test (~> 0.6.3)
16
+ rails-dom-testing (~> 2.0)
17
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
18
+ actionview (5.0.1)
19
+ activesupport (= 5.0.1)
20
+ builder (~> 3.1)
21
+ erubis (~> 2.7.0)
22
+ rails-dom-testing (~> 2.0)
23
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
24
+ active_model_serializers (0.10.4)
25
+ actionpack (>= 4.1, < 6)
26
+ activemodel (>= 4.1, < 6)
27
+ case_transform (>= 0.2)
28
+ jsonapi (= 0.1.1.beta6)
29
+ activemodel (5.0.1)
30
+ activesupport (= 5.0.1)
31
+ activesupport (5.0.1)
32
+ concurrent-ruby (~> 1.0, >= 1.0.2)
33
+ i18n (~> 0.7)
34
+ minitest (~> 5.1)
35
+ tzinfo (~> 1.1)
36
+ binding_of_caller (0.7.2)
37
+ debug_inspector (>= 0.0.1)
38
+ builder (3.2.2)
39
+ byebug (9.0.6)
40
+ case_transform (0.2)
41
+ activesupport
42
+ coderay (1.1.1)
43
+ concurrent-ruby (1.0.4)
44
+ daemons (1.2.4)
45
+ debug_inspector (0.0.2)
46
+ dotenv (2.1.1)
47
+ erubis (2.7.0)
48
+ eventmachine (1.2.1)
49
+ faraday (0.10.1)
50
+ multipart-post (>= 1.2, < 3)
51
+ faraday_middleware (0.10.1)
52
+ faraday (>= 0.7.4, < 1.0)
53
+ i18n (0.7.0)
54
+ jsonapi (0.1.1.beta6)
55
+ jsonapi-parser (= 0.1.1.beta3)
56
+ jsonapi-renderer (= 0.1.1.beta1)
57
+ jsonapi-parser (0.1.1.beta3)
58
+ jsonapi-renderer (0.1.1.beta1)
59
+ loofah (2.0.3)
60
+ nokogiri (>= 1.5.9)
61
+ method_source (0.8.2)
62
+ mini_portile2 (2.1.0)
63
+ minitest (5.10.1)
64
+ moneta (0.8.1)
65
+ multipart-post (2.0.0)
66
+ nokogiri (1.7.0.1)
67
+ mini_portile2 (~> 2.1.0)
68
+ parallel (1.10.0)
69
+ parse-stack (1.6.7)
70
+ active_model_serializers (>= 0.9, < 1)
71
+ activemodel (>= 4.2.1, < 6)
72
+ activesupport (>= 4.2.1, < 6)
73
+ faraday (>= 0.8, < 1)
74
+ faraday_middleware (>= 0.9, < 1)
75
+ moneta (>= 0.7, < 1)
76
+ parallel (>= 1.6, < 2)
77
+ rack (< 3)
78
+ pry (0.10.4)
79
+ coderay (~> 1.1.0)
80
+ method_source (~> 0.8.1)
81
+ slop (~> 3.4)
82
+ pry-nav (0.2.4)
83
+ pry (>= 0.9.10, < 0.11.0)
84
+ pry-stack_explorer (0.4.9.2)
85
+ binding_of_caller (>= 0.7)
86
+ pry (>= 0.9.11)
87
+ rack (2.0.1)
88
+ rack-test (0.6.3)
89
+ rack (>= 1.0)
90
+ rails-dom-testing (2.0.2)
91
+ activesupport (>= 4.2.0, < 6.0)
92
+ nokogiri (~> 1.6)
93
+ rails-html-sanitizer (1.0.3)
94
+ loofah (~> 2.0)
95
+ rake (12.0.0)
96
+ redcarpet (3.4.0)
97
+ slop (3.6.0)
98
+ sucker_punch (2.0.2)
99
+ concurrent-ruby (~> 1.0.0)
100
+ thin (1.7.0)
101
+ daemons (~> 1.0, >= 1.0.9)
102
+ eventmachine (~> 1.0, >= 1.0.4)
103
+ rack (>= 1, < 3)
104
+ thread_safe (0.3.5)
105
+ tzinfo (1.2.2)
106
+ thread_safe (~> 0.1)
107
+ yard (0.9.7)
108
+
109
+ PLATFORMS
110
+ ruby
111
+
112
+ DEPENDENCIES
113
+ byebug
114
+ dotenv
115
+ minitest
116
+ parse-stack-async!
117
+ pry
118
+ pry-nav
119
+ pry-stack_explorer
120
+ rake
121
+ redcarpet
122
+ thin
123
+ yard
124
+
125
+ BUNDLED WITH
126
+ 1.13.6
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014-2017 Anthony Persaud, Modernistik LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # Parse Stack - Async
2
+
3
+ This [Parse Stack](https://github.com/modernistik/parse-stack) plugin adds support for background saves and deletes, similar to the use of `saveInBackground` and `saveEventually` in other [Parse Server](https://github.com/ParsePlatform/parse-server) SDKs. It utilizes [SuckerPunch](https://github.com/brandonhilkert/sucker_punch) to perform the asynchronous processing of the API operation in a separate queue.
4
+
5
+ [![Gitter](https://badges.gitter.im/modernistik/parse-stack.svg)](https://gitter.im/modernistik/parse-stack?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'parse-stack-async'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install parse-stack-async
22
+
23
+ ## Usage
24
+ This plugin for Parse Stack allows you to save and delete objects in an asynchronous manner, without blocking the main thread of an application. This is useful when saving objects in a web application like Rails.
25
+
26
+ This plugin adds two methods to all `Parse::Object` subclasses: `save_eventually` and `destroy_eventually`, which mimic the same API in the mobile SDKs for Parse. These take an optional block that will provide you information whether it was successful in performing the corresponding operation.
27
+
28
+ ```ruby
29
+
30
+ require 'parse/stack'
31
+ require 'parse/stack/async'
32
+
33
+ object = Parse::User.first # get a user
34
+ object.username = 'newUserName'
35
+
36
+ # saves object in a background thread.
37
+ object.save_eventually do |success|
38
+ puts "Successfully saved in Parse!" if success
39
+ end
40
+
41
+ # Or delete asynchronously
42
+ anotherObject.destroy_eventually do |success|
43
+ puts "Deleted object from Parse!" if success
44
+ end
45
+
46
+ ```
47
+
48
+ ## Contributing
49
+
50
+ Bug reports and pull requests are welcome on GitHub at https://github.com/modernistik/parse-stack-async.
51
+
52
+ ## License
53
+
54
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << 'lib/parse/stack'
7
+ t.test_files = FileList['test/lib/**/*_test.rb']
8
+ t.warning = false
9
+ t.verbose = true
10
+ end
11
+ task :default => :test
12
+
13
+
14
+ task :console do
15
+ exec './bin/console'
16
+ end
17
+ task :c => :console
18
+
19
+ desc 'List undocumented methods'
20
+ task 'yard:stats' do
21
+ exec 'yard stats --list-undoc'
22
+ end
23
+
24
+ desc 'Start the yard server'
25
+ task 'yard' do
26
+ exec 'rm -rf ./yard && yard server --reload'
27
+ end
data/bin/console ADDED
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require 'dotenv'
5
+ require 'byebug'
6
+ require "parse/stack/async"
7
+ Dotenv.load
8
+
9
+ Parse.setup # cache: 'redis://localhost:6379'
10
+
11
+ puts "[ParseServerURL] #{Parse.client.server_url}"
12
+ puts "[ParseAppID] #{Parse.client.app_id}"
13
+ Parse.auto_generate_models!.each do |model|
14
+ puts "Generated #{model}"
15
+ end
16
+ # You can add fixtures and/or initialization code here to make experimenting
17
+ # with your gem easier. You can also use a different console, if you like.
18
+
19
+ # (If you use this, don't forget to add pry to your Gemfile!)
20
+ require "pry"
21
+ Pry.start
22
+
23
+ # require "irb"
24
+ # IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,113 @@
1
+ require 'sucker_punch'
2
+ require 'active_support'
3
+ require 'active_support/core_ext'
4
+ require 'parse/stack'
5
+ require "parse/stack/async/version"
6
+
7
+ # This module is defined in the Parse-Stack gem.
8
+ # @see {Parse::Stack}
9
+ module Parse
10
+ # This module is defined in the Parse-Stack gem.
11
+ # @see {Parse::Stack}
12
+ module Stack
13
+ # This is a plugin to Parse Stack that allows objects to be saved and deleted in a
14
+ # background thread, while providing you a callback block.
15
+ module Async
16
+
17
+ # A class to support running blocks in serial queue on a background thread.
18
+ # @!visibility private
19
+ class SerialDispatchQueue
20
+ include SuckerPunch::Job
21
+ workers 1 # serial queue
22
+ # @!visibility private
23
+ def perform(block = nil)
24
+ block.call() if block.respond_to?(:call)
25
+ block = nil # help gc
26
+ end
27
+ end # Serial
28
+
29
+ # A class to support running blocks in concurrent queue on a background thread.
30
+ # @!visibility private
31
+ class ParallelDispatchQueue
32
+ include SuckerPunch::Job
33
+ # @!visibility private
34
+ def perform(block = nil)
35
+ block.call() if block.respond_to?(:call)
36
+ block = nil # help gc
37
+ end
38
+ end # Parallel
39
+
40
+ # Helper method to run a block on a background thread.
41
+ # @param type [Symbol] the queue to use when dispatching the block.
42
+ # * :serial - add the request to a serial queue.
43
+ # * :parallel - add the request to a concurrent queue.
44
+ def self.run(type = :parallel)
45
+ raise "You need to pass a block to async." unless block_given?
46
+ if type == :parallel
47
+ ParallelDispatchQueue.perform_async Proc.new
48
+ else
49
+ SerialDispatchQueue.perform_async Proc.new
50
+ end
51
+ end
52
+
53
+ end # Async
54
+ end # Stack
55
+
56
+ # Additions to the Parse::Object class.
57
+ class Object < Pointer
58
+ # Adds support for saving a Parse object in the background.
59
+ # @example
60
+ # object.save_eventually do |success|
61
+ # puts "Saved successfully" if success
62
+ # end
63
+ # @yield A block to call after the save has completed.
64
+ # @yieldparam [Boolean] success whether the save was successful.
65
+ # @return [Boolean] whether the job was enqueued.
66
+ def save_eventually
67
+ block = block_given? ? Proc.new : nil
68
+ _self = self
69
+ Parse::Stack::Async.run do
70
+ begin
71
+ result = true
72
+ _self.save!
73
+ rescue => e
74
+ result = false
75
+ puts "[SaveEventually] Failed for object #{_self.parse_class}##{_self.id}: #{e}"
76
+ ensure
77
+ block.call(result) if block
78
+ block = nil
79
+ _self = nil
80
+ end # begin
81
+ end # do
82
+ end # save_eventually
83
+
84
+ # Adds support for deleting a Parse object in the background.
85
+ # @example
86
+ # object.destroy_eventually do |success|
87
+ # puts 'Deleted successfully' if success
88
+ # end
89
+ # @yield A block to call after the deletion has completed.
90
+ # @yieldparam [Boolean] success whether the save was successful.'
91
+ # @return [Boolean] whether the job was enqueued.
92
+ def destroy_eventually
93
+ block = block_given? ? Proc.new : nil
94
+ _self = self
95
+ Parse::Stack::Async.run do
96
+ begin
97
+ result = true
98
+ _self.destroy
99
+ rescue => e
100
+ result = false
101
+ puts "[DestroyEventually] Failed for object #{_self.parse_class}##{_self.id}: #{e}"
102
+ ensure
103
+ block.call(result) if block
104
+ block = nil
105
+ _self = nil
106
+ end # begin
107
+ end # do
108
+ end # destroy_eventually
109
+ alias_method :delete_eventually, :destroy_eventually
110
+
111
+ end # Object
112
+
113
+ end # Parse
@@ -0,0 +1,8 @@
1
+ module Parse
2
+ module Stack
3
+ module Async
4
+ # Version number for this gem
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,44 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'parse/stack/async/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "parse-stack-async"
8
+ spec.version = Parse::Stack::Async::VERSION
9
+ spec.authors = ["Anthony Persaud"]
10
+ spec.email = ["persaud@modernistik.com"]
11
+
12
+ spec.summary = %q{Parse Server operations asynchronously.}
13
+ spec.description = %q{Perform Parse Server operations asynchronously. This is a plugin to the Parse Stack that allows for CRUD operations to be done in a background thread.}
14
+ spec.homepage = "https://github.com/modernistik/parse-stack-async"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against " \
23
+ # "public gem pushes."
24
+ # end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "bin"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_runtime_dependency "parse-stack", ['~> 1', '>= 1.6']
34
+ spec.add_runtime_dependency "sucker_punch", '~> 2'
35
+ end
36
+
37
+ ## Development
38
+ # After checking out the repo, run `bin/setup` to install dependencies. You can
39
+ # also run `bin/console` for an interactive prompt that will allow you to experiment.
40
+ #
41
+ # To install this gem onto your local machine, run `bundle exec rake install`.
42
+ # To release a new version, update the version number in `version.rb`, and then run
43
+ # `bundle exec rake release`, which will create a git tag for the version,
44
+ # push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: parse-stack-async
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Anthony Persaud
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-01-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: parse-stack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: '1.6'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '1.6'
33
+ - !ruby/object:Gem::Dependency
34
+ name: sucker_punch
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '2'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '2'
47
+ description: Perform Parse Server operations asynchronously. This is a plugin to the
48
+ Parse Stack that allows for CRUD operations to be done in a background thread.
49
+ email:
50
+ - persaud@modernistik.com
51
+ executables: []
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - ".gitignore"
56
+ - Gemfile
57
+ - Gemfile.lock
58
+ - LICENSE.txt
59
+ - README.md
60
+ - Rakefile
61
+ - bin/console
62
+ - bin/setup
63
+ - lib/parse/stack/async.rb
64
+ - lib/parse/stack/async/version.rb
65
+ - parse-stack-async.gemspec
66
+ homepage: https://github.com/modernistik/parse-stack-async
67
+ licenses:
68
+ - MIT
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 2.6.8
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: Parse Server operations asynchronously.
90
+ test_files: []