interface 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGES +4 -1
- data/README +74 -77
- data/Rakefile +46 -39
- data/examples/example_instance.rb +6 -6
- data/examples/example_interface.rb +10 -9
- data/examples/example_sub.rb +13 -13
- data/examples/example_unrequire.rb +9 -9
- data/interface.gemspec +18 -19
- data/lib/interface.rb +83 -77
- data/test/test_interface.rb +54 -57
- metadata +56 -43
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 23d3e90da2f1b1e9211caa134f5cbf2fa7500080
|
4
|
+
data.tar.gz: 582c023b875152e4c92b549968d11d952469b331
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0d1d5fafe57cd928828aa00e6f08037dc275e7a420f9ca1714dc016799d5aceb052910ff89d29e8df0ee446d79a9ef2ed1db8728928dbbc6f016abe6fb50b807
|
7
|
+
data.tar.gz: f59cddb23c7ea032f150d907135826bad6b8cd0a0f4bd5d40d8aec14704194948965c984d037fb9e04ec59f782cb5dadb78c1e2a2e1d5f362e7a2604b770d005
|
data/CHANGES
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
== 1.0.3 - 12-Oct-2014
|
2
|
+
* Rakefile, gemspec and README updates.
|
3
|
+
|
1
4
|
== 1.0.2 - 7-Oct-2009
|
2
5
|
* Fixed packaging bug in the gemspec, and made some other minor changes.
|
3
6
|
* Added the 'gem' rake task.
|
@@ -20,4 +23,4 @@
|
|
20
23
|
* Some test suite and doc changes.
|
21
24
|
|
22
25
|
== 0.1.0 - 9-May-2004
|
23
|
-
* Initial release
|
26
|
+
* Initial release
|
data/README
CHANGED
@@ -1,77 +1,74 @@
|
|
1
|
-
== Description
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
== Installation
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
==
|
74
|
-
|
75
|
-
|
76
|
-
== Author
|
77
|
-
Daniel J. Berger
|
1
|
+
== Description
|
2
|
+
This module provides Java style interfaces for Ruby, including a fairly
|
3
|
+
similar syntax. I don't necessarily believe in interfaces, but I wanted to
|
4
|
+
put it out there as proof that it could be done. Frankly, Java needs mixins
|
5
|
+
more than Ruby needs interfaces, but here you go.
|
6
|
+
|
7
|
+
== Installation
|
8
|
+
gem install interface
|
9
|
+
|
10
|
+
== Synopsis
|
11
|
+
require 'interface'
|
12
|
+
|
13
|
+
MyInterface = interface{
|
14
|
+
required_methods :foo, :bar, :baz
|
15
|
+
}
|
16
|
+
|
17
|
+
# Raises an error until 'baz' is defined
|
18
|
+
class MyClass
|
19
|
+
def foo
|
20
|
+
puts "foo"
|
21
|
+
end
|
22
|
+
|
23
|
+
def bar
|
24
|
+
puts "bar"
|
25
|
+
end
|
26
|
+
|
27
|
+
implements MyInterface
|
28
|
+
end
|
29
|
+
|
30
|
+
== General Notes
|
31
|
+
Subinterfaces work as well. See the test_sub.rb file under the 'test'
|
32
|
+
directory for a sample.
|
33
|
+
|
34
|
+
== Developer's Notes
|
35
|
+
A discussion on IRC with Mauricio Fernandez got us talking about traits.
|
36
|
+
During that discussion I remembered a blog entry by David Naseby. I
|
37
|
+
revisited his blog entry and took a closer look:
|
38
|
+
|
39
|
+
http://ruby-naseby.blogspot.com/2008/11/traits-in-ruby.html
|
40
|
+
|
41
|
+
Keep in mind that I also happened to be thinking about Java at the moment
|
42
|
+
because of a recent job switch that involved coding in Java. I was also
|
43
|
+
trying to figure out what the purpose of interfaces were.
|
44
|
+
|
45
|
+
As I read the first page of David Naseby's article I realized that,
|
46
|
+
whether intended or not, he had implemented a rudimentary form of interfaces
|
47
|
+
for Ruby. When I discovered this, I talked about it some more with Mauricio
|
48
|
+
and he and I (mostly him) fleshed out the rest of the module, including some
|
49
|
+
syntax improvements. The result is syntax and functionality that is nearly
|
50
|
+
identical to Java.
|
51
|
+
|
52
|
+
I should note that, although I am listed as the author, this was mostly the
|
53
|
+
combined work of David Naseby and Mauricio Fernandez. I just happened to be
|
54
|
+
the guy that put it all together.
|
55
|
+
|
56
|
+
== Acknowledgements
|
57
|
+
This module was largely inspired and somewhat copied from a post by
|
58
|
+
David Naseby (see URL above). It was subsequently modified almost entirely
|
59
|
+
by Mauricio Fernandez through a series of discussions on IRC.
|
60
|
+
|
61
|
+
== Copyright
|
62
|
+
(C) 2004-2014 Daniel J. Berger
|
63
|
+
All rights reserved.
|
64
|
+
|
65
|
+
== Warranty
|
66
|
+
This package is provided "as is" and without any express or
|
67
|
+
implied warranties, including, without limitation, the implied
|
68
|
+
warranties of merchantability and fitness for a particular purpose.
|
69
|
+
|
70
|
+
== License
|
71
|
+
Artistic 2.0
|
72
|
+
|
73
|
+
== Author
|
74
|
+
Daniel J. Berger
|
data/Rakefile
CHANGED
@@ -1,46 +1,53 @@
|
|
1
1
|
require 'rake'
|
2
|
+
require 'rake/clean'
|
2
3
|
require 'rake/testtask'
|
3
|
-
require 'rbconfig'
|
4
|
-
include Config
|
5
|
-
|
6
|
-
desc 'Install the interface library (non-gem)'
|
7
|
-
task :install do
|
8
|
-
sitelibdir = CONFIG["sitelibdir"]
|
9
|
-
file = "lib/interface.rb"
|
10
|
-
FileUtils.cp(file, sitelibdir, :verbose => true)
|
11
|
-
end
|
12
|
-
|
13
|
-
task :gem do
|
14
|
-
spec = eval(IO.read('interface.gemspec'))
|
15
|
-
Gem::Builder.new(spec).build
|
16
|
-
end
|
17
|
-
|
18
|
-
task :install_gem => [:gem] do
|
19
|
-
file = Dir["*.gem"].first
|
20
|
-
sh "gem install #{file}"
|
21
|
-
end
|
22
|
-
|
23
|
-
desc 'Run the example_instance.rb sample program'
|
24
|
-
task :example_instance do
|
25
|
-
ruby '-Ilib examples/example_instance.rb'
|
26
|
-
end
|
27
|
-
|
28
|
-
desc 'Run the example_interface.rb sample program'
|
29
|
-
task :example_interface do
|
30
|
-
ruby '-Ilib examples/example_interface.rb'
|
31
|
-
end
|
32
4
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
5
|
+
CLEAN.include("**/*.gem", "**/*.rbc")
|
6
|
+
|
7
|
+
namespace :gem do
|
8
|
+
desc "Create the interface gem"
|
9
|
+
task :create => [:clean] do
|
10
|
+
spec = eval(IO.read('interface.gemspec'))
|
11
|
+
if Gem::VERSION < "2.0"
|
12
|
+
Gem::Builder.new(spec).build
|
13
|
+
else
|
14
|
+
require 'rubygems/package'
|
15
|
+
Gem::Package.build(spec)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
desc "Install the interface gem"
|
20
|
+
task :install => [:create] do
|
21
|
+
file = Dir["*.gem"].first
|
22
|
+
sh "gem install -l #{file}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
namespace :example do
|
27
|
+
desc 'Run the example_instance.rb sample program'
|
28
|
+
task :instance do
|
29
|
+
ruby '-Ilib examples/example_instance.rb'
|
30
|
+
end
|
31
|
+
|
32
|
+
desc 'Run the example_interface.rb sample program'
|
33
|
+
task :interface do
|
34
|
+
ruby '-Ilib examples/example_interface.rb'
|
35
|
+
end
|
36
|
+
|
37
|
+
desc 'Run the example_sub.rb sample program'
|
38
|
+
task :sub do
|
39
|
+
ruby '-Ilib examples/example_sub.rb'
|
40
|
+
end
|
41
|
+
|
42
|
+
desc 'Run the example_unrequire.rb sample program'
|
43
|
+
task :unrequire do
|
44
|
+
ruby '-Ilib examples/example_unrequire.rb'
|
45
|
+
end
|
41
46
|
end
|
42
47
|
|
43
48
|
Rake::TestTask.new do |t|
|
44
|
-
|
45
|
-
|
49
|
+
t.verbose = true
|
50
|
+
t.warning = true
|
46
51
|
end
|
52
|
+
|
53
|
+
task :default => :test
|
@@ -2,18 +2,18 @@
|
|
2
2
|
# example_instance.rb
|
3
3
|
#
|
4
4
|
# Sample program to demonstrate extending an interface to an instance
|
5
|
-
# of a class. You can run this program via the 'rake
|
5
|
+
# of a class. You can run this program via the 'rake example:instance'
|
6
6
|
# task. Modify as you see fit.
|
7
7
|
#######################################################################
|
8
8
|
require 'interface'
|
9
9
|
|
10
10
|
MyInterface = interface{
|
11
|
-
|
11
|
+
required_methods :foo, :bar
|
12
12
|
}
|
13
13
|
|
14
14
|
class Foo
|
15
|
-
|
16
|
-
|
15
|
+
def foo; end
|
16
|
+
def bar; end
|
17
17
|
end
|
18
18
|
|
19
19
|
class Bar
|
@@ -26,5 +26,5 @@ b = Bar.new
|
|
26
26
|
|
27
27
|
# This will blow up
|
28
28
|
class << b
|
29
|
-
|
30
|
-
end
|
29
|
+
include MyInterface
|
30
|
+
end
|
@@ -2,26 +2,27 @@
|
|
2
2
|
# example_interface.rb
|
3
3
|
#
|
4
4
|
# Sample test script that demonstrates a typical interface. You can
|
5
|
-
# run this example via the 'rake
|
5
|
+
# run this example via the 'rake example:interface' task. Modify this
|
6
6
|
# code as you see fit.
|
7
7
|
#######################################################################
|
8
8
|
require 'interface'
|
9
9
|
|
10
10
|
MyInterface = interface{
|
11
|
-
|
11
|
+
required_methods :foo, :bar
|
12
12
|
}
|
13
13
|
|
14
14
|
class MyClass
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
def foo; end
|
16
|
+
def bar; end
|
17
|
+
include MyInterface
|
18
18
|
end
|
19
19
|
|
20
20
|
=begin
|
21
21
|
# Raises an error until bar is defined
|
22
22
|
class Foo
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
def foo
|
24
|
+
puts "foo"
|
25
|
+
end
|
26
|
+
include MyInterface
|
26
27
|
end
|
27
|
-
=end
|
28
|
+
=end
|
data/examples/example_sub.rb
CHANGED
@@ -2,33 +2,33 @@
|
|
2
2
|
# example_sub.rb
|
3
3
|
#
|
4
4
|
# Sample program to demonstrate extending a sub-interface. You can
|
5
|
-
# run this program via the 'rake
|
5
|
+
# run this program via the 'rake example:sub' task. Modify this code
|
6
6
|
# as you see fit.
|
7
7
|
#######################################################################
|
8
8
|
require 'interface'
|
9
9
|
|
10
10
|
module MyInterface
|
11
|
-
|
12
|
-
|
11
|
+
extend Interface
|
12
|
+
required_methods :foo, :bar
|
13
13
|
end
|
14
14
|
|
15
15
|
module MySubInterface
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
extend Interface
|
17
|
+
extend MyInterface
|
18
|
+
required_methods :baz
|
19
19
|
end
|
20
20
|
|
21
21
|
class MyClass
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
def baz; end
|
23
|
+
def bar; end
|
24
|
+
def foo; end
|
25
|
+
include MySubInterface
|
26
26
|
end
|
27
27
|
|
28
28
|
=begin
|
29
29
|
# Raises an error
|
30
30
|
class MyClass
|
31
|
-
|
32
|
-
|
31
|
+
def baz; end
|
32
|
+
include MyInterface
|
33
33
|
end
|
34
|
-
=end
|
34
|
+
=end
|
@@ -2,25 +2,25 @@
|
|
2
2
|
# example_unrequire.rb
|
3
3
|
#
|
4
4
|
# Sample test script for to verify that unrequired_methods works properly.
|
5
|
-
# You can run this code via the 'rake
|
5
|
+
# You can run this code via the 'rake example:unrequire' rake task. Modify
|
6
6
|
# this code as you see fit.
|
7
7
|
###########################################################################
|
8
8
|
require 'interface'
|
9
9
|
|
10
10
|
MyInterface = interface{
|
11
|
-
|
11
|
+
required_methods :foo, :bar
|
12
12
|
}
|
13
13
|
|
14
14
|
# require foo and baz, but not bar
|
15
15
|
MySubInterface = interface{
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
extends MyInterface
|
17
|
+
required_methods :baz
|
18
|
+
unrequired_methods :bar
|
19
19
|
}
|
20
20
|
|
21
21
|
# No error
|
22
22
|
class MyClass
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
23
|
+
def foo; end
|
24
|
+
def baz; end
|
25
|
+
include MySubInterface
|
26
|
+
end
|
data/interface.gemspec
CHANGED
@@ -1,25 +1,24 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
|
3
|
-
Gem::Specification.new do |
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
gem.files = Dir['**/*'].reject{ |f| f.include?('CVS') }
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'interface'
|
5
|
+
spec.version = '1.0.3'
|
6
|
+
spec.author = 'Daniel J. Berger'
|
7
|
+
spec.license = 'Artistic 2.0'
|
8
|
+
spec.email = 'djberg96@gmail.com'
|
9
|
+
spec.homepage = 'https://github.com/djberg96/interface'
|
10
|
+
spec.summary = 'Java style interfaces for Ruby'
|
11
|
+
spec.test_file = 'test/test_interface.rb'
|
12
|
+
spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
|
14
13
|
|
15
|
-
|
16
|
-
gem.rubyforge_project = 'shards'
|
14
|
+
spec.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
|
17
15
|
|
18
|
-
|
16
|
+
spec.add_development_dependency('test-unit')
|
17
|
+
spec.add_development_dependency('rake')
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
spec.description = <<-EOF
|
20
|
+
The interface library implements Java style interfaces for Ruby.
|
21
|
+
It lets you define a set a methods that must be defined in the
|
22
|
+
including class or module, or an error is raised.
|
23
|
+
EOF
|
25
24
|
end
|
data/lib/interface.rb
CHANGED
@@ -4,98 +4,104 @@
|
|
4
4
|
# http://java.sun.com/docs/books/tutorial/java/concepts/interface.html
|
5
5
|
#
|
6
6
|
module Interface
|
7
|
-
|
8
|
-
|
7
|
+
# The version of the interface library.
|
8
|
+
Interface::VERSION = '1.0.3'
|
9
9
|
|
10
|
-
|
11
|
-
|
10
|
+
# Raised if a class or instance does not meet the interface requirements.
|
11
|
+
class MethodMissing < RuntimeError; end
|
12
12
|
|
13
|
-
|
13
|
+
alias :extends :extend
|
14
14
|
|
15
|
-
|
15
|
+
private
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
17
|
+
def extend_object(obj)
|
18
|
+
return append_features(obj) if Interface === obj
|
19
|
+
append_features(class << obj; self end)
|
20
|
+
included(obj)
|
21
|
+
end
|
22
|
+
|
23
|
+
def append_features(mod)
|
24
|
+
return super if Interface === mod
|
25
25
|
|
26
|
-
|
27
|
-
|
26
|
+
# Is this a sub-interface?
|
27
|
+
inherited = (self.ancestors-[self]).select{ |x| Interface === x }
|
28
|
+
inherited = inherited.map{ |x| x.instance_variable_get('@ids') }
|
28
29
|
|
29
|
-
|
30
|
-
|
30
|
+
# Store required method ids
|
31
|
+
ids = @ids + inherited.flatten
|
32
|
+
@unreq ||= []
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
# Iterate over the methods, minus the unrequired methods, and raise
|
35
|
+
# an error if the method has not been defined.
|
36
|
+
(ids - @unreq).uniq.each do |id|
|
37
|
+
id = id.to_s if RUBY_VERSION.to_f < 1.9
|
38
|
+
unless mod.instance_methods(true).include?(id)
|
39
|
+
raise Interface::MethodMissing, id
|
37
40
|
end
|
41
|
+
end
|
38
42
|
|
39
|
-
|
40
|
-
|
43
|
+
super mod
|
44
|
+
end
|
41
45
|
|
42
|
-
|
46
|
+
public
|
43
47
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
48
|
+
# Accepts an array of method names that define the interface. When this
|
49
|
+
# module is included/implemented, those method names must have already been
|
50
|
+
# defined.
|
51
|
+
#
|
52
|
+
def required_methods(*ids)
|
53
|
+
@ids = ids
|
54
|
+
end
|
51
55
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
56
|
+
# Accepts an array of method names that are removed as a requirement for
|
57
|
+
# implementation. Presumably you would use this in a sub-interface where
|
58
|
+
# you only wanted a partial implementation of an existing interface.
|
59
|
+
#
|
60
|
+
def unrequired_methods(*ids)
|
61
|
+
@unreq ||= []
|
62
|
+
@unreq += ids
|
63
|
+
end
|
60
64
|
end
|
61
65
|
|
62
|
-
|
63
|
-
#
|
64
|
-
#
|
65
|
-
#
|
66
|
-
#
|
67
|
-
#
|
68
|
-
#
|
69
|
-
#
|
70
|
-
#
|
71
|
-
#
|
72
|
-
#
|
73
|
-
#
|
74
|
-
#
|
75
|
-
#
|
76
|
-
#
|
77
|
-
#
|
78
|
-
#
|
79
|
-
#
|
80
|
-
#
|
81
|
-
#
|
82
|
-
#
|
83
|
-
#
|
84
|
-
#
|
85
|
-
#
|
86
|
-
#
|
87
|
-
#
|
88
|
-
#
|
89
|
-
#
|
90
|
-
#
|
91
|
-
#
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
66
|
+
class Object
|
67
|
+
# The interface method creates an interface module which typically sets
|
68
|
+
# a list of methods that must be defined in the including class or module.
|
69
|
+
# If the methods are not defined, an Interface::MethodMissing error is raised.
|
70
|
+
#
|
71
|
+
# A interface can extend an existing interface as well. These are called
|
72
|
+
# sub-interfaces, and they can included the rules for their parent interface
|
73
|
+
# by simply extending it.
|
74
|
+
#
|
75
|
+
# Example:
|
76
|
+
#
|
77
|
+
# # Require 'alpha' and 'beta' methods
|
78
|
+
# AlphaInterface = interface{
|
79
|
+
# required_methods :alpha, :beta
|
80
|
+
# }
|
81
|
+
#
|
82
|
+
# # A sub-interface that requires 'beta' and 'gamma' only
|
83
|
+
# GammaInterface = interface{
|
84
|
+
# extends AlphaInterface
|
85
|
+
# required_methods :gamma
|
86
|
+
# unrequired_methods :alpha
|
87
|
+
# }
|
88
|
+
#
|
89
|
+
# # Raises an Interface::MethodMissing error because :beta is not defined.
|
90
|
+
# class MyClass
|
91
|
+
# def alpha
|
92
|
+
# # ...
|
93
|
+
# end
|
94
|
+
# implements AlphaInterface
|
95
|
+
# end
|
96
|
+
#
|
97
|
+
def interface(&block)
|
98
|
+
mod = Module.new
|
99
|
+
mod.extend(Interface)
|
100
|
+
mod.instance_eval(&block)
|
101
|
+
mod
|
102
|
+
end
|
97
103
|
end
|
98
104
|
|
99
105
|
class Module
|
100
|
-
|
106
|
+
alias :implements :include
|
101
107
|
end
|
data/test/test_interface.rb
CHANGED
@@ -3,64 +3,61 @@
|
|
3
3
|
#
|
4
4
|
# Test suite for the Interface module.
|
5
5
|
#####################################################
|
6
|
-
require '
|
7
|
-
gem 'test-unit'
|
8
|
-
|
9
|
-
require 'test/unit'
|
6
|
+
require 'test-unit'
|
10
7
|
require 'interface'
|
11
8
|
|
12
9
|
class TC_Interface < Test::Unit::TestCase
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
10
|
+
def self.startup
|
11
|
+
alpha_interface = interface{
|
12
|
+
required_methods :alpha, :beta
|
13
|
+
}
|
14
|
+
|
15
|
+
gamma_interface = interface{
|
16
|
+
extends alpha_interface
|
17
|
+
required_methods :gamma
|
18
|
+
unrequired_methods :alpha
|
19
|
+
}
|
20
|
+
|
21
|
+
# Workaround for 1.9.x
|
22
|
+
@@alpha_interface = alpha_interface
|
23
|
+
@@gamma_interface = gamma_interface
|
24
|
+
|
25
|
+
eval("class A; end")
|
26
|
+
|
27
|
+
eval("
|
28
|
+
class B
|
29
|
+
def alpha; end
|
30
|
+
def beta; end
|
31
|
+
end
|
32
|
+
")
|
33
|
+
|
34
|
+
eval("
|
35
|
+
class C
|
36
|
+
def beta; end
|
37
|
+
def gamma; end
|
38
|
+
end
|
39
|
+
")
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_version
|
43
|
+
assert_equal('1.0.3', Interface::VERSION)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_interface_requirements_not_met
|
47
|
+
assert_raise(Interface::MethodMissing){ A.extend(@@alpha_interface) }
|
48
|
+
assert_raise(Interface::MethodMissing){ A.new.extend(@@alpha_interface) }
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_sub_interface_requirements_not_met
|
52
|
+
assert_raise(Interface::MethodMissing){ B.extend(@@gamma_interface) }
|
53
|
+
assert_raise(Interface::MethodMissing){ B.new.extend(@@gamma_interface) }
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_alpha_interface_requirements_met
|
57
|
+
assert_nothing_raised{ B.new.extend(@@alpha_interface) }
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_gamma_interface_requirements_met
|
61
|
+
assert_nothing_raised{ C.new.extend(@@gamma_interface) }
|
62
|
+
end
|
66
63
|
end
|
metadata
CHANGED
@@ -1,76 +1,89 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: interface
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
|
-
authors:
|
6
|
+
authors:
|
7
7
|
- Daniel J. Berger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
dependencies:
|
15
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2014-10-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
16
14
|
name: test-unit
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
17
20
|
type: :development
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
20
|
-
requirements:
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
21
31
|
- - ">="
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version:
|
24
|
-
|
25
|
-
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: |2
|
42
|
+
The interface library implements Java style interfaces for Ruby.
|
43
|
+
It lets you define a set a methods that must be defined in the
|
44
|
+
including class or module, or an error is raised.
|
26
45
|
email: djberg96@gmail.com
|
27
46
|
executables: []
|
28
|
-
|
29
47
|
extensions: []
|
30
|
-
|
31
|
-
extra_rdoc_files:
|
48
|
+
extra_rdoc_files:
|
32
49
|
- README
|
33
50
|
- CHANGES
|
34
51
|
- MANIFEST
|
35
|
-
files:
|
52
|
+
files:
|
36
53
|
- CHANGES
|
54
|
+
- MANIFEST
|
55
|
+
- README
|
56
|
+
- Rakefile
|
37
57
|
- examples/example_instance.rb
|
38
58
|
- examples/example_interface.rb
|
39
59
|
- examples/example_sub.rb
|
40
60
|
- examples/example_unrequire.rb
|
41
61
|
- interface.gemspec
|
42
62
|
- lib/interface.rb
|
43
|
-
- MANIFEST
|
44
|
-
- Rakefile
|
45
|
-
- README
|
46
63
|
- test/test_interface.rb
|
47
|
-
|
48
|
-
|
49
|
-
licenses:
|
64
|
+
homepage: https://github.com/djberg96/interface
|
65
|
+
licenses:
|
50
66
|
- Artistic 2.0
|
67
|
+
metadata: {}
|
51
68
|
post_install_message:
|
52
69
|
rdoc_options: []
|
53
|
-
|
54
|
-
require_paths:
|
70
|
+
require_paths:
|
55
71
|
- lib
|
56
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
-
requirements:
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
58
74
|
- - ">="
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version:
|
61
|
-
|
62
|
-
|
63
|
-
requirements:
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
64
79
|
- - ">="
|
65
|
-
- !ruby/object:Gem::Version
|
66
|
-
version:
|
67
|
-
version:
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
68
82
|
requirements: []
|
69
|
-
|
70
|
-
|
71
|
-
rubygems_version: 1.3.5
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 2.4.1
|
72
85
|
signing_key:
|
73
|
-
specification_version:
|
86
|
+
specification_version: 4
|
74
87
|
summary: Java style interfaces for Ruby
|
75
|
-
test_files:
|
88
|
+
test_files:
|
76
89
|
- test/test_interface.rb
|