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 CHANGED
@@ -1,3 +1,7 @@
1
+ ### 0.0.4
2
+
3
+ * alias the fscked methods instead of caching
4
+
1
5
  ### 0.0.3
2
6
 
3
7
  * better caching, better performance
data/Gemfile.lock CHANGED
@@ -1,20 +1,20 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fsck (0.0.1)
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.3.0)
11
- rspec-core (~> 2.3.0)
12
- rspec-expectations (~> 2.3.0)
13
- rspec-mocks (~> 2.3.0)
14
- rspec-core (2.3.0)
15
- rspec-expectations (2.3.0)
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.3.0)
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 greatly abusing `method_missing`. Each 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.
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 regex that allows for any number of other words to be inserted wherever. If you aren't careful with the words you choose, you may unintentionally call another method.
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
- Your application will take a more than trivial performance hit if you use this gem. The benchmark I ran on Fixnum (bench.rb) shows that using a fscked method is roughly 20 times slower. This only tests the performance of repeated fscked method calls (which should be most common use). If you're dynamically building a fscked method call based on some variable, you can expect much worse performance. Use at your own risk.
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.bm(10) do |r|
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
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
14
14
 
15
15
  s.rubyforge_project = "fsck"
16
16
 
17
- s.required_ruby_version = "~> 1.9.1"
17
+ s.required_ruby_version = "~> 1.9.2"
18
18
 
19
19
  s.add_development_dependency "rspec", "~> 2.3"
20
20
 
data/lib/fsck/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Fsck
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
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
- @_fsck_method_name_cache[sym] = matches.sort_by(&:length).last
21
- send(@_fsck_method_name_cache[sym], *args, &block)
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
 
@@ -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
- - 3
9
- version: 0.0.3
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-06 00:00:00 -09:00
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
- - 1
76
- version: 1.9.1
75
+ - 2
76
+ version: 1.9.2
77
77
  required_rubygems_version: !ruby/object:Gem::Requirement
78
78
  none: false
79
79
  requirements: