fsck 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +8 -8
- data/README.md +3 -3
- data/bench.rb +11 -1
- data/fsck.gemspec +1 -1
- data/lib/fsck/version.rb +1 -1
- data/lib/fsck.rb +4 -6
- data/spec/fsck/fsck_spec.rb +20 -0
- metadata +5 -5
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
fsck (0.0.
|
4
|
+
fsck (0.0.4)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: http://rubygems.org/
|
8
8
|
specs:
|
9
9
|
diff-lcs (1.1.2)
|
10
|
-
rspec (2.
|
11
|
-
rspec-core (~> 2.
|
12
|
-
rspec-expectations (~> 2.
|
13
|
-
rspec-mocks (~> 2.
|
14
|
-
rspec-core (2.
|
15
|
-
rspec-expectations (2.
|
10
|
+
rspec (2.4.0)
|
11
|
+
rspec-core (~> 2.4.0)
|
12
|
+
rspec-expectations (~> 2.4.0)
|
13
|
+
rspec-mocks (~> 2.4.0)
|
14
|
+
rspec-core (2.4.0)
|
15
|
+
rspec-expectations (2.4.0)
|
16
16
|
diff-lcs (~> 1.1.2)
|
17
|
-
rspec-mocks (2.
|
17
|
+
rspec-mocks (2.4.0)
|
18
18
|
|
19
19
|
PLATFORMS
|
20
20
|
ruby
|
data/README.md
CHANGED
@@ -50,9 +50,9 @@ Fsck also provides a way to use its functionality on every object in ruby.
|
|
50
50
|
|
51
51
|
## Fsck: How does it work?
|
52
52
|
|
53
|
-
Fsck achieves its functionality by
|
53
|
+
Fsck achieves its functionality by tapping into `method_missing`. The first time a fscked method is called, every method defined on the object is examined. The method with the longest name is assumed to be the *intended* method, and the fscked method is aliased to this method.
|
54
54
|
|
55
|
-
The examination process splits the word of each method name, building a
|
55
|
+
The examination process splits the word of each method name, building a regular expression that allows for any number of other words to be inserted anywhere in the method name. If you aren't careful with the words you choose, you may unintentionally call another method.
|
56
56
|
|
57
57
|
# you may expect this to call #each, but it will instead call #each_value
|
58
58
|
my_hash.what_i_need_is_each_set_of_key_plus_value { |k,v| puts k }
|
@@ -65,7 +65,7 @@ Fsck is named after the use of the Unix file system utility, specifically as it
|
|
65
65
|
|
66
66
|
## Disclaimer
|
67
67
|
|
68
|
-
|
68
|
+
Because Fsck now uses method aliasing, there's only a slight performance hit on the first call to a fscked method. This should be inline with many other gems out there. Performance aside, using this gem will have quite an impact on the maintainability of your code. Use at your own risk.
|
69
69
|
|
70
70
|
## License
|
71
71
|
MIT License. Copyright 2011 Chris Thorn.
|
data/bench.rb
CHANGED
@@ -5,11 +5,21 @@ require "fsck/deep"
|
|
5
5
|
|
6
6
|
N = 1_000
|
7
7
|
|
8
|
-
Benchmark.
|
8
|
+
Benchmark.bmbm(10) do |r|
|
9
9
|
r.report("vanilla") { N.times { 42.succ } }
|
10
10
|
r.report("fscked") { N.times { 42.gimme_succ_please } }
|
11
11
|
end
|
12
12
|
|
13
|
+
# v0.0.4
|
14
|
+
# Rehearsal ---------------------------------------------
|
15
|
+
# vanilla 0.000000 0.000000 0.000000 ( 0.000163)
|
16
|
+
# fscked 0.000000 0.000000 0.000000 ( 0.003473)
|
17
|
+
# ------------------------------------ total: 0.000000sec
|
18
|
+
#
|
19
|
+
# user system total real
|
20
|
+
# vanilla 0.000000 0.000000 0.000000 ( 0.000100)
|
21
|
+
# fscked 0.000000 0.000000 0.000000 ( 0.000199)
|
22
|
+
|
13
23
|
# v0.0.3
|
14
24
|
# user system total real
|
15
25
|
# vanilla 0.000000 0.000000 0.000000 ( 0.000246)
|
data/fsck.gemspec
CHANGED
data/lib/fsck/version.rb
CHANGED
data/lib/fsck.rb
CHANGED
@@ -1,9 +1,5 @@
|
|
1
1
|
module Fsck
|
2
2
|
def method_missing(sym, *args, &block)
|
3
|
-
@_fsck_method_name_cache ||= {}
|
4
|
-
|
5
|
-
return send(@_fsck_method_name_cache[sym], *args, &block) if @_fsck_method_name_cache[sym]
|
6
|
-
|
7
3
|
fscked_method = sym.to_s
|
8
4
|
|
9
5
|
if punctuation = fscked_method[/[!?=]$/]
|
@@ -17,8 +13,10 @@ module Fsck
|
|
17
13
|
if matches.empty?
|
18
14
|
super
|
19
15
|
else
|
20
|
-
|
21
|
-
|
16
|
+
method = matches.sort_by(&:length).last
|
17
|
+
target = singleton_methods.include?(method) ? singleton_class : self.class
|
18
|
+
target.class_exec { alias_method(sym, method) }
|
19
|
+
send(sym, *args, &block)
|
22
20
|
end
|
23
21
|
end
|
24
22
|
|
data/spec/fsck/fsck_spec.rb
CHANGED
@@ -52,4 +52,24 @@ describe Fsck do
|
|
52
52
|
@obj.the_method_will_be_called?
|
53
53
|
end
|
54
54
|
end
|
55
|
+
|
56
|
+
describe "aliasing" do
|
57
|
+
it "should alias method on the first call" do
|
58
|
+
@obj.stub(:the_method)
|
59
|
+
@obj.calling_the_method
|
60
|
+
@obj.methods.should include(:calling_the_method)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should alias method defined in the class in the scope of the class" do
|
64
|
+
@obj.class.send(:define_method, :the_method) {}
|
65
|
+
@obj.calling_the_method
|
66
|
+
@obj.class.instance_methods(false).should include(:calling_the_method)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should alias singleton method in the scope of the singleton" do
|
70
|
+
@obj.define_singleton_method(:sing_method) {}
|
71
|
+
@obj.calling_sing_method
|
72
|
+
@obj.sinlgeton_methods(false).should include(:calling_sing_method)
|
73
|
+
end
|
74
|
+
end
|
55
75
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 4
|
9
|
+
version: 0.0.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Chris Thorn
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-01-
|
17
|
+
date: 2011-01-08 00:00:00 -09:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -72,8 +72,8 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
72
72
|
segments:
|
73
73
|
- 1
|
74
74
|
- 9
|
75
|
-
-
|
76
|
-
version: 1.9.
|
75
|
+
- 2
|
76
|
+
version: 1.9.2
|
77
77
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
78
|
none: false
|
79
79
|
requirements:
|