fsck 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  pkg/*
2
2
  *.gem
3
3
  .bundle
4
+ .rspec
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ### 0.0.5
2
+
3
+ * add respond_to_missing support
4
+
1
5
  ### 0.0.4
2
6
 
3
7
  * alias the fscked methods instead of caching
@@ -13,4 +17,4 @@
13
17
 
14
18
  ### 0.0.1
15
19
 
16
- * initial release
20
+ * initial release
data/Gemfile.lock CHANGED
@@ -6,15 +6,15 @@ PATH
6
6
  GEM
7
7
  remote: http://rubygems.org/
8
8
  specs:
9
- diff-lcs (1.1.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
- diff-lcs (~> 1.1.2)
17
- rspec-mocks (2.4.0)
9
+ diff-lcs (1.1.3)
10
+ rspec (2.12.0)
11
+ rspec-core (~> 2.12.0)
12
+ rspec-expectations (~> 2.12.0)
13
+ rspec-mocks (~> 2.12.0)
14
+ rspec-core (2.12.1)
15
+ rspec-expectations (2.12.0)
16
+ diff-lcs (~> 1.1.3)
17
+ rspec-mocks (2.12.0)
18
18
 
19
19
  PLATFORMS
20
20
  ruby
data/Rakefile CHANGED
@@ -1,2 +1,8 @@
1
1
  require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task :default => :spec
data/fsck.gemspec CHANGED
@@ -13,9 +13,9 @@ Gem::Specification.new do |s|
13
13
  s.description = s.summary
14
14
 
15
15
  s.rubyforge_project = "fsck"
16
-
16
+
17
17
  s.required_ruby_version = "~> 1.9.2"
18
-
18
+
19
19
  s.add_development_dependency "rspec", "~> 2.3"
20
20
 
21
21
  s.files = `git ls-files`.split("\n")
data/lib/fsck/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Fsck
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/fsck.rb CHANGED
@@ -1,28 +1,38 @@
1
1
  module Fsck
2
- def method_missing(sym, *args, &block)
3
- fscked_method = sym.to_s
4
-
5
- if punctuation = fscked_method[/[!?=]$/]
6
- fscked_method.chop!
7
- end
8
-
9
- matches = methods.select do |m|
10
- fscked_method =~ /^#{__fsck_method_regex_str__(m)}#{punctuation}$/
11
- end
2
+ def method_missing(method_name, *args, &block)
3
+ fscked_method = __fsck_method__(method_name)
12
4
 
13
- if matches.empty?
14
- super
5
+ if fscked_method
6
+ target = singleton_methods.include?(fscked_method) ? singleton_class : self.class
7
+ target.class_exec { alias_method(method_name, fscked_method) }
8
+ send(method_name, *args, &block)
15
9
  else
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)
10
+ super
20
11
  end
21
12
  end
22
-
13
+
14
+ def respond_to_missing?(method_name, include_private = false)
15
+ !!__fsck_method__(method_name)
16
+ end
17
+
23
18
  private
19
+
24
20
  def __fsck_method_regex_str__(method)
25
21
  words = method.to_s.delete("!?=").split("_").map { |w| Regexp.escape(w) }
26
22
  "(\\w*_)?#{words.join('\w*_\w*')}(_\\w*)?"
27
23
  end
24
+
25
+ def __fsck_method__(method_name)
26
+ fscked_method = method_name.to_s
27
+
28
+ if punctuation = fscked_method[/[!?=]$/]
29
+ fscked_method.chop!
30
+ end
31
+
32
+ matches = methods.select do |method|
33
+ fscked_method =~ /^#{__fsck_method_regex_str__(method)}#{punctuation}$/
34
+ end
35
+
36
+ matches.max_by(&:length)
37
+ end
28
38
  end
@@ -1,75 +1,80 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Fsck do
4
- before :each do
5
- @obj = Class.new { include Fsck }.new
6
- end
7
-
4
+ subject { Class.new { include Fsck }.new }
5
+
8
6
  describe "method is called" do
9
7
  it "should match method with fluff at the beginning" do
10
- @obj.should_receive(:the_method)
11
- @obj.call_the_method
8
+ subject.should_receive(:the_method)
9
+ subject.call_the_method
12
10
  end
13
-
11
+
14
12
  it "should match method with fluff at the end" do
15
- @obj.should_receive(:the_method)
16
- @obj.the_method_is_called
13
+ subject.should_receive(:the_method)
14
+ subject.the_method_is_called
17
15
  end
18
-
16
+
19
17
  it "should match method with fluff in the middle" do
20
- @obj.should_receive(:the_method)
21
- @obj.the_awesome_method
18
+ subject.should_receive(:the_method)
19
+ subject.the_awesome_method
22
20
  end
23
21
  end
24
-
22
+
25
23
  describe "return value" do
26
24
  it "should return the value from the method" do
27
- @obj.should_receive(:the_method).and_return(42)
28
- @obj.the_method_will_obey.should eql(42)
25
+ subject.should_receive(:the_method).and_return(42)
26
+ subject.the_method_will_obey.should eql(42)
29
27
  end
30
28
  end
31
-
29
+
32
30
  describe "method parameters" do
33
31
  it "should pass along all parameters" do
34
- @obj.should_receive(:the_method).with(42, [1,2,3], "yo dawg")
35
- @obj.the_awesome_method(42, [1,2,3], "yo dawg")
32
+ subject.should_receive(:the_method).with(42, [1,2,3], "yo dawg")
33
+ subject.the_awesome_method(42, [1,2,3], "yo dawg")
36
34
  end
37
35
  end
38
-
36
+
39
37
  describe "whacky method names" do
40
38
  it "should pass the regex when containing regex special characters" do
41
- @obj.should_receive(:[])
42
- @obj.send "square_[]_brackets"
39
+ subject.should_receive(:[])
40
+ subject.send "square_[]_brackets"
43
41
  end
44
-
42
+
45
43
  it "should not match within words" do
46
- @obj.should_not_receive(:the_method)
47
- @obj.the_methods
44
+ subject.should_not_receive(:the_method)
45
+ subject.the_methods
48
46
  end
49
-
47
+
50
48
  it "should allow fluff at the end of punctuated methods" do
51
- @obj.should_receive(:the_method?)
52
- @obj.the_method_will_be_called?
49
+ subject.should_receive(:the_method?)
50
+ subject.the_method_will_be_called?
53
51
  end
54
52
  end
55
-
53
+
56
54
  describe "aliasing" do
57
55
  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)
56
+ subject.stub(:the_method)
57
+ subject.calling_the_method
58
+ subject.methods.should include(:calling_the_method)
61
59
  end
62
-
60
+
63
61
  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)
62
+ subject.class.send(:define_method, :the_method) {}
63
+ subject.calling_the_method
64
+ subject.class.instance_methods(false).should include(:calling_the_method)
67
65
  end
68
-
66
+
69
67
  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)
68
+ subject.define_singleton_method(:sing_method) {}
69
+ subject.calling_sing_method
70
+ subject.sinlgeton_methods(false).should include(:calling_sing_method)
71
+ end
72
+ end
73
+
74
+ describe "respond to" do
75
+ it "should respond to fsked method" do
76
+ subject.stub(:the_method?)
77
+ subject.should respond_to :the_awesome_method?
73
78
  end
74
79
  end
75
- end
80
+ end
metadata CHANGED
@@ -1,46 +1,39 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: fsck
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 4
9
- version: 0.0.4
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Chris Thorn
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2011-01-08 00:00:00 -09:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-12-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: rspec
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
18
+ requirements:
26
19
  - - ~>
27
- - !ruby/object:Gem::Version
28
- segments:
29
- - 2
30
- - 3
31
- version: "2.3"
20
+ - !ruby/object:Gem::Version
21
+ version: '2.3'
32
22
  type: :development
33
- version_requirements: *id001
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '2.3'
34
30
  description: A gem that allows you to be yourself while writing code.
35
- email:
31
+ email:
36
32
  - thorncp@gmail.com
37
33
  executables: []
38
-
39
34
  extensions: []
40
-
41
35
  extra_rdoc_files: []
42
-
43
- files:
36
+ files:
44
37
  - .gitignore
45
38
  - CHANGELOG.md
46
39
  - Gemfile
@@ -55,40 +48,30 @@ files:
55
48
  - license.txt
56
49
  - spec/fsck/fsck_spec.rb
57
50
  - spec/spec_helper.rb
58
- has_rdoc: true
59
- homepage: ""
51
+ homepage: ''
60
52
  licenses: []
61
-
62
53
  post_install_message:
63
54
  rdoc_options: []
64
-
65
- require_paths:
55
+ require_paths:
66
56
  - lib
67
- required_ruby_version: !ruby/object:Gem::Requirement
57
+ required_ruby_version: !ruby/object:Gem::Requirement
68
58
  none: false
69
- requirements:
59
+ requirements:
70
60
  - - ~>
71
- - !ruby/object:Gem::Version
72
- segments:
73
- - 1
74
- - 9
75
- - 2
61
+ - !ruby/object:Gem::Version
76
62
  version: 1.9.2
77
- required_rubygems_version: !ruby/object:Gem::Requirement
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
64
  none: false
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- segments:
83
- - 0
84
- version: "0"
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
85
69
  requirements: []
86
-
87
70
  rubyforge_project: fsck
88
- rubygems_version: 1.3.7
71
+ rubygems_version: 1.8.24
89
72
  signing_key:
90
73
  specification_version: 3
91
74
  summary: A gem that allows you to be yourself while writing code.
92
- test_files:
75
+ test_files:
93
76
  - spec/fsck/fsck_spec.rb
94
77
  - spec/spec_helper.rb