ruby_patch 1.1.0 → 2.0.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/lib/ruby_patch/auto_load.rb
CHANGED
@@ -1,19 +1,30 @@
|
|
1
1
|
module RubyPatch
|
2
2
|
module AutoLoad
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
|
4
|
+
def const_missing(name)
|
5
|
+
require file_name(name)
|
6
|
+
|
7
|
+
# Consider the case where you try to require ::A::B.
|
8
|
+
# If you don't use `full_name', `defined?' will determine whether ::RubyPatch::AutoLoad::B is defined, whereas `self' is ::A.
|
9
|
+
if eval "defined? #{full_name(name)}"
|
10
|
+
const_get(name)
|
11
|
+
else
|
12
|
+
$stderr.puts "#{full_name(name)} is not defined in #{file_name(name)}."
|
13
|
+
raise super
|
9
14
|
end
|
10
15
|
end
|
11
16
|
|
17
|
+
private
|
18
|
+
|
12
19
|
# You should use +module Http; end+ rather than +module HTTP; end+
|
13
|
-
def
|
14
|
-
|
20
|
+
def file_name(name)
|
21
|
+
full_name(name).split('::').map{|t|
|
15
22
|
t.sub(/\A([A-Z])/){$1.downcase}.gsub(/([A-Z])/){"_#{$1.downcase}"}
|
16
|
-
}.join('/')
|
23
|
+
}.join('/')
|
24
|
+
end
|
25
|
+
|
26
|
+
def full_name(name)
|
27
|
+
"#{self}::#{name}"
|
17
28
|
end
|
18
29
|
end
|
19
30
|
end
|
data/lib/ruby_patch/core_ext.rb
CHANGED
data/lib/ruby_patch/version.rb
CHANGED
@@ -24,18 +24,4 @@ describe ::RubyPatch::AutoLoad do
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
27
|
-
|
28
|
-
describe '#_file_name' do
|
29
|
-
context Symbol do
|
30
|
-
it do
|
31
|
-
::Dummy._file_name(:'A::B').should == 'dummy/a/b.rb'
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context String do
|
36
|
-
it do
|
37
|
-
::Dummy._file_name('A::B').should == 'dummy/a/b.rb'
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
27
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_patch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &2152555840 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '2.10'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2152555840
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: simplecov
|
27
|
-
requirement: &
|
27
|
+
requirement: &2152555320 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0.6'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2152555320
|
36
36
|
description: Monkey patches used by kshramt's libraries.
|
37
37
|
email:
|
38
38
|
executables: []
|
@@ -43,7 +43,6 @@ files:
|
|
43
43
|
- lib/ruby_patch/auto_load.rb
|
44
44
|
- lib/ruby_patch/core_ext.rb
|
45
45
|
- lib/ruby_patch/core_ext/class.rb
|
46
|
-
- lib/ruby_patch/core_ext/enumerable.rb
|
47
46
|
- lib/ruby_patch/core_ext/module.rb
|
48
47
|
- lib/ruby_patch/core_ext/object.rb
|
49
48
|
- lib/ruby_patch/core_ext/string.rb
|
@@ -53,7 +52,6 @@ files:
|
|
53
52
|
- ruby_patch.gemspec
|
54
53
|
- spec/ruby_patch/auto_load_spec.rb
|
55
54
|
- spec/ruby_patch/core_ext/class_spec.rb
|
56
|
-
- spec/ruby_patch/core_ext/enumerable_spec.rb
|
57
55
|
- spec/ruby_patch/core_ext/module_spec.rb
|
58
56
|
- spec/ruby_patch/core_ext/object_spec.rb
|
59
57
|
- spec/ruby_patch/core_ext/string_spec.rb
|
@@ -87,7 +85,6 @@ summary: Monky patches for ruby.
|
|
87
85
|
test_files:
|
88
86
|
- spec/ruby_patch/auto_load_spec.rb
|
89
87
|
- spec/ruby_patch/core_ext/class_spec.rb
|
90
|
-
- spec/ruby_patch/core_ext/enumerable_spec.rb
|
91
88
|
- spec/ruby_patch/core_ext/module_spec.rb
|
92
89
|
- spec/ruby_patch/core_ext/object_spec.rb
|
93
90
|
- spec/ruby_patch/core_ext/string_spec.rb
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Enumerable do
|
4
|
-
describe 'classify' do
|
5
|
-
it do
|
6
|
-
(1..4).classify{|i| i.odd?}.should == {
|
7
|
-
true => [1, 3],
|
8
|
-
false => [2, 4],
|
9
|
-
}
|
10
|
-
end
|
11
|
-
|
12
|
-
it do
|
13
|
-
[1, '1', :'1'].classify{|v| v.class}.should == {
|
14
|
-
Fixnum => [1],
|
15
|
-
String => ['1'],
|
16
|
-
Symbol => [:'1'],
|
17
|
-
}
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|