Skip to content
Browse files

General cleanup, add rpsec, add dynamic methods

  • Loading branch information...
1 parent 451d842 commit d623b8096434c3199eb872c49e86038632508d0a @bloudermilk committed Oct 22, 2011
View
2 .rspec
@@ -0,0 +1,2 @@
+--colour
+--format <%= ENV["CI"] ? 'progress' : 'documentation'%>
View
9 .travis.yml
@@ -0,0 +1,9 @@
+rvm:
+ - 1.8.7
+ - 1.9.2
+ - 1.9.3
+ - ruby-head
+ - jruby
+ - rbx
+ - rbx-2.0
+ - ree
View
4 Gemfile
@@ -0,0 +1,4 @@
+source :rubygems
+gemspec
+
+gem "rake"
View
70 Gemfile.lock
@@ -0,0 +1,70 @@
+PATH
+ remote: .
+ specs:
+ acts_as_async (0.1.0)
+ activerecord
+ activesupport
+ resque
+ resque-scheduler
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ activemodel (3.1.1)
+ activesupport (= 3.1.1)
+ builder (~> 3.0.0)
+ i18n (~> 0.6)
+ activerecord (3.1.1)
+ activemodel (= 3.1.1)
+ activesupport (= 3.1.1)
+ arel (~> 2.2.1)
+ tzinfo (~> 0.3.29)
+ activesupport (3.1.1)
+ multi_json (~> 1.0)
+ arel (2.2.1)
+ builder (3.0.0)
+ diff-lcs (1.1.3)
+ i18n (0.6.0)
+ multi_json (1.0.3)
+ rack (1.3.5)
+ rack-protection (1.1.4)
+ rack
+ rake (0.9.2)
+ redis (2.2.2)
+ redis-namespace (1.0.3)
+ redis (< 3.0.0)
+ resque (1.19.0)
+ multi_json (~> 1.0)
+ redis-namespace (~> 1.0.2)
+ sinatra (>= 0.9.2)
+ vegas (~> 0.1.2)
+ resque-scheduler (1.9.9)
+ redis (>= 2.0.1)
+ resque (>= 1.8.0)
+ rufus-scheduler
+ rspec (2.7.0)
+ rspec-core (~> 2.7.0)
+ rspec-expectations (~> 2.7.0)
+ rspec-mocks (~> 2.7.0)
+ rspec-core (2.7.1)
+ rspec-expectations (2.7.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.7.0)
+ rufus-scheduler (2.0.11)
+ tzinfo (>= 0.3.23)
+ sinatra (1.3.1)
+ rack (~> 1.3, >= 1.3.4)
+ rack-protection (~> 1.1, >= 1.1.2)
+ tilt (~> 1.3, >= 1.3.3)
+ tilt (1.3.3)
+ tzinfo (0.3.30)
+ vegas (0.1.8)
+ rack (>= 1.0.0)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ acts_as_async!
+ rake
+ rspec (~> 2.7.0)
View
21 Rakefile
@@ -0,0 +1,21 @@
+require "bundler"
+Bundler.setup
+
+require "rake"
+require "rspec"
+require "rspec/core/rake_task"
+
+$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
+require "acts_as_async/version"
+
+RSpec::Core::RakeTask.new("spec")
+task :default => :spec
+
+task :build do
+ system "gem build acts_as_async.gemspec"
+end
+
+task :install => :build do
+ system "sudo gem install acts_as_async-#{ActsAsAsync::VERSION}.gem"
+end
+
View
BIN acts_as_async-0.1.0.gem
Binary file not shown.
View
34 acts_as_async.gemspec
@@ -1,27 +1,25 @@
-$LOAD_PATH.unshift 'lib'
-require 'acts_as_async/version'
+$LOAD_PATH.unshift "lib"
-Gem::Specification.new do |s|
- s.name = "acts_as_async"
- s.version = ActsAsAsync::VERSION
- s.date = Time.now.strftime('%Y-%m-%d')
- s.summary = "Acts As Async is a Resque-backed ActiveRecord delayed job tool"
- s.homepage = "http://github.com/bloudermilk/acts_as_async"
- s.email = "brendan@gophilosophie.com"
- s.authors = [ "Brendan Loudermilk" ]
-
- s.files = %w( README.md LICENSE )
- s.files += Dir.glob("lib/**/*")
+require "acts_as_async/version"
- s.extra_rdoc_files = [ "LICENSE", "README.md" ]
- s.rdoc_options = ["--charset=UTF-8"]
+Gem::Specification.new do |s|
+ s.name = "acts_as_async"
+ s.version = ActsAsAsync::VERSION
+ s.platform = Gem::Platform::RUBY
+ s.authors = ["Brendan Loudermilk"]
+ s.email = ["brendan@gophilosophie.com"]
+ s.homepage = "http://github.com/bloudermilk/acts_as_async"
+ s.summary = "The marriage of ActiveRecord and Resque"
+ s.description = "ActsAsAsync is an ActiveRecord extension that provides your models with easy-to-use Resque helpers"
# TODO: Find minimum versions
s.add_dependency "resque"
s.add_dependency "resque-scheduler"
+ s.add_dependency "activesupport"
s.add_dependency "activerecord"
- s.description = <<description
- This gem is so crazy you won't believe.
-description
+ s.add_development_dependency "rspec", "~> 2.7.0"
+
+ s.files = Dir.glob("lib/**/*") + %w(LICENSE Rakefile README.md)
+ s.require_path = "lib"
end
View
4 lib/acts_as_async.rb
@@ -1,3 +1,7 @@
+require "active_support/concern"
+
+require "active_record"
+
require "resque"
require "resque_scheduler"
View
49 lib/acts_as_async/helper.rb
@@ -2,6 +2,11 @@ module ActsAsAsync
module Helper
extend ActiveSupport::Concern
+ included do
+ include SharedMethods
+ extend SharedMethods
+ end
+
module ClassMethods
# Args will be an optional ID, a method name and optional arguments
def perform(*args)
@@ -17,7 +22,7 @@ def perform(*args)
method = args.shift
end
- receiver.send(method, *args)
+ receiver.__send__(method, *args)
end
def async(method, *args)
@@ -46,5 +51,47 @@ def async_in(time, method, *args)
Resque.enqueue_in(time, self.class, id, method, *args)
end
end
+
+ module SharedMethods
+ METHOD_REGEXP = /\Aasync_([a-zA-Z]\w*?)(_at|_in)?(!)?\z/
+
+ def method_missing(method_id, *args, &block)
+ if method_id =~ METHOD_REGEXP
+ # Compose the method to be async'd, with an optional bang
+ method = "#{$1}#{$3}"
+
+ if respond_to? method
+ # If we're not using the _at or _in methods, just call async
+ if $2.nil?
+ __send__(:async, method, *args)
+
+ # Otherwise compose the Helper method
+ else
+ __send__("async#{$2}", args.shift, method, *args)
+ end
+ else
+ message = "Tried to async the method #{method} but it isn't defined."
+ raise NoMethodError, message
+ end
+ else
+ super
+ end
+ end
+
+ # Use respond_to_missing? on newer Ruby versions but fall back to
+ # overriding respond_to? on older versions. In both cases, return
+ # true for any match, even if the method to be async'd doesn't
+ # exist, since technically we do respond to that method but throw
+ # an exception.
+ if RUBY_VERSION >= "1.9.2"
+ def respond_to_missing?(method_id, include_private)
+ method =~ METHOD_REGEXP || super
+ end
+ else
+ def respond_to?(method_id, include_private)
+ method =~ METHOD_REGEXP || super
+ end
+ end
+ end
end
end
View
7 spec/acts_as_async/base_extensions_spec.rb
@@ -0,0 +1,7 @@
+require "spec_helper"
+
+describe ActsAsAsync::BaseExtensions do
+ it "should kick ass!" do
+ ActsAsAsync.should == "kick ass!"
+ end
+end
View
2 spec/spec_helper.rb
@@ -0,0 +1,2 @@
+require "rspec"
+require "acts_as_async"

0 comments on commit d623b80

Please sign in to comment.
Something went wrong with that request. Please try again.