irregular_method 0.1.0 → 0.1.1

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{irregular_method}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Mike Nelson"]
12
- s.date = %q{2010-02-01}
12
+ s.date = %q{2010-02-18}
13
13
  s.description = %q{Writing a bunch of case statements to handle regular expressions in method missing is just plain annoying. I suggest they get separated out and defined as their own methods. Well... ruby doesn't really let that happen, but there is an alternative.}
14
14
  s.email = %q{mdnelson30@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
27
27
  "lib/irregular_method.rb",
28
28
  "spec/irregular_method_spec.rb",
29
29
  "spec/models/method_missing.rb",
30
+ "spec/models/user.rb",
30
31
  "spec/schema.rb",
31
32
  "spec/spec.opts",
32
33
  "spec/spec_helper.rb"
@@ -39,6 +40,7 @@ Gem::Specification.new do |s|
39
40
  s.test_files = [
40
41
  "spec/irregular_method_spec.rb",
41
42
  "spec/models/method_missing.rb",
43
+ "spec/models/user.rb",
42
44
  "spec/schema.rb",
43
45
  "spec/spec_helper.rb"
44
46
  ]
@@ -26,7 +26,7 @@ module Irregular
26
26
 
27
27
 
28
28
  def method_missing(name, *args)
29
- method_id = name.id2name
29
+ method_id = name.to_s
30
30
  irregular_methods && irregular_methods.each do |context|
31
31
  regex = context[0]
32
32
  block = context[1]
@@ -36,7 +36,23 @@ module Irregular
36
36
  end
37
37
  end
38
38
  end
39
- super
39
+ super(name, *args)
40
+ end
41
+
42
+ def respond_to?(method_name)
43
+ result = super(method_name)
44
+ if !result
45
+ method_id = method_name.to_s
46
+ irregular_methods && irregular_methods.each do |context|
47
+ regex = context[0]
48
+ regex.each do |reg|
49
+ if method_id =~ reg
50
+ return true
51
+ end
52
+ end
53
+ end
54
+ end
55
+ result
40
56
  end
41
57
 
42
58
  end
@@ -11,4 +11,13 @@ describe "IrregularMethod" do
11
11
  mm.test_multiple.should eql('mm1 handles multiple options: test')
12
12
  mm.success_options.should eql('mm1 handles multiple options: success')
13
13
  end
14
+
15
+
16
+ # this is why respond_to? is overridden
17
+ it "should handle association proxies correctly" do
18
+
19
+ u = User.create(:method_missing => MethodMissing.create(:name => 'mm2'), :name => 'fred')
20
+ u.method_missing.nothing_test.should eql('mm2 found: nothing')
21
+
22
+ end
14
23
  end
@@ -0,0 +1,3 @@
1
+ class User < ActiveRecord::Base
2
+ belongs_to :method_missing
3
+ end
data/spec/schema.rb CHANGED
@@ -5,4 +5,9 @@ ActiveRecord::Schema.define :version => 0 do
5
5
  t.timestamps
6
6
  end
7
7
 
8
+ create_table :user, :force => true do |t|
9
+ t.string :name
10
+ t.integer :method_missing_id
11
+ t.timestamps
12
+ end
8
13
  end
data/spec/spec_helper.rb CHANGED
@@ -6,6 +6,7 @@ require 'irregular_method'
6
6
  require 'spec'
7
7
  require 'spec/autorun'
8
8
  require 'models/method_missing'
9
+ require 'models/user'
9
10
 
10
11
  ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + '/debug.log')
11
12
  ActiveRecord::Base.configurations = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: irregular_method
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Nelson
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-01 00:00:00 -05:00
12
+ date: 2010-02-18 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -42,6 +42,7 @@ files:
42
42
  - lib/irregular_method.rb
43
43
  - spec/irregular_method_spec.rb
44
44
  - spec/models/method_missing.rb
45
+ - spec/models/user.rb
45
46
  - spec/schema.rb
46
47
  - spec/spec.opts
47
48
  - spec/spec_helper.rb
@@ -76,5 +77,6 @@ summary: Method missing is messy. Fix it by defining regular expression methods.
76
77
  test_files:
77
78
  - spec/irregular_method_spec.rb
78
79
  - spec/models/method_missing.rb
80
+ - spec/models/user.rb
79
81
  - spec/schema.rb
80
82
  - spec/spec_helper.rb