fsck 0.0.1 → 0.0.2

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/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ ### 0.0.2
2
+
3
+ * fluff at end of method with punctuation bug fix
4
+ * lightning fast caching!
5
+
6
+ ### 0.0.1
7
+
8
+ * initial release
@@ -1,6 +1,10 @@
1
1
  # Fsck
2
2
  Fsck allows you to express your feelings while you're developing. It does this by allowing you to add words to method names on the fly.
3
3
 
4
+ ## Installation
5
+
6
+ gem install fsck
7
+
4
8
  ## Examples
5
9
  Fsck allows you to have a sense of closure during your everyday development life. Here's some examples:
6
10
 
data/lib/fsck/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Fsck
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/fsck.rb CHANGED
@@ -1,15 +1,29 @@
1
1
  module Fsck
2
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
+
3
9
  matches = methods.select do |m|
4
- words = m.to_s.split("_").map { |w| Regexp.escape(w) }
5
- sym =~ /^(\w*_)?#{words.join('\w*_\w*')}(_\w*)?$/
10
+ fscked_method =~ /^#{__fsck_cache__(m)}#{punctuation}$/
6
11
  end
7
12
 
8
13
  if matches.empty?
9
14
  super
10
15
  else
11
- method = matches.sort_by(&:length).last
12
- send method, *args, &block
16
+ send(matches.sort_by(&:length).last, *args, &block)
13
17
  end
14
18
  end
19
+
20
+ private
21
+ def __fsck_cache__(method)
22
+ @_fsck_method_name_cache ||= {}
23
+
24
+ return @_fsck_method_name_cache[method] if @_fsck_method_name_cache[method]
25
+
26
+ words = method.to_s.delete("!?=").split("_").map { |w| Regexp.escape(w) }
27
+ @_fsck_method_name_cache[method] = "(\\w*_)?#{words.join('\w*_\w*')}(_\\w*)?"
28
+ end
15
29
  end
@@ -1,92 +1,55 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Fsck do
4
- describe "method is called" do
5
- before :each do
6
- @class = Class.new do
7
- include Fsck
8
-
9
- def the_method
10
- end
11
- end
12
- end
4
+ before :each do
5
+ @obj = Class.new { include Fsck }.new
6
+ end
13
7
 
8
+ describe "method is called" do
14
9
  it "should match method with fluff at the beginning" do
15
- obj = @class.new
16
- obj.should_receive(:the_method)
17
- obj.call_the_method
10
+ @obj.should_receive(:the_method)
11
+ @obj.call_the_method
18
12
  end
19
13
 
20
14
  it "should match method with fluff at the end" do
21
- obj = @class.new
22
- obj.should_receive(:the_method)
23
- obj.the_method_is_called
15
+ @obj.should_receive(:the_method)
16
+ @obj.the_method_is_called
24
17
  end
25
18
 
26
19
  it "should match method with fluff in the middle" do
27
- obj = @class.new
28
- obj.should_receive(:the_method)
29
- obj.the_awesome_method
20
+ @obj.should_receive(:the_method)
21
+ @obj.the_awesome_method
30
22
  end
31
23
  end
32
24
 
33
25
  describe "return value" do
34
- before :each do
35
- @class = Class.new do
36
- include Fsck
37
-
38
- def the_method
39
- 42
40
- end
41
- end
42
- end
43
-
44
26
  it "should return the value from the method" do
45
- obj = @class.new
46
- obj.the_method_will_obey.should eql(42)
27
+ @obj.should_receive(:the_method).and_return(42)
28
+ @obj.the_method_will_obey.should eql(42)
47
29
  end
48
30
  end
49
31
 
50
32
  describe "method parameters" do
51
- before :each do
52
- @class = Class.new do
53
- include Fsck
54
-
55
- def the_method(*args)
56
- end
57
- end
58
- end
59
-
60
33
  it "should pass along all parameters" do
61
- obj = @class.new
62
- obj.should_receive(:the_method).with(42, [1,2,3], "yo dawg")
63
- obj.the_awesome_method(42, [1,2,3], "yo dawg")
34
+ @obj.should_receive(:the_method).with(42, [1,2,3], "yo dawg")
35
+ @obj.the_awesome_method(42, [1,2,3], "yo dawg")
64
36
  end
65
37
  end
66
38
 
67
39
  describe "whacky method names" do
68
- before :each do
69
- @class = Class.new do
70
- include Fsck
71
-
72
- def []
73
- end
74
-
75
- def the_method
76
- end
77
- end
78
- end
79
-
80
40
  it "should pass the regex when containing regex special characters" do
81
- obj = @class.new
82
- obj.should_receive(:[])
83
- obj.send "square_[]_brackets"
41
+ @obj.should_receive(:[])
42
+ @obj.send "square_[]_brackets"
84
43
  end
85
44
 
86
45
  it "should not match within words" do
87
- obj = @class.new
88
- obj.should_not_receive(:the_method)
89
- obj.the_methods
46
+ @obj.should_not_receive(:the_method)
47
+ @obj.the_methods
48
+ end
49
+
50
+ it "should allow fluff at the end of punctuated methods" do
51
+ @obj.should_receive(:the_method?)
52
+ @obj.the_method_will_be_called?
90
53
  end
91
54
  end
92
55
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
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-04 00:00:00 -09:00
17
+ date: 2011-01-05 00:00:00 -09:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -42,9 +42,10 @@ extra_rdoc_files: []
42
42
 
43
43
  files:
44
44
  - .gitignore
45
+ - CHANGELOG.md
45
46
  - Gemfile
46
47
  - Gemfile.lock
47
- - README.rdoc
48
+ - README.md
48
49
  - Rakefile
49
50
  - fsck.gemspec
50
51
  - lib/fsck.rb