activeasync 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+
7
+ before_script: "sh -c 'cd spec/dummy && bundle exec rake db:migrate'"
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.0.2 (2012-01-26)
2
+ * railtie for initializing activeasync in rails
3
+ * rspec module for use in testing
4
+
1
5
  ## 0.0.1 (2012-01-26)
2
6
 
3
7
  * async method: interface for sending methods with arguments to Resque
data/Gemfile CHANGED
@@ -1,4 +1,3 @@
1
- source "http://rubygems.org"
1
+ source :rubygems
2
2
 
3
- # Specify your gem's dependencies in activeasync.gemspec
4
3
  gemspec
data/README.md ADDED
@@ -0,0 +1,110 @@
1
+ # ActiveAsync
2
+
3
+ ActiveAsync aims to provide an interface for easily setting up ActiveRecord objects
4
+ and ruby classes to run methods asynchronously.
5
+
6
+ ActiveAsync currently depends on Resque and ActiveSupport.
7
+
8
+ [![Build Status](https://secure.travis-ci.org/challengepost/activeasync.png)](http://travis-ci.org/challengepost/activeasync)
9
+
10
+ ## Install
11
+
12
+ In your Gemfile
13
+
14
+ gem "activeasync"
15
+
16
+ Or via command line
17
+
18
+ gem install activeasync
19
+
20
+
21
+ ## Usage
22
+
23
+ Background class methods
24
+
25
+ ``` ruby
26
+ require 'active_async'
27
+
28
+ class HeavyLifter
29
+ include ActiveAsync::Async
30
+
31
+ def lift(*stuff)
32
+ # heavy lifting
33
+ end
34
+
35
+ end
36
+
37
+ HeavyLifter.async(:lift, 1, 2, 3)
38
+ ```
39
+
40
+ With ActiveRecord and Rails
41
+
42
+ ``` ruby
43
+ # config/application.rb
44
+ require 'active_async/railtie'
45
+
46
+ # app/models/risky_business.rb
47
+ class RiskyBusiness < ActiveRecord::Base
48
+
49
+ def party_time
50
+ # all night long
51
+ end
52
+
53
+ end
54
+
55
+ business = RiskyBusiness.last
56
+ business.async(:party_time) # runs business#party_time asynchronously
57
+ ```
58
+
59
+ Run callbacks asynchronously
60
+
61
+ ``` ruby
62
+ class LateNite < ActiveRecord::Base
63
+ after_save :drive_home, :async => true
64
+
65
+ def drive_home
66
+ # traffic jam
67
+ end
68
+
69
+ end
70
+
71
+ late_nite = LateNite.last
72
+ late_nite.save # runs late_night#drive_home asynchronously after save
73
+ ```
74
+
75
+ ## RSpec
76
+
77
+ ActiveAsync comes with some helpers support for RSpec.
78
+
79
+ To remove Resque dependency from some of your specs, use the :stub_resque option in
80
+ selectd spec blocks. Async methods will run in the foreground.
81
+
82
+ ``` ruby
83
+ # spec/spec_helper.rb
84
+
85
+ require 'active_async/rspec'
86
+
87
+ # spec/models/late_nite_spec.rb
88
+
89
+ it "drive home after late nite save", :stub_resque do
90
+ # all methods run in foreground
91
+ end
92
+ ```
93
+
94
+ You can also manually set the Async background adapter to `ActiveAsync::FakeResque` or
95
+ any similar module/class that responds to `#enqueue(*args)`:
96
+
97
+ ``` ruby
98
+ before do
99
+ ActiveAsync.background = ActiveAsync::FakeResque
100
+ end
101
+ ```
102
+
103
+ ## Contributing
104
+
105
+ To contribute to activeasync, clone the project and submit pull requests in a branch with tests.
106
+
107
+ To run tests, install the bundle and migrate the test database:
108
+
109
+ $ bundle
110
+ $ cd spec/dummy && bundle exec rake db:migrate db:test:prepare
data/activeasync.gemspec CHANGED
@@ -26,6 +26,5 @@ Gem::Specification.new do |s|
26
26
  s.add_development_dependency "rails", "~> 3.0"
27
27
  s.add_development_dependency "rspec", "~> 2.8.0"
28
28
  s.add_development_dependency "database_cleaner", "~> 0.7.0"
29
- s.add_development_dependency "ruby-debug"
30
29
  s.add_development_dependency "sqlite3"
31
30
  end
data/lib/active_async.rb CHANGED
@@ -3,7 +3,6 @@ require "active_support/concern"
3
3
  require "active_async/version"
4
4
  require "active_async/async"
5
5
  require "active_async/callbacks"
6
- require "active_async/active_record"
7
6
 
8
7
  module ActiveAsync
9
8
  extend self
@@ -0,0 +1,12 @@
1
+ require "rails"
2
+ require "active_record"
3
+ require "active_async"
4
+ require "active_async/active_record"
5
+
6
+ module ActiveAsync
7
+ class Railtie < Rails::Railtie
8
+ initializer "active_async.configure_rails_initialization" do
9
+ ::ActiveRecord::Base.send :include, ActiveAsync::ActiveRecord
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ require 'active_async'
2
+ require 'active_async/fake_resque'
3
+
4
+ RSpec.configure do |config|
5
+ config.treat_symbols_as_metadata_keys_with_true_values = true
6
+ config.before(:each, :stub_resque) do |example|
7
+ ActiveAsync.background = ActiveAsync::FakeResque
8
+ end
9
+
10
+ config.after(:each, :stub_resque) do |example|
11
+ ActiveAsync.background = Resque
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module ActiveAsync
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -5,8 +5,11 @@ describe ActiveAsync::Callbacks do
5
5
  describe "active model example", :stub_resque do
6
6
  class DummyBase
7
7
  extend ActiveModel::Callbacks
8
+ include ActiveAsync::Async
9
+ include ActiveAsync::Callbacks
8
10
 
9
11
  define_model_callbacks :save, :update, :create
12
+ define_async_callbacks :after_save, :after_update, :after_create
10
13
 
11
14
  def id; object_id; end
12
15
  def find(id); end
@@ -14,11 +17,6 @@ describe ActiveAsync::Callbacks do
14
17
  def save; run_callbacks :save; end
15
18
  def update; run_callbacks :update; end
16
19
  def create; run_callbacks :create; end
17
-
18
- include ActiveAsync::Async
19
- include ActiveAsync::Callbacks
20
-
21
- define_async_callbacks :after_save, :after_update, :after_create
22
20
  end
23
21
 
24
22
  class DummyUser < DummyBase
@@ -106,7 +104,7 @@ describe ActiveAsync::Callbacks do
106
104
  it "should update method name and define async method when async is true" do
107
105
  extracted_args = DummyUser.send(:extract_async_methods, [:method_name, {:async => true}])
108
106
  extracted_args.should == ["async_method_name", {}]
109
- DummyUser.instance_methods.should include("async_method_name")
107
+ DummyUser.instance_methods.map(&:to_sym).should include(:async_method_name)
110
108
  end
111
109
  end
112
110
 
@@ -4,10 +4,12 @@ require File.expand_path('../boot', __FILE__)
4
4
  require "active_record/railtie"
5
5
  require "action_controller/railtie"
6
6
  require "action_mailer/railtie"
7
- require "active_resource/railtie"
7
+ # require "active_resource/railtie"
8
8
  # require "sprockets/railtie"
9
9
  # require "rails/test_unit/railtie"
10
10
 
11
+ require 'active_async/railtie'
12
+
11
13
  if defined?(Bundler)
12
14
  # If you precompile assets before deploying to production, use this line
13
15
  Bundler.require(*Rails.groups(:assets => %w(development test)))
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  # This file is auto-generated from the current state of the database. Instead
2
3
  # of editing this file, please use the migrations feature of Active Record to
3
4
  # incrementally modify your database, and then regenerate this schema definition.
data/spec/spec_helper.rb CHANGED
@@ -6,7 +6,7 @@ ENV["RAILS_ENV"] ||= 'test'
6
6
 
7
7
  require 'rspec/autorun'
8
8
  require 'database_cleaner'
9
- require 'active_async'
9
+ require 'active_async/rspec'
10
10
 
11
11
  require File.expand_path("../dummy/config/environment.rb", __FILE__)
12
12
 
metadata CHANGED
@@ -1,141 +1,96 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: activeasync
3
- version: !ruby/object:Gem::Version
4
- hash: 29
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 1
10
- version: 0.0.1
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Ross Kaffenberger
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-01-27 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- version_requirements: &id001 !ruby/object:Gem::Requirement
22
- none: false
23
- requirements:
24
- - - ~>
25
- - !ruby/object:Gem::Version
26
- hash: 27
27
- segments:
28
- - 1
29
- - 10
30
- version: "1.10"
31
- requirement: *id001
32
- prerelease: false
12
+ date: 2012-01-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
33
15
  name: resque
34
- type: :runtime
35
- - !ruby/object:Gem::Dependency
36
- version_requirements: &id002 !ruby/object:Gem::Requirement
16
+ requirement: &70145636764700 !ruby/object:Gem::Requirement
37
17
  none: false
38
- requirements:
18
+ requirements:
39
19
  - - ~>
40
- - !ruby/object:Gem::Version
41
- hash: 7
42
- segments:
43
- - 3
44
- - 0
45
- version: "3.0"
46
- requirement: *id002
20
+ - !ruby/object:Gem::Version
21
+ version: '1.10'
22
+ type: :runtime
47
23
  prerelease: false
24
+ version_requirements: *70145636764700
25
+ - !ruby/object:Gem::Dependency
48
26
  name: activesupport
49
- type: :runtime
50
- - !ruby/object:Gem::Dependency
51
- version_requirements: &id003 !ruby/object:Gem::Requirement
27
+ requirement: &70145636764160 !ruby/object:Gem::Requirement
52
28
  none: false
53
- requirements:
29
+ requirements:
54
30
  - - ~>
55
- - !ruby/object:Gem::Version
56
- hash: 7
57
- segments:
58
- - 3
59
- - 0
60
- version: "3.0"
61
- requirement: *id003
31
+ - !ruby/object:Gem::Version
32
+ version: '3.0'
33
+ type: :runtime
62
34
  prerelease: false
35
+ version_requirements: *70145636764160
36
+ - !ruby/object:Gem::Dependency
63
37
  name: rails
64
- type: :development
65
- - !ruby/object:Gem::Dependency
66
- version_requirements: &id004 !ruby/object:Gem::Requirement
38
+ requirement: &70145636763680 !ruby/object:Gem::Requirement
67
39
  none: false
68
- requirements:
40
+ requirements:
69
41
  - - ~>
70
- - !ruby/object:Gem::Version
71
- hash: 47
72
- segments:
73
- - 2
74
- - 8
75
- - 0
76
- version: 2.8.0
77
- requirement: *id004
42
+ - !ruby/object:Gem::Version
43
+ version: '3.0'
44
+ type: :development
78
45
  prerelease: false
46
+ version_requirements: *70145636763680
47
+ - !ruby/object:Gem::Dependency
79
48
  name: rspec
80
- type: :development
81
- - !ruby/object:Gem::Dependency
82
- version_requirements: &id005 !ruby/object:Gem::Requirement
49
+ requirement: &70145636763200 !ruby/object:Gem::Requirement
83
50
  none: false
84
- requirements:
51
+ requirements:
85
52
  - - ~>
86
- - !ruby/object:Gem::Version
87
- hash: 3
88
- segments:
89
- - 0
90
- - 7
91
- - 0
92
- version: 0.7.0
93
- requirement: *id005
53
+ - !ruby/object:Gem::Version
54
+ version: 2.8.0
55
+ type: :development
94
56
  prerelease: false
57
+ version_requirements: *70145636763200
58
+ - !ruby/object:Gem::Dependency
95
59
  name: database_cleaner
96
- type: :development
97
- - !ruby/object:Gem::Dependency
98
- version_requirements: &id006 !ruby/object:Gem::Requirement
60
+ requirement: &70145636762700 !ruby/object:Gem::Requirement
99
61
  none: false
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- hash: 3
104
- segments:
105
- - 0
106
- version: "0"
107
- requirement: *id006
108
- prerelease: false
109
- name: ruby-debug
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: 0.7.0
110
66
  type: :development
111
- - !ruby/object:Gem::Dependency
112
- version_requirements: &id007 !ruby/object:Gem::Requirement
113
- none: false
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- hash: 3
118
- segments:
119
- - 0
120
- version: "0"
121
- requirement: *id007
122
67
  prerelease: false
68
+ version_requirements: *70145636762700
69
+ - !ruby/object:Gem::Dependency
123
70
  name: sqlite3
71
+ requirement: &70145636762300 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
124
77
  type: :development
125
- description: "Provides async methods ruby objects for queuing background jobs. Currently supports Resque. Bonus: callback hooks for ActiveRecord objects"
126
- email:
78
+ prerelease: false
79
+ version_requirements: *70145636762300
80
+ description: ! 'Provides async methods ruby objects for queuing background jobs. Currently
81
+ supports Resque. Bonus: callback hooks for ActiveRecord objects'
82
+ email:
127
83
  - rosskaff@gmail.com
128
84
  executables: []
129
-
130
85
  extensions: []
131
-
132
86
  extra_rdoc_files: []
133
-
134
- files:
87
+ files:
135
88
  - .gitignore
89
+ - .travis.yml
136
90
  - CHANGELOG.md
137
91
  - Gemfile
138
92
  - MIT-LICENSE
93
+ - README.md
139
94
  - Rakefile
140
95
  - activeasync.gemspec
141
96
  - lib/active_async.rb
@@ -143,6 +98,8 @@ files:
143
98
  - lib/active_async/async.rb
144
99
  - lib/active_async/callbacks.rb
145
100
  - lib/active_async/fake_resque.rb
101
+ - lib/active_async/railtie.rb
102
+ - lib/active_async/rspec.rb
146
103
  - lib/active_async/version.rb
147
104
  - spec/active_async/active_record_spec.rb
148
105
  - spec/active_async/async_spec.rb
@@ -151,12 +108,8 @@ files:
151
108
  - spec/active_async_spec.rb
152
109
  - spec/dummy/.gitignore
153
110
  - spec/dummy/Rakefile
154
- - spec/dummy/app/assets/images/rails.png
155
- - spec/dummy/app/assets/javascripts/application.js
156
- - spec/dummy/app/assets/stylesheets/application.css
157
111
  - spec/dummy/app/controllers/application_controller.rb
158
112
  - spec/dummy/app/helpers/application_helper.rb
159
- - spec/dummy/app/mailers/.gitkeep
160
113
  - spec/dummy/app/models/.gitkeep
161
114
  - spec/dummy/app/models/blog.rb
162
115
  - spec/dummy/app/models/post.rb
@@ -169,7 +122,6 @@ files:
169
122
  - spec/dummy/config/environments/development.rb
170
123
  - spec/dummy/config/environments/production.rb
171
124
  - spec/dummy/config/environments/test.rb
172
- - spec/dummy/config/initializers/async.rb
173
125
  - spec/dummy/config/initializers/backtrace_silencers.rb
174
126
  - spec/dummy/config/initializers/inflections.rb
175
127
  - spec/dummy/config/initializers/mime_types.rb
@@ -182,51 +134,31 @@ files:
182
134
  - spec/dummy/db/migrate/20120127010859_create_blogs.rb
183
135
  - spec/dummy/db/schema.rb
184
136
  - spec/dummy/db/seeds.rb
185
- - spec/dummy/lib/assets/.gitkeep
186
- - spec/dummy/lib/tasks/.gitkeep
187
137
  - spec/dummy/log/.gitkeep
188
- - spec/dummy/public/404.html
189
- - spec/dummy/public/422.html
190
- - spec/dummy/public/500.html
191
- - spec/dummy/public/favicon.ico
192
138
  - spec/dummy/script/rails
193
- - spec/dummy/vendor/assets/javascripts/.gitkeep
194
- - spec/dummy/vendor/assets/stylesheets/.gitkeep
195
- - spec/dummy/vendor/plugins/.gitkeep
196
139
  - spec/spec_helper.rb
197
- - spec/support/stub_resque.rb
198
- homepage: ""
140
+ homepage: ''
199
141
  licenses: []
200
-
201
142
  post_install_message:
202
143
  rdoc_options: []
203
-
204
- require_paths:
144
+ require_paths:
205
145
  - lib
206
- required_ruby_version: !ruby/object:Gem::Requirement
146
+ required_ruby_version: !ruby/object:Gem::Requirement
207
147
  none: false
208
- requirements:
209
- - - ">="
210
- - !ruby/object:Gem::Version
211
- hash: 3
212
- segments:
213
- - 0
214
- version: "0"
215
- required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ! '>='
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
216
153
  none: false
217
- requirements:
218
- - - ">="
219
- - !ruby/object:Gem::Version
220
- hash: 3
221
- segments:
222
- - 0
223
- version: "0"
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
224
158
  requirements: []
225
-
226
159
  rubyforge_project: activeasync
227
- rubygems_version: 1.8.10
160
+ rubygems_version: 1.8.5
228
161
  signing_key:
229
162
  specification_version: 3
230
163
  summary: Add async support to ruby objects
231
164
  test_files: []
232
-
Binary file
@@ -1,13 +0,0 @@
1
- // This is a manifest file that'll be compiled into application.js, which will include all the files
2
- // listed below.
3
- //
4
- // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
- // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
- //
7
- // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
- // the compiled file.
9
- //
10
- // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
- // GO AFTER THE REQUIRES BELOW.
12
- //
13
- //= require_tree .
@@ -1,13 +0,0 @@
1
- /*
2
- * This is a manifest file that'll be compiled into application.css, which will include all the files
3
- * listed below.
4
- *
5
- * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
- * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
- *
8
- * You're free to add application-wide styles to this file and they'll appear at the top of the
9
- * compiled file, but it's generally better to create a new file per style scope.
10
- *
11
- *= require_self
12
- *= require_tree .
13
- */
File without changes
@@ -1,2 +0,0 @@
1
- require 'active_async'
2
- ActiveRecord::Base.send :include, ActiveAsync::ActiveRecord
File without changes
File without changes
@@ -1,26 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>The page you were looking for doesn't exist (404)</title>
5
- <style type="text/css">
6
- body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
- div.dialog {
8
- width: 25em;
9
- padding: 0 4em;
10
- margin: 4em auto 0 auto;
11
- border: 1px solid #ccc;
12
- border-right-color: #999;
13
- border-bottom-color: #999;
14
- }
15
- h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
- </style>
17
- </head>
18
-
19
- <body>
20
- <!-- This file lives in public/404.html -->
21
- <div class="dialog">
22
- <h1>The page you were looking for doesn't exist.</h1>
23
- <p>You may have mistyped the address or the page may have moved.</p>
24
- </div>
25
- </body>
26
- </html>
@@ -1,26 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>The change you wanted was rejected (422)</title>
5
- <style type="text/css">
6
- body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
- div.dialog {
8
- width: 25em;
9
- padding: 0 4em;
10
- margin: 4em auto 0 auto;
11
- border: 1px solid #ccc;
12
- border-right-color: #999;
13
- border-bottom-color: #999;
14
- }
15
- h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
- </style>
17
- </head>
18
-
19
- <body>
20
- <!-- This file lives in public/422.html -->
21
- <div class="dialog">
22
- <h1>The change you wanted was rejected.</h1>
23
- <p>Maybe you tried to change something you didn't have access to.</p>
24
- </div>
25
- </body>
26
- </html>
@@ -1,25 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>We're sorry, but something went wrong (500)</title>
5
- <style type="text/css">
6
- body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
- div.dialog {
8
- width: 25em;
9
- padding: 0 4em;
10
- margin: 4em auto 0 auto;
11
- border: 1px solid #ccc;
12
- border-right-color: #999;
13
- border-bottom-color: #999;
14
- }
15
- h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
- </style>
17
- </head>
18
-
19
- <body>
20
- <!-- This file lives in public/500.html -->
21
- <div class="dialog">
22
- <h1>We're sorry, but something went wrong.</h1>
23
- </div>
24
- </body>
25
- </html>
File without changes
File without changes
File without changes
File without changes
@@ -1,12 +0,0 @@
1
- require 'active_async/fake_resque'
2
-
3
- RSpec.configure do |c|
4
- c.treat_symbols_as_metadata_keys_with_true_values = true
5
- c.before(:each, :stub_resque) do |example|
6
- ActiveAsync.background = ActiveAsync::FakeResque
7
- end
8
-
9
- c.after(:each, :stub_resque) do |example|
10
- ActiveAsync.background = Resque
11
- end
12
- end