botfly 0.3.5 → 0.3.6
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/TODO +1 -0
- data/VERSION +1 -1
- data/botfly.gemspec +1 -1
- data/lib/botfly/common_block_acceptor.rb +15 -1
- data/spec/botfly/common_block_acceptor_spec.rb +13 -2
- metadata +2 -2
data/TODO
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
Botfly Todo List (by priority)
|
2
2
|
==============================
|
3
3
|
* Have Bot.new and Bot#run instead of just #login that always runs
|
4
|
+
* Write cucumber integration testes
|
4
5
|
* Replace CommonBlockAcceptor responder chain array with ResponderChain object
|
5
6
|
** Spec & create ResponderChain class
|
6
7
|
** Have responder chain stop call first responder ONLY after reaching a match
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.6
|
data/botfly.gemspec
CHANGED
@@ -34,12 +34,26 @@ module Botfly
|
|
34
34
|
def initialize(obj); @obj = obj; end
|
35
35
|
|
36
36
|
def method_missing(name,&block)
|
37
|
+
@type = name
|
37
38
|
Botfly.logger.info("#{@obj.to_debug_s}: Bot#on")
|
38
|
-
|
39
|
+
|
39
40
|
(@obj.responders[name] ||= []) << responder = klass.new(@obj, &block)
|
40
41
|
Botfly.logger.info("#{@obj.to_debug_s}: #{@obj.class_prefix}#{name.to_s.capitalize}Responder added to responder chain")
|
41
42
|
return responder
|
42
43
|
end
|
44
|
+
|
45
|
+
private
|
46
|
+
def klass
|
47
|
+
begin
|
48
|
+
klass = Botfly.const_get(@obj.class_prefix + @type.to_s.split('_').map(&:capitalize).join + "Responder")
|
49
|
+
rescue
|
50
|
+
if @obj.class_prefix.empty?
|
51
|
+
klass = Responder
|
52
|
+
else
|
53
|
+
klass = Botfly.const_get(@obj.class_prefix+"Responder")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
43
57
|
end
|
44
58
|
|
45
59
|
def class_prefix; ''; end
|
@@ -52,7 +52,7 @@ describe CommonBlockAcceptor do
|
|
52
52
|
class FooBarResponder; def initialize(baz);end; end
|
53
53
|
end
|
54
54
|
|
55
|
-
it "should instanciate responder based on name" do
|
55
|
+
it "should instanciate specialized responder based on name if class exists" do
|
56
56
|
FooResponder.should_receive(:new)
|
57
57
|
on.foo
|
58
58
|
end
|
@@ -65,7 +65,7 @@ describe CommonBlockAcceptor do
|
|
65
65
|
it "should add class prefix to front of responder class" do
|
66
66
|
acceptor.stub(:class_prefix).and_return('Foo')
|
67
67
|
Botfly.should_receive(:const_get).with('FooBarResponder').and_return(FooBarResponder)
|
68
|
-
on.bar
|
68
|
+
on.bar.should be_a_kind_of FooBarResponder
|
69
69
|
end
|
70
70
|
|
71
71
|
it "should add responder to object's responder chain hash" do
|
@@ -80,6 +80,17 @@ describe CommonBlockAcceptor do
|
|
80
80
|
FooResponder.stub(:new).and_return(:foo_instance)
|
81
81
|
on.foo.should be :foo_instance
|
82
82
|
end
|
83
|
+
|
84
|
+
it "should default to Responder for basic responder" do
|
85
|
+
Responder.stub(:new).and_return(:plain)
|
86
|
+
on.baz.should be :plain
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should still add class prefix even if special responder not found" do
|
90
|
+
acceptor.stub(:class_prefix).and_return('Foo')
|
91
|
+
FooResponder.stub(:new).and_return(:plain)
|
92
|
+
on.baz.should be :plain
|
93
|
+
end
|
83
94
|
end
|
84
95
|
end
|
85
96
|
|