ayl 0.2.1 → 0.3.0

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.3.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "ayl"
8
- s.version = "0.2.1"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Dave Sieh"]
12
- s.date = "2013-07-22"
12
+ s.date = "2013-08-07"
13
13
  s.description = "Invoke code At Your Leisure. ayl is a small framework that simplifies the process of implementing asynchronous method calls in Ruby."
14
14
  s.email = "j0hnds@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -21,7 +21,7 @@ module Ayl
21
21
  Message.new(nil, nil, MessageOptions.new).tap do | m |
22
22
  m.send(:message_hash=, message_hash)
23
23
  m.send(:code=, code)
24
- m.options.decay_failed_job = message_hash[:decay_failed_job] if message_hash[:decay_failed_job]
24
+ m.options.failed_job_handler = message_hash[:failed_job_handler] if message_hash[:failed_job_handler]
25
25
  end
26
26
 
27
27
  end
@@ -33,7 +33,7 @@ module Ayl
33
33
  def to_hash
34
34
  @message_hash ||= {
35
35
  :type => :ayl,
36
- :decay_failed_job => options.decay_failed_job,
36
+ :failed_job_handler => options.failed_job_handler,
37
37
  :code => to_rrepr
38
38
  }
39
39
  end
@@ -2,12 +2,14 @@ module Ayl
2
2
 
3
3
  class MessageOptions
4
4
 
5
- OPTIONS = [ :priority, :fuzz, :delay, :time_to_run, :queue_name, :decay_failed_job ]
5
+ OPTIONS = [ :priority, :fuzz, :delay, :time_to_run, :queue_name, :failed_job_handler ]
6
+
7
+ VALID_FAILED_JOB_HANDLERS = %W{ bury decay delete }
6
8
 
7
9
  attr_accessor *OPTIONS
8
10
 
9
11
  class << self
10
- attr_accessor :default_priority, :default_fuzz, :default_delay, :default_time_to_run, :default_queue_name, :default_decay_failed_job
12
+ attr_accessor :default_priority, :default_fuzz, :default_delay, :default_time_to_run, :default_queue_name, :default_failed_job_handler
11
13
  end
12
14
 
13
15
  # Set the default options
@@ -16,7 +18,7 @@ module Ayl
16
18
  self.default_delay = 0
17
19
  self.default_time_to_run = 120
18
20
  self.default_queue_name = 'default'
19
- self.default_decay_failed_job = false
21
+ self.default_failed_job_handler = 'delete'
20
22
 
21
23
  def initialize(opts=nil)
22
24
  opts ||= {}
@@ -24,6 +26,11 @@ module Ayl
24
26
  unknown_options = opts.keys - OPTIONS
25
27
  raise "unknown options specified: #{unknown_options}" unless unknown_options.empty?
26
28
  OPTIONS.each do |o|
29
+ if o == :failed_job_handler
30
+ if !(v = opts[o]).nil?
31
+ raise "value for :failed_job_handler must be one of: #{VALID_FAILED_JOB_HANDLERS.join(', ')}" unless VALID_FAILED_JOB_HANDLERS.include?(v)
32
+ end
33
+ end
27
34
  send("#{o}=".to_sym, opts.fetch(o, self.class.send("default_#{o}".to_sym)))
28
35
  end
29
36
  end
@@ -10,7 +10,7 @@ describe Ayl::MessageOptions do
10
10
  Ayl::MessageOptions.default_delay.should == 0
11
11
  Ayl::MessageOptions.default_time_to_run.should == 120
12
12
  Ayl::MessageOptions.default_queue_name.should == 'default'
13
- Ayl::MessageOptions.default_decay_failed_job.should == false
13
+ Ayl::MessageOptions.default_failed_job_handler.should == 'delete'
14
14
  end
15
15
 
16
16
  it "should reflect the changes if changes have been made" do
@@ -19,14 +19,14 @@ describe Ayl::MessageOptions do
19
19
  Ayl::MessageOptions.default_delay = 2300
20
20
  Ayl::MessageOptions.default_time_to_run = 1
21
21
  Ayl::MessageOptions.default_queue_name = 'different'
22
- Ayl::MessageOptions.default_decay_failed_job = true
22
+ Ayl::MessageOptions.default_failed_job_handler = 'bury'
23
23
 
