shuber-interface 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -45,10 +45,7 @@ module Interface
45
45
 
46
46
  # Returns an array of methods from the specified <tt>interface</tt> that the current object does not implement
47
47
  def unimplemented_methods_for(interface)
48
- interface.instance_methods(false).reject do |method|
49
- method = method.to_sym
50
- (respond_to?(method, true) && self.method(method).owner != interface) || respond_to_missing?(method, true)
51
- end.sort
48
+ interface.instance_methods(false).reject { |method| respond_to_missing?(method.to_sym, true) || self.method(method.to_sym).owner != interface }.sort
52
49
  end
53
50
 
54
51
  # <tt>Object#respond_to_missing?</tt> wasn't implemented until ruby version 1.9
@@ -1,14 +1,20 @@
1
1
  module Interface
2
- # When extended, this abstract interface will re-define an object's methods to raise <tt>NotImplementedError</tt> when called (unless handled by <tt>method_missing</tt>)
2
+ # When extended, this module will re-define an interface's methods to raise <tt>NotImplementedError</tt> when called (unless handled by <tt>method_missing</tt>)
3
3
  module Abstract
4
- def self.extended(base) # :nodoc:
5
- base.class_eval do
4
+ def self.extended(interface) # :nodoc:
5
+ interface.class_eval do
6
6
  instance_methods(false).each do |method|
7
7
  define_method(method) do |*args, &block|
8
+ methods = [:super, :method_missing]
8
9
  begin
9
- method_missing(method.to_sym, *args, &block)
10
+ send(methods.shift, *args, &block)
10
11
  rescue NoMethodError
11
- raise NotImplementedError.new("#{self.class} needs to implement '#{method}' for interface #{base}")
12
+ if methods.empty?
13
+ raise NotImplementedError.new("#{self.class} needs to implement '#{method}' for interface #{interface}")
14
+ else
15
+ args.unshift(method.to_sym)
16
+ retry
17
+ end
12
18
  end
13
19
  end
14
20
  end
@@ -3,7 +3,7 @@ module Interface
3
3
  module Version
4
4
  MAJOR = 0
5
5
  MINOR = 0
6
- PATCH = 3
6
+ PATCH = 4
7
7
 
8
8
  # Returns a version string by joining <tt>MAJOR</tt>, <tt>MINOR</tt>, and <tt>PATCH</tt> with <tt>'.'</tt>
9
9
  #
@@ -7,11 +7,18 @@ module Remote
7
7
  def on
8
8
  end
9
9
 
10
+ def on?
11
+ end
12
+
10
13
  def off
11
14
  end
12
15
  end
13
16
 
14
17
  class BrokenDevice
18
+ def on?
19
+ !!@power
20
+ end
21
+
15
22
  implements Remote, MockInterface
16
23
  end
17
24
 
@@ -87,4 +94,9 @@ class InterfaceTest < Test::Unit::TestCase
87
94
  assert respond_to?(:respond_to_missing?)
88
95
  end
89
96
 
97
+ def test_should_call_super
98
+ assert !BrokenDevice.new.on?
99
+ assert !Device.new.on?
100
+ end
101
+
90
102
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shuber-interface
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sean Huber