ruby_patch 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ruby_patch.rb +1 -0
- data/lib/ruby_patch/auto_load.rb +17 -0
- data/lib/ruby_patch/version.rb +1 -1
- data/spec/ruby_patch/auto_load_spec.rb +43 -0
- data/spec/ruby_patch/dummy/a.rb +1 -0
- metadata +10 -6
data/lib/ruby_patch.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
module RubyPatch
|
2
|
+
module AutoLoad
|
3
|
+
def const_missing(const_name)
|
4
|
+
begin
|
5
|
+
require _file_name(const_name)
|
6
|
+
self.const_get(const_name)
|
7
|
+
rescue LoadError
|
8
|
+
super
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
# You should use +module Http; end+ rather than +module HTTP; end+
|
13
|
+
def _file_name(name)
|
14
|
+
"#{self}::#{name}".split('::').map{|t| t.sub(/\A([A-Z])/){$1.downcase}.gsub(/([A-Z])/){"_#{$1.downcase}"}}.join('/') + '.rb'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/ruby_patch/version.rb
CHANGED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'ruby_patch/auto_load'
|
3
|
+
require 'ruby_patch/object'
|
4
|
+
|
5
|
+
describe ::RubyPatch::AutoLoad do
|
6
|
+
before :each do
|
7
|
+
class ::Dummy
|
8
|
+
extend ::RubyPatch::AutoLoad
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#auto_load' do
|
13
|
+
before :all do
|
14
|
+
$LOAD_PATH.unshift(__DIR__) unless $LOAD_PATH.include?(__DIR__)
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'normal case' do
|
18
|
+
it do
|
19
|
+
lambda{::Dummy::A}.should_not raise_error
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'wrong case' do
|
24
|
+
it do
|
25
|
+
lambda{::Dummy::B}.should raise_error
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#_file_name' do
|
31
|
+
context Symbol do
|
32
|
+
it do
|
33
|
+
::Dummy._file_name(:'A::B').should == 'dummy/a/b.rb'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context String do
|
38
|
+
it do
|
39
|
+
::Dummy._file_name('A::B').should == 'dummy/a/b.rb'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
module A; 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: 0.
|
4
|
+
version: 0.3.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-06-
|
12
|
+
date: 2012-06-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &2157610140 !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: *2157610140
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: simplecov
|
27
|
-
requirement: &
|
27
|
+
requirement: &2157609600 !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: *2157609600
|
36
36
|
description: Monkey patches used by kshramt's libraries.
|
37
37
|
email:
|
38
38
|
executables: []
|
@@ -40,6 +40,7 @@ extensions: []
|
|
40
40
|
extra_rdoc_files: []
|
41
41
|
files:
|
42
42
|
- lib/ruby_patch.rb
|
43
|
+
- lib/ruby_patch/auto_load.rb
|
43
44
|
- lib/ruby_patch/class.rb
|
44
45
|
- lib/ruby_patch/enumerable.rb
|
45
46
|
- lib/ruby_patch/object.rb
|
@@ -48,7 +49,9 @@ files:
|
|
48
49
|
- lib/ruby_patch/version.rb
|
49
50
|
- rakefile
|
50
51
|
- ruby_patch.gemspec
|
52
|
+
- spec/ruby_patch/auto_load_spec.rb
|
51
53
|
- spec/ruby_patch/class_spec.rb
|
54
|
+
- spec/ruby_patch/dummy/a.rb
|
52
55
|
- spec/ruby_patch/enumerable_spec.rb
|
53
56
|
- spec/ruby_patch/object_spec.rb
|
54
57
|
- spec/ruby_patch/string_spec.rb
|
@@ -80,6 +83,7 @@ signing_key:
|
|
80
83
|
specification_version: 3
|
81
84
|
summary: Monky patches for ruby.
|
82
85
|
test_files:
|
86
|
+
- spec/ruby_patch/auto_load_spec.rb
|
83
87
|
- spec/ruby_patch/class_spec.rb
|
84
88
|
- spec/ruby_patch/enumerable_spec.rb
|
85
89
|
- spec/ruby_patch/object_spec.rb
|