24
24
  Ayl::MessageOptions.default_priority.should == 256
25
25
  Ayl::MessageOptions.default_fuzz.should == 18
26
26
  Ayl::MessageOptions.default_delay.should == 2300
27
27
  Ayl::MessageOptions.default_time_to_run.should == 1
28
28
  Ayl::MessageOptions.default_queue_name.should == 'different'
29
- Ayl::MessageOptions.default_decay_failed_job.should == true
29
+ Ayl::MessageOptions.default_failed_job_handler.should == 'bury'
30
30
  end
31
31
 
32
32
  end
@@ -41,7 +41,7 @@ describe Ayl::MessageOptions do
41
41
  mo.delay.should == Ayl::MessageOptions.default_delay
42
42
  mo.time_to_run.should == Ayl::MessageOptions.default_time_to_run
43
43
  mo.queue_name.should == Ayl::MessageOptions.default_queue_name
44
- mo.decay_failed_job.should == Ayl::MessageOptions.default_decay_failed_job
44
+ mo.failed_job_handler.should == Ayl::MessageOptions.default_failed_job_handler
45
45
  end
46
46
 
47
47
  it "should respond with the correct defaults when initialized with nil" do
@@ -52,7 +52,7 @@ describe Ayl::MessageOptions do
52
52
  mo.delay.should == Ayl::MessageOptions.default_delay
53
53
  mo.time_to_run.should == Ayl::MessageOptions.default_time_to_run
54
54
  mo.queue_name.should == Ayl::MessageOptions.default_queue_name
55
- mo.decay_failed_job.should == Ayl::MessageOptions.default_decay_failed_job
55
+ mo.failed_job_handler.should == Ayl::MessageOptions.default_failed_job_handler
56
56
  end
57
57
 
58
58
  it "should respond with the correct defaults when initialized with no parameter" do
@@ -63,11 +63,11 @@ describe Ayl::MessageOptions do
63
63
  mo.delay.should == Ayl::MessageOptions.default_delay
64
64
  mo.time_to_run.should == Ayl::MessageOptions.default_time_to_run
65
65
  mo.queue_name.should == Ayl::MessageOptions.default_queue_name
66
- mo.decay_failed_job.should == Ayl::MessageOptions.default_decay_failed_job
66
+ mo.failed_job_handler.should == Ayl::MessageOptions.default_failed_job_handler
67
67
  end
68
68
 
69
69
  it "should respond with the correct values when all are specified in the options" do
70
- opts = { :priority => 22, :fuzz => 88, :delay => 99, :time_to_run => 11, :queue_name => 'stub', :decay_failed_job => true }
70
+ opts = { :priority => 22, :fuzz => 88, :delay => 99, :time_to_run => 11, :queue_name => 'stub', :failed_job_handler => 'decay' }
71
71
  mo = Ayl::MessageOptions.new(opts)
72
72
 
73
73
  mo.priority.should == opts[:priority]
@@ -75,7 +75,7 @@ describe Ayl::MessageOptions do
75
75
  mo.delay.should == opts[:delay]
76
76
  mo.time_to_run.should == opts[:time_to_run]
77
77
  mo.queue_name.should == opts[:queue_name]
78
- mo.decay_failed_job.should == opts[:decay_failed_job]
78
+ mo.failed_job_handler.should == opts[:failed_job_handler]
79
79
  end
80
80
 
81
81
  it "should respond with the correct values when some values are specified in the options" do
@@ -87,7 +87,7 @@ describe Ayl::MessageOptions do
87
87
  mo.delay.should == opts[:delay]
88
88
  mo.time_to_run.should == Ayl::MessageOptions.default_time_to_run
89
89
  mo.queue_name.should == Ayl::MessageOptions.default_queue_name
90
- mo.decay_failed_job.should == Ayl::MessageOptions.default_decay_failed_job
90
+ mo.failed_job_handler.should == Ayl::MessageOptions.default_failed_job_handler
91
91
  end
92
92
 
93
93
  it "should raise an exception when an invalid option is provided in the hash" do
@@ -9,7 +9,7 @@ describe Ayl::Message do
9
9
  Ayl::MessageOptions.default_delay = 0
