cognition 2.0.5 → 2.0.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.
- checksums.yaml +4 -4
- data/lib/cognition/matcher.rb +10 -4
- data/lib/cognition/plugins/base.rb +2 -2
- data/lib/cognition/version.rb +1 -1
- data/test/test_matcher.rb +0 -10
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0fee2a13ff5efc9bdd6be1a8c4be10b980d1e641
|
4
|
+
data.tar.gz: fea3717ab564a976080201025d641ab65e584980
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 789570221b292d985f550719c978135d3cd976c27dc4544859dcb1ca4d786d83de866a4d1f5ffb60a20610022484ee42fb6dc0059825cb1dab44b815d69a621f
|
7
|
+
data.tar.gz: 7f1dfa3993d8ee9cb3fc7b03e880a0ca8b84ac4f7c6ee764cfa5626cded7aa5d3eb56e4e46ad20502f77e581be922e145621e4aba920b0738d32d4af7aecccea
|
data/lib/cognition/matcher.rb
CHANGED
@@ -22,10 +22,16 @@ module Cognition
|
|
22
22
|
run(msg)
|
23
23
|
end
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
if ENV and ENV["RAILS_ENV"] == "production"
|
26
|
+
def run(msg)
|
27
|
+
@response = action.call(msg, match_data)
|
28
|
+
rescue => e
|
29
|
+
@response = "'#{msg.command}' found, but raised #{e.inspect}"
|
30
|
+
end
|
31
|
+
else
|
32
|
+
def run(msg)
|
33
|
+
@response = action.call(msg, match_data)
|
34
|
+
end
|
29
35
|
end
|
30
36
|
|
31
37
|
def matches?(msg)
|
@@ -58,8 +58,8 @@ module Cognition
|
|
58
58
|
|
59
59
|
def underscore(string)
|
60
60
|
word = string.to_s.gsub(/::/, "/")
|
61
|
-
word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, "
|
62
|
-
word.gsub!(/([a-z\d])([A-Z])/, "
|
61
|
+
word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, "\\1_\\2")
|
62
|
+
word.gsub!(/([a-z\d])([A-Z])/, "\\1_\\2")
|
63
63
|
word.tr!("-", "_")
|
64
64
|
word.downcase!
|
65
65
|
word
|
data/lib/cognition/version.rb
CHANGED
data/test/test_matcher.rb
CHANGED
@@ -74,18 +74,8 @@ class MatcherTest < Minitest::Test
|
|
74
74
|
matcher_with_help = Cognition::Matcher.new(/hello\s*(?<name>.*)/, { help: { "hello" => "says hello" } }, &proc(&method(:dummy_method)))
|
75
75
|
assert_equal ["hello - says hello"], matcher_with_help.help
|
76
76
|
end
|
77
|
-
|
78
|
-
def test_returns_error_if_method_returns_an_error
|
79
|
-
msg = Cognition::Message.new("error")
|
80
|
-
matcher_with_error = Cognition::Matcher.new(/error/, &proc(&method(:error_method)))
|
81
|
-
assert matcher_with_error.attempt(msg).match("'error' found, but raised")
|
82
|
-
end
|
83
77
|
end
|
84
78
|
|
85
79
|
def dummy_method(_, match_data)
|
86
80
|
"Hello #{match_data['name']}"
|
87
81
|
end
|
88
|
-
|
89
|
-
def error_method(*)
|
90
|
-
foobarcall
|
91
|
-
end
|