interface 1.0.5 → 1.2.0
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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/{CHANGES → CHANGES.md} +45 -30
- data/Gemfile +2 -0
- data/LICENSE +72 -0
- data/{MANIFEST → MANIFEST.md} +13 -12
- data/README.md +91 -0
- data/Rakefile +11 -8
- data/examples/enhanced_features_demo.rb +110 -0
- data/examples/example_interface.rb +2 -2
- data/interface.gemspec +35 -34
- data/lib/interface.rb +268 -40
- data/spec/interface_enhanced_spec.rb +175 -0
- data/spec/interface_spec.rb +56 -0
- data.tar.gz.sig +0 -0
- metadata +28 -28
- metadata.gz.sig +0 -0
- data/README +0 -74
- data/test/test_interface.rb +0 -64
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f12f52d0bb291fe96e86776130cfc7aedb5741520160057f675c0f04bb73e4f
|
4
|
+
data.tar.gz: 279405e1b859fdd0e71cf8d5cd1b253ec056eb2a80f82203b132dc4bc3d0934d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6ca7f3b16edbe729c20ac3c62d602fa15afab6a7723ed955244c8cab8ec5272025f2663096981ff9e832199f8c477af56683ab4f3a2dcd288b329ae3a704051
|
7
|
+
data.tar.gz: ead9f3702e3983f4509b01ec92cc3f7326b8a80601ab03663dfa5a3ae98a5a9b81c1c790b249de2ae150734efb28913930b56fb1ff17b4f977260ba632694b33
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/{CHANGES → CHANGES.md}
RENAMED
@@ -1,30 +1,45 @@
|
|
1
|
-
|
2
|
-
*
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
*
|
11
|
-
* Updated
|
12
|
-
|
13
|
-
|
14
|
-
*
|
15
|
-
|
16
|
-
|
17
|
-
*
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
*
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
*
|
1
|
+
## 1.2.0 - 8-Jul-2025
|
2
|
+
* Updated to use deferred method declaration validation. This means you
|
3
|
+
no longer have to define methods before including the interface.
|
4
|
+
* Additional specs and example added.
|
5
|
+
|
6
|
+
## 1.1.0 - 4-May-2022
|
7
|
+
* Switch from test-unit to rspec.
|
8
|
+
|
9
|
+
## 1.0.5 - 26-Oct-2019
|
10
|
+
* Now assumes Ruby 2.
|
11
|
+
* Updated cert.
|
12
|
+
* Fixed missing hyphen in license name.
|
13
|
+
* Added metadata to the gemspec.
|
14
|
+
* The VERSION constant is now frozen.
|
15
|
+
|
16
|
+
## 1.0.4 - 8-Jan-2016
|
17
|
+
* This gem is now signed.
|
18
|
+
* The gem related tasks in the Rakefile now assume Rubygems 2.x.
|
19
|
+
|
20
|
+
## 1.0.3 - 12-Oct-2014
|
21
|
+
* Rakefile, gemspec and README updates.
|
22
|
+
|
23
|
+
## 1.0.2 - 7-Oct-2009
|
24
|
+
* Fixed packaging bug in the gemspec, and made some other minor changes.
|
25
|
+
* Added the 'gem' rake task.
|
26
|
+
* Updated copyright and license in the README.
|
27
|
+
|
28
|
+
## 1.0.1 - 29-Jul-2009
|
29
|
+
* Now compatible with Ruby 1.9.x.
|
30
|
+
* Replaced the install.rb with a Rakefile and various tasks.
|
31
|
+
* Updated the license to Artistic 2.0.
|
32
|
+
* Added test-unit 2.x as a development dependency and refactored the test
|
33
|
+
suite to take advantage of some of its features.
|
34
|
+
* Renamed the test file to test_interface.rb.
|
35
|
+
* Renamed the example programs to all start with 'example_' to avoid any
|
36
|
+
possible confusion with actual test suites.
|
37
|
+
* Added rake tasks for running the example programs.
|
38
|
+
* Updated and refactored the gemspec.
|
39
|
+
|
40
|
+
## 1.0.0 - 5-Jun-2005
|
41
|
+
* Re-released on RubyForge.
|
42
|
+
* Some test suite and doc changes.
|
43
|
+
|
44
|
+
## 0.1.0 - 9-May-2004
|
45
|
+
* Initial release
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
Copyright (c) 2000-2006, The Perl Foundation.
|
2
|
+
|
3
|
+
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
|
4
|
+
|
5
|
+
Preamble
|
6
|
+
This license establishes the terms under which a given free software Package may be copied, modified, distributed, and/or redistributed. The intent is that the Copyright Holder maintains some artistic control over the development of that Package while still keeping the Package available as open source and free software.
|
7
|
+
|
8
|
+
You are always permitted to make arrangements wholly outside of this license directly with the Copyright Holder of a given Package. If the terms of this license do not permit the full use that you propose to make of the Package, you should contact the Copyright Holder and seek a different licensing arrangement.
|
9
|
+
|
10
|
+
Definitions
|
11
|
+
“Copyright Holder” means the individual(s) or organization(s) named in the copyright notice for the entire Package.
|
12
|
+
|
13
|
+
“Contributor” means any party that has contributed code or other material to the Package, in accordance with the Copyright Holder’s procedures.
|
14
|
+
|
15
|
+
“You” and “your” means any person who would like to copy, distribute, or modify the Package.
|
16
|
+
|
17
|
+
“Package” means the collection of files distributed by the Copyright Holder, and derivatives of that collection and/or of those files. A given Package may consist of either the Standard Version, or a Modified Version.
|
18
|
+
|
19
|
+
“Distribute” means providing a copy of the Package or making it accessible to anyone else, or in the case of a company or organization, to others outside of your company or organization.
|
20
|
+
|
21
|
+
“Distributor Fee” means any fee that you charge for Distributing this Package or providing support for this Package to another party. It does not mean licensing fees.
|
22
|
+
|
23
|
+
“Standard Version” refers to the Package if it has not been modified, or has been modified only in ways explicitly requested by the Copyright Holder.
|
24
|
+
|
25
|
+
“Modified Version” means the Package, if it has been changed, and such changes were not explicitly requested by the Copyright Holder.
|
26
|
+
|
27
|
+
“Original License” means this Artistic License as Distributed with the Standard Version of the Package, in its current version or as it may be modified by The Perl Foundation in the future.
|
28
|
+
|
29
|
+
“Source” form means the source code, documentation source, and configuration files for the Package.
|
30
|
+
|
31
|
+
“Compiled” form means the compiled bytecode, object code, binary, or any other form resulting from mechanical transformation or translation of the Source form.
|
32
|
+
|
33
|
+
Permission for Use and Modification Without Distribution
|
34
|
+
(1) You are permitted to use the Standard Version and create and use Modified Versions for any purpose without restriction, provided that you do not Distribute the Modified Version.
|
35
|
+
|
36
|
+
Permissions for Redistribution of the Standard Version
|
37
|
+
(2) You may Distribute verbatim copies of the Source form of the Standard Version of this Package in any medium without restriction, either gratis or for a Distributor Fee, provided that you duplicate all of the original copyright notices and associated disclaimers. At your discretion, such verbatim copies may or may not include a Compiled form of the Package.
|
38
|
+
|
39
|
+
(3) You may apply any bug fixes, portability changes, and other modifications made available from the Copyright Holder. The resulting Package will still be considered the Standard Version, and as such will be subject to the Original License.
|
40
|
+
|
41
|
+
Distribution of Modified Versions of the Package as Source
|
42
|
+
(4) You may Distribute your Modified Version as Source (either gratis or for a Distributor Fee, and with or without a Compiled form of the Modified Version) provided that you clearly document how it differs from the Standard Version, including, but not limited to, documenting any non-standard features, executables, or modules, and provided that you do at least ONE of the following:
|
43
|
+
|
44
|
+
(a) make the Modified Version available to the Copyright Holder of the Standard Version, under the Original License, so that the Copyright Holder may include your modifications in the Standard Version.
|
45
|
+
(b) ensure that installation of your Modified Version does not prevent the user installing or running the Standard Version. In addition, the Modified Version must bear a name that is different from the name of the Standard Version.
|
46
|
+
(c) allow anyone who receives a copy of the Modified Version to make the Source form of the Modified Version available to others under
|
47
|
+
(i) the Original License or
|
48
|
+
(ii) a license that permits the licensee to freely copy, modify and redistribute the Modified Version using the same licensing terms that apply to the copy that the licensee received, and requires that the Source form of the Modified Version, and of any works derived from it, be made freely available in that license fees are prohibited but Distributor Fees are allowed.
|
49
|
+
|
50
|
+
Distribution of Compiled Forms of the Standard Version or Modified Versions without the Source
|
51
|
+
(5) You may Distribute Compiled forms of the Standard Version without the Source, provided that you include complete instructions on how to get the Source of the Standard Version. Such instructions must be valid at the time of your distribution. If these instructions, at any time while you are carrying out such distribution, become invalid, you must provide new instructions on demand or cease further distribution. If you provide valid instructions or cease distribution within thirty days after you become aware that the instructions are invalid, then you do not forfeit any of your rights under this license.
|
52
|
+
|
53
|
+
(6) You may Distribute a Modified Version in Compiled form without the Source, provided that you comply with Section 4 with respect to the Source of the Modified Version.
|
54
|
+
|
55
|
+
Aggregating or Linking the Package
|
56
|
+
(7) You may aggregate the Package (either the Standard Version or Modified Version) with other packages and Distribute the resulting aggregation provided that you do not charge a licensing fee for the Package. Distributor Fees are permitted, and licensing fees for other components in the aggregation are permitted. The terms of this license apply to the use and Distribution of the Standard or Modified Versions as included in the aggregation.
|
57
|
+
|
58
|
+
(8) You are permitted to link Modified and Standard Versions with other works, to embed the Package in a larger work of your own, or to build stand-alone binary or bytecode versions of applications that include the Package, and Distribute the result without restriction, provided the result does not expose a direct interface to the Package.
|
59
|
+
|
60
|
+
Items That are Not Considered Part of a Modified Version
|
61
|
+
(9) Works (including, but not limited to, modules and scripts) that merely extend or make use of the Package, do not, by themselves, cause the Package to be a Modified Version. In addition, such works are not considered parts of the Package itself, and are not subject to the terms of this license.
|
62
|
+
|
63
|
+
General Provisions
|
64
|
+
(10) Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License. By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license.
|
65
|
+
|
66
|
+
(11) If your Modified Version has been derived from a Modified Version made by someone other than you, you are nevertheless required to ensure that your Modified Version complies with the requirements of this license.
|
67
|
+
|
68
|
+
(12) This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder.
|
69
|
+
|
70
|
+
(13) This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement, then this Artistic License to you shall terminate on the date that such litigation is filed.
|
71
|
+
|
72
|
+
(14) Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS “AS IS’ AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/{MANIFEST → MANIFEST.md}
RENAMED
@@ -1,12 +1,13 @@
|
|
1
|
-
* CHANGES
|
2
|
-
*
|
3
|
-
*
|
4
|
-
*
|
5
|
-
*
|
6
|
-
*
|
7
|
-
*
|
8
|
-
* examples/
|
9
|
-
* examples/
|
10
|
-
* examples/
|
11
|
-
*
|
12
|
-
*
|
1
|
+
* CHANGES.md
|
2
|
+
* LICENSE
|
3
|
+
* MANIFEST.md
|
4
|
+
* README.md
|
5
|
+
* Rakefile
|
6
|
+
* interface.gemspec
|
7
|
+
* certs/djberg96_pub.pem
|
8
|
+
* examples/example_instance.rb
|
9
|
+
* examples/example_interface.rb
|
10
|
+
* examples/example_sub.rb
|
11
|
+
* examples/example_unrequire.rb
|
12
|
+
* lib/interface.rb
|
13
|
+
* spec/interface_spec.rb
|
data/README.md
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
[](https://github.com/djberg96/interface/actions/workflows/ruby.yml)
|
2
|
+
|
3
|
+
## Description
|
4
|
+
This library provides Java style interfaces for Ruby.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
`gem install interface`
|
8
|
+
|
9
|
+
## Adding the trusted cert
|
10
|
+
`gem cert --add <(curl -Ls https://raw.githubusercontent.com/djberg96/interface/main/certs/djberg96_pub.pem)`
|
11
|
+
|
12
|
+
## Synopsis
|
13
|
+
```ruby
|
14
|
+
require 'interface'
|
15
|
+
|
16
|
+
MyInterface = interface do
|
17
|
+
required_methods :foo, :bar, :baz
|
18
|
+
end
|
19
|
+
|
20
|
+
# Raises an error until 'baz' is defined
|
21
|
+
class MyClass
|
22
|
+
implements MyInterface
|
23
|
+
|
24
|
+
def foo
|
25
|
+
puts "foo"
|
26
|
+
end
|
27
|
+
|
28
|
+
def bar
|
29
|
+
puts "bar"
|
30
|
+
end
|
31
|
+
|
32
|
+
# Uncomment to work
|
33
|
+
# def baz; end
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
## General Notes
|
38
|
+
Subinterfaces work as well. See the test_sub.rb file under the 'test'
|
39
|
+
directory for a sample.
|
40
|
+
|
41
|
+
## Developer's Notes
|
42
|
+
A discussion on IRC with Mauricio Fernandez got us talking about traits.
|
43
|
+
During that discussion I remembered a blog entry by David Naseby. I
|
44
|
+
revisited his blog entry and took a closer look:
|
45
|
+
|
46
|
+
http://ruby-naseby.blogspot.com/2008/11/traits-in-ruby.html
|
47
|
+
|
48
|
+
Keep in mind that I also happened to be thinking about Java at the moment
|
49
|
+
because of a recent job switch that involved coding in Java. I was also
|
50
|
+
trying to figure out what the purpose of interfaces were.
|
51
|
+
|
52
|
+
As I read the first page of David Naseby's article I realized that,
|
53
|
+
whether intended or not, he had implemented a rudimentary form of interfaces
|
54
|
+
for Ruby. When I discovered this, I talked about it some more with Mauricio
|
55
|
+
and he and I (mostly him) fleshed out the rest of the module, including some
|
56
|
+
syntax improvements. The result is syntax and functionality that is nearly
|
57
|
+
identical to Java.
|
58
|
+
|
59
|
+
I should note that, although I am listed as the author, this was mostly the
|
60
|
+
combined work of David Naseby and Mauricio Fernandez. I just happened to be
|
61
|
+
the guy that put it all together.
|
62
|
+
|
63
|
+
In more recent versions this code was enhanced with the help of AI.
|
64
|
+
Specifically, it was updated to use the TracePoint interface so that an
|
65
|
+
interface could be declared at the top of the class, with the method
|
66
|
+
validations deferred.
|
67
|
+
|
68
|
+
## Acknowledgements
|
69
|
+
This module was largely inspired and somewhat copied from a post by
|
70
|
+
David Naseby (see URL above). It was subsequently modified almost entirely
|
71
|
+
by Mauricio Fernandez through a series of discussions on IRC, and later
|
72
|
+
by evil AI bots that will eventually kill us all.
|
73
|
+
|
74
|
+
## See Also
|
75
|
+
The Crystal programming language, which has syntax very similar to Ruby's,
|
76
|
+
effectively implements interfaces via the `abstract` keyword.
|
77
|
+
|
78
|
+
## Copyright
|
79
|
+
(C) 2004-2025 Daniel J. Berger
|
80
|
+
All rights reserved.
|
81
|
+
|
82
|
+
## Warranty
|
83
|
+
This package is provided "as is" and without any express or
|
84
|
+
implied warranties, including, without limitation, the implied
|
85
|
+
warranties of merchantability and fitness for a particular purpose.
|
86
|
+
|
87
|
+
## License
|
88
|
+
Artistic-2.0
|
89
|
+
|
90
|
+
## Author
|
91
|
+
Daniel J. Berger
|
data/Rakefile
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
require 'rake'
|
2
2
|
require 'rake/clean'
|
3
|
-
require '
|
3
|
+
require 'rspec/core/rake_task'
|
4
4
|
|
5
|
-
CLEAN.include("**/*.gem", "**/*.rbc")
|
5
|
+
CLEAN.include("**/*.gem", "**/*.rbc", "**/*.lock")
|
6
6
|
|
7
7
|
namespace :gem do
|
8
8
|
desc "Create the interface gem"
|
9
9
|
task :create => [:clean] do
|
10
10
|
require 'rubygems/package'
|
11
|
-
spec =
|
11
|
+
spec = Gem::Specification.load('interface.gemspec')
|
12
12
|
spec.signing_key = File.join(Dir.home, '.ssh', 'gem-private_key.pem')
|
13
|
-
Gem::Package.build(spec
|
13
|
+
Gem::Package.build(spec)
|
14
14
|
end
|
15
15
|
|
16
16
|
desc "Install the interface gem"
|
@@ -42,9 +42,12 @@ namespace :example do
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
45
|
+
desc "Run the test suite"
|
46
|
+
RSpec::Core::RakeTask.new(:spec)
|
47
|
+
|
48
|
+
# Clean up afterwards
|
49
|
+
Rake::Task[:spec].enhance do
|
50
|
+
Rake::Task[:clean].invoke
|
48
51
|
end
|
49
52
|
|
50
|
-
task :default => :
|
53
|
+
task :default => :spec
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../lib/interface'
|
4
|
+
|
5
|
+
puts "=== Interface Library Improvements Demo ==="
|
6
|
+
puts
|
7
|
+
|
8
|
+
# 1. Enhanced Error Messages
|
9
|
+
puts "1. Enhanced Error Messages:"
|
10
|
+
puts "-" * 40
|
11
|
+
|
12
|
+
PaymentInterface = interface do
|
13
|
+
required_methods :process_payment, :validate_payment, :send_receipt
|
14
|
+
end
|
15
|
+
|
16
|
+
class IncompletePaymentProcessor
|
17
|
+
def process_payment
|
18
|
+
puts "Processing payment..."
|
19
|
+
end
|
20
|
+
# Missing validate_payment and send_receipt methods
|
21
|
+
end
|
22
|
+
|
23
|
+
begin
|
24
|
+
IncompletePaymentProcessor.include PaymentInterface
|
25
|
+
rescue Interface::MethodMissing => e
|
26
|
+
puts "Error caught with enhanced details:"
|
27
|
+
puts " Missing methods: #{e.missing_methods.join(', ')}"
|
28
|
+
puts " Target class: #{e.target_name}"
|
29
|
+
puts " Interface: #{e.interface_name}"
|
30
|
+
puts " Full message: #{e.message}"
|
31
|
+
end
|
32
|
+
|
33
|
+
puts
|
34
|
+
|
35
|
+
# 2. Interface Introspection
|
36
|
+
puts "2. Interface Introspection:"
|
37
|
+
puts "-" * 40
|
38
|
+
|
39
|
+
StorageInterface = interface do
|
40
|
+
required_methods :save, :load, :delete
|
41
|
+
end
|
42
|
+
|
43
|
+
puts "Required methods: #{StorageInterface.get_required_methods}"
|
44
|
+
|
45
|
+
# 3. Sub-interface with unrequired methods
|
46
|
+
puts "3. Sub-interface with selective requirements:"
|
47
|
+
puts "-" * 40
|
48
|
+
|
49
|
+
ReadOnlyStorageInterface = interface do
|
50
|
+
extend StorageInterface
|
51
|
+
unrequired_methods :save, :delete
|
52
|
+
end
|
53
|
+
|
54
|
+
puts "Original interface requires: #{StorageInterface.get_required_methods}"
|
55
|
+
puts "Read-only interface requires: #{ReadOnlyStorageInterface.get_required_methods}"
|
56
|
+
puts "Read-only interface unrequires: #{ReadOnlyStorageInterface.get_unrequired_methods}"
|
57
|
+
|
58
|
+
# 4. Interface Satisfaction Checking
|
59
|
+
puts "4. Interface Satisfaction Checking:"
|
60
|
+
puts "-" * 40
|
61
|
+
|
62
|
+
class FileStorage
|
63
|
+
def save; puts "Saving to file"; end
|
64
|
+
def load; puts "Loading from file"; end
|
65
|
+
def delete; puts "Deleting file"; end
|
66
|
+
end
|
67
|
+
|
68
|
+
class ReadOnlyFileStorage
|
69
|
+
def load; puts "Loading from file"; end
|
70
|
+
end
|
71
|
+
|
72
|
+
puts "FileStorage satisfies StorageInterface: #{StorageInterface.satisfied_by?(FileStorage)}"
|
73
|
+
puts "ReadOnlyFileStorage satisfies StorageInterface: #{StorageInterface.satisfied_by?(ReadOnlyFileStorage)}"
|
74
|
+
puts "ReadOnlyFileStorage satisfies ReadOnlyStorageInterface: #{ReadOnlyStorageInterface.satisfied_by?(ReadOnlyFileStorage)}"
|
75
|
+
|
76
|
+
# 5. Complex inheritance hierarchy
|
77
|
+
puts "5. Complex Interface Inheritance:"
|
78
|
+
puts "-" * 40
|
79
|
+
|
80
|
+
BaseInterface = interface do
|
81
|
+
required_methods :initialize_connection, :close_connection
|
82
|
+
end
|
83
|
+
|
84
|
+
AuthenticatedInterface = interface do
|
85
|
+
extend BaseInterface
|
86
|
+
required_methods :authenticate, :authorize
|
87
|
+
end
|
88
|
+
|
89
|
+
DatabaseInterface = interface do
|
90
|
+
extend AuthenticatedInterface
|
91
|
+
required_methods :query, :transaction
|
92
|
+
unrequired_methods :authorize # Don't require authorization for this specific interface
|
93
|
+
end
|
94
|
+
|
95
|
+
puts "BaseInterface requires: #{BaseInterface.get_required_methods}"
|
96
|
+
puts "AuthenticatedInterface requires: #{AuthenticatedInterface.get_required_methods}"
|
97
|
+
puts "DatabaseInterface requires: #{DatabaseInterface.get_required_methods}"
|
98
|
+
|
99
|
+
# 6. String to symbol conversion
|
100
|
+
puts "6. Automatic String to Symbol Conversion:"
|
101
|
+
puts "-" * 40
|
102
|
+
|
103
|
+
StringInterface = interface do
|
104
|
+
required_methods 'string_method', 'another_string_method'
|
105
|
+
end
|
106
|
+
|
107
|
+
puts "Methods defined with strings: #{StringInterface.get_required_methods}"
|
108
|
+
|
109
|
+
puts
|
110
|
+
puts "=== Demo Complete ==="
|
@@ -5,16 +5,16 @@
|
|
5
5
|
# run this example via the 'rake example:interface' task. Modify this
|
6
6
|
# code as you see fit.
|
7
7
|
#######################################################################
|
8
|
-
|
8
|
+
require_relative '../lib/interface'
|
9
9
|
|
10
10
|
MyInterface = interface{
|
11
11
|
required_methods :foo, :bar
|
12
12
|
}
|
13
13
|
|
14
14
|
class MyClass
|
15
|
+
include MyInterface
|
15
16
|
def foo; end
|
16
17
|
def bar; end
|
17
|
-
include MyInterface
|
18
18
|
end
|
19
19
|
|
20
20
|
=begin
|
data/interface.gemspec
CHANGED
@@ -1,34 +1,35 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
|
3
|
-
Gem::Specification.new do |spec|
|
4
|
-
spec.name = 'interface'
|
5
|
-
spec.version = '1.0
|
6
|
-
spec.author = 'Daniel J. Berger'
|
7
|
-
spec.license = 'Artistic-2.0'
|
8
|
-
spec.email = 'djberg96@gmail.com'
|
9
|
-
spec.homepage = 'http://github.com/djberg96/interface'
|
10
|
-
spec.summary = 'Java style interfaces for Ruby'
|
11
|
-
spec.test_file = '
|
12
|
-
spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
|
13
|
-
spec.cert_chain = Dir['certs/*']
|
14
|
-
|
15
|
-
spec.
|
16
|
-
|
17
|
-
|
18
|
-
spec.
|
19
|
-
|
20
|
-
|
21
|
-
'
|
22
|
-
'
|
23
|
-
'
|
24
|
-
'
|
25
|
-
'
|
26
|
-
'
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'interface'
|
5
|
+
spec.version = '1.2.0'
|
6
|
+
spec.author = 'Daniel J. Berger'
|
7
|
+
spec.license = 'Artistic-2.0'
|
8
|
+
spec.email = 'djberg96@gmail.com'
|
9
|
+
spec.homepage = 'http://github.com/djberg96/interface'
|
10
|
+
spec.summary = 'Java style interfaces for Ruby'
|
11
|
+
spec.test_file = 'spec/interface_spec.rb'
|
12
|
+
spec.files = Dir['**/*'].reject{ |f| f.include?('git') || f.include?('misc') }
|
13
|
+
spec.cert_chain = Dir['certs/*']
|
14
|
+
|
15
|
+
spec.add_development_dependency('rake')
|
16
|
+
spec.add_development_dependency('rspec', '~> 3.9')
|
17
|
+
|
18
|
+
spec.metadata = {
|
19
|
+
'homepage_uri' => 'https://github.com/djberg96/interface',
|
20
|
+
'bug_tracker_uri' => 'https://github.com/djberg96/interface/issues',
|
21
|
+
'changelog_uri' => 'https://github.com/djberg96/interface/blob/main/CHANGES.md',
|
22
|
+
'documentation_uri' => 'https://github.com/djberg96/interface/wiki',
|
23
|
+
'source_code_uri' => 'https://github.com/djberg96/interface',
|
24
|
+
'wiki_uri' => 'https://github.com/djberg96/interface/wiki',
|
25
|
+
'rubygems_mfa_required' => 'true',
|
26
|
+
'github_repo' => 'https://github.com/djberg96/interface',
|
27
|
+
'funding_uri' => 'https://github.com/sponsors/djberg96',
|
28
|
+
}
|
29
|
+
|
30
|
+
spec.description = <<-EOF
|
31
|
+
The interface library implements Java style interfaces for Ruby.
|
32
|
+
It lets you define a set a methods that must be defined in the
|
33
|
+
including class or module, or an error is raised.
|
34
|
+
EOF
|
35
|
+
end
|