10
10
  Ayl::MessageOptions.default_time_to_run = 120
11
11
  Ayl::MessageOptions.default_queue_name = 'default'
12
- Ayl::MessageOptions.default_decay_failed_job = false
12
+ Ayl::MessageOptions.default_failed_job_handler = 'decay'
13
13
  end
14
14
 
15
15
  context "Initialization" do
@@ -57,14 +57,14 @@ describe Ayl::Message do
57
57
  it "should package up the message into a hash" do
58
58
  options = Ayl::MessageOptions.new
59
59
  m = Ayl::Message.new("object", :method_name, options, "arg1", "arg2")
60
- m.to_hash.should == { :type => :ayl, :decay_failed_job => false, :code => "\"object\".method_name(\"arg1\", \"arg2\")" }
60
+ m.to_hash.should == { :type => :ayl, :failed_job_handler => 'decay', :code => "\"object\".method_name(\"arg1\", \"arg2\")" }
61
61
  end
62
62
 
63
63
  it "should package up the message into a hash when the decay failed job has been set" do
64
64
  options = Ayl::MessageOptions.new
65
- options.decay_failed_job = true
65
+ options.failed_job_handler = 'decay'
66
66
  m = Ayl::Message.new("object", :method_name, options, "arg1", "arg2")
67
- m.to_hash.should == { :type => :ayl, :decay_failed_job => true, :code => "\"object\".method_name(\"arg1\", \"arg2\")" }
67
+ m.to_hash.should == { :type => :ayl, :failed_job_handler => 'decay', :code => "\"object\".method_name(\"arg1\", \"arg2\")" }
68
68
  end
69
69
 
70
70
  it "should be able to create a message from a hash with code that has arguments" do
@@ -104,27 +104,28 @@ describe Ayl::Message do
104
104
  end
105
105
 
106
106
  it "should create a message with decay_failed job set to false if not in the original hash" do
107
+ Ayl::MessageOptions.default_failed_job_handler = 'delete'
107
108
  m_hash = { :type => :ayl, :code => "String._ayl_after_create(2.to_s(2))" }
108
109
  m = Ayl::Message.from_hash(m_hash)
109
110
  m.options.is_a?(Ayl::MessageOptions).should be_true
110
111
  m.to_hash.should === m_hash
111
- m.options.decay_failed_job.should be_false
112
+ m.options.failed_job_handler.should == 'delete'
112
113
  end
113
114
 
114
115
  it "should create a message with decay_failed job set to false if in the original hash as false" do
115
- m_hash = { :type => :ayl, :decay_failed_job => false, :code => "String._ayl_after_create(2.to_s(2))" }
116
+ m_hash = { :type => :ayl, :failed_job_handler => 'delete', :code => "String._ayl_after_create(2.to_s(2))" }
116
117
  m = Ayl::Message.from_hash(m_hash)
117
118
  m.options.is_a?(Ayl::MessageOptions).should be_true
118
119
  m.to_hash.should === m_hash
119
- m.options.decay_failed_job.should be_false
120
+ m.options.failed_job_handler.should == 'delete'
120
121
  end
121
122
 
122
123
  it "should create a message with decay_failed job set to true if in the original hash as true" do
123
- m_hash = { :type => :ayl, :decay_failed_job => true, :code => "String._ayl_after_create(2.to_s(2))" }
124
+ m_hash = { :type => :ayl, :failed_job_handler => 'decay', :code => "String._ayl_after_create(2.to_s(2))" }
124
125
  m = Ayl::Message.from_hash(m_hash)
125
126
  m.options.is_a?(Ayl::MessageOptions).should be_true
126
127
  m.to_hash.should === m_hash
127
- m.options.decay_failed_job.should be_true
128
+ m.options.failed_job_handler.should == 'decay'
128
129
  end
129
130
 
130
131
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ayl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-22 00:00:00.000000000 Z
12
+ date: 2013-08-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -142,7 +142,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
142
142
  version: '0'
143
143
  segments:
144
144
  - 0
145
- hash: 3676915364557125950
145
+ hash: 831016271210020708
146
146
  required_rubygems_version: !ruby/object:Gem::Requirement
147
147
  none: false
148
148
  requirements: