jeremymcanally-context 0.0.6 → 0.5
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/context.gemspec +1 -1
- data/lib/context/core_ext/string.rb +3 -2
- data/lib/context/lifecycle.rb +4 -2
- data/lib/context/version.rb +2 -2
- data/test/test_core_ext.rb +4 -0
- metadata +1 -1
data/context.gemspec
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
class String
|
2
2
|
# Replaces spaces and tabs with _ so we can use the string as a method name
|
3
|
+
# Also replace dangerous punctuation
|
3
4
|
def to_method_name
|
4
|
-
self.downcase.gsub(/[\s:']+/,'_')
|
5
|
+
self.downcase.gsub(/[\s:',;!#]+/,'_')
|
5
6
|
end
|
6
7
|
|
7
8
|
# Borrowed from +camelize+ in ActiveSupport
|
@@ -13,4 +14,4 @@ class String
|
|
13
14
|
def to_class_name
|
14
15
|
self.to_method_name.gsub(/\/(.?)/) { "#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
|
15
16
|
end
|
16
|
-
end
|
17
|
+
end
|
data/lib/context/lifecycle.rb
CHANGED
@@ -42,22 +42,24 @@ class Test::Unit::TestCase
|
|
42
42
|
|
43
43
|
child.class_eval do
|
44
44
|
def setup
|
45
|
+
super
|
45
46
|
run_each_callbacks :before
|
46
47
|
end
|
47
48
|
|
48
49
|
def teardown
|
50
|
+
super
|
49
51
|
run_each_callbacks :after
|
50
52
|
end
|
51
53
|
end
|
52
54
|
end
|
53
55
|
|
54
56
|
def run_each_callbacks(callback_type) # :nodoc:
|
55
|
-
self.class.gather_callbacks(callback_type, :each).each { |c| instance_eval(&c) }
|
57
|
+
self.class.gather_callbacks(callback_type, :each).each { |c| instance_eval(&c) if c }
|
56
58
|
end
|
57
59
|
|
58
60
|
def run_all_callbacks(callback_type) # :nodoc:
|
59
61
|
previous_ivars = instance_variables
|
60
|
-
self.class.gather_callbacks(callback_type, :all).each { |c| instance_eval(&c) }
|
62
|
+
self.class.gather_callbacks(callback_type, :all).each { |c| instance_eval(&c) if c }
|
61
63
|
(instance_variables - previous_ivars).inject({}) do |hash, ivar|
|
62
64
|
hash.update ivar => instance_variable_get(ivar)
|
63
65
|
end
|
data/lib/context/version.rb
CHANGED
data/test/test_core_ext.rb
CHANGED
@@ -13,5 +13,9 @@ class TestCoreExt < Test::Unit::TestCase
|
|
13
13
|
it "should change spaces to _" do
|
14
14
|
assert :this_has_been_great, "This has been great".to_method_name
|
15
15
|
end
|
16
|
+
|
17
|
+
it "should change dangerous punctuation to _" do
|
18
|
+
assert :no__really__this_was__good_, "No, really; this was #good!".to_method_name
|
19
|
+
end
|
16
20
|
end
|
17
21
|
end
|