rubycube 0.3.1 → 0.4.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
- data/cube.gemspec +3 -1
- data/examples/demo.rb +13 -8
- data/examples/traits.rb +26 -10
- data/lib/cube/interfaces.rb +11 -45
- data/lib/cube/toplevel.rb +28 -39
- data/lib/cube/traits.rb +0 -32
- data/rubycube-0.3.0.gem +0 -0
- data/test/test_interface.rb +9 -5
- metadata +34 -68
- data/doc/Bar.html +0 -102
- data/doc/CHANGES.html +0 -159
- data/doc/Foo.html +0 -184
- data/doc/Interface.html +0 -278
- data/doc/Interface/MethodMissing.html +0 -104
- data/doc/Interface/PrivateVisibleMethodMissing.html +0 -102
- data/doc/Interface/PublicVisibleMethodMissing.html +0 -102
- data/doc/MANIFEST.html +0 -114
- data/doc/Module.html +0 -153
- data/doc/MyClass.html +0 -234
- data/doc/MyInterface.html +0 -106
- data/doc/MySubInterface.html +0 -110
- data/doc/Object.html +0 -299
- data/doc/README.html +0 -222
- data/doc/Rakefile.html +0 -148
- data/doc/TC_Interface.html +0 -438
- data/doc/certs/djberg96_pub_pem.html +0 -110
- data/doc/created.rid +0 -13
- data/doc/css/fonts.css +0 -167
- data/doc/css/rdoc.css +0 -590
- data/doc/fonts/Lato-Light.ttf +0 -0
- data/doc/fonts/Lato-LightItalic.ttf +0 -0
- data/doc/fonts/Lato-Regular.ttf +0 -0
- data/doc/fonts/Lato-RegularItalic.ttf +0 -0
- data/doc/fonts/SourceCodePro-Bold.ttf +0 -0
- data/doc/fonts/SourceCodePro-Regular.ttf +0 -0
- data/doc/images/add.png +0 -0
- data/doc/images/arrow_up.png +0 -0
- data/doc/images/brick.png +0 -0
- data/doc/images/brick_link.png +0 -0
- data/doc/images/bug.png +0 -0
- data/doc/images/bullet_black.png +0 -0
- data/doc/images/bullet_toggle_minus.png +0 -0
- data/doc/images/bullet_toggle_plus.png +0 -0
- data/doc/images/date.png +0 -0
- data/doc/images/delete.png +0 -0
- data/doc/images/find.png +0 -0
- data/doc/images/loadingAnimation.gif +0 -0
- data/doc/images/macFFBgHack.png +0 -0
- data/doc/images/package.png +0 -0
- data/doc/images/page_green.png +0 -0
- data/doc/images/page_white_text.png +0 -0
- data/doc/images/page_white_width.png +0 -0
- data/doc/images/plugin.png +0 -0
- data/doc/images/ruby.png +0 -0
- data/doc/images/tag_blue.png +0 -0
- data/doc/images/tag_green.png +0 -0
- data/doc/images/transparent.png +0 -0
- data/doc/images/wrench.png +0 -0
- data/doc/images/wrench_orange.png +0 -0
- data/doc/images/zoom.png +0 -0
- data/doc/index.html +0 -121
- data/doc/interface_gemspec.html +0 -121
- data/doc/js/darkfish.js +0 -161
- data/doc/js/jquery.js +0 -4
- data/doc/js/navigation.js +0 -142
- data/doc/js/navigation.js.gz +0 -0
- data/doc/js/search.js +0 -109
- data/doc/js/search_index.js +0 -1
- data/doc/js/search_index.js.gz +0 -0
- data/doc/js/searcher.js +0 -228
- data/doc/js/searcher.js.gz +0 -0
- data/doc/table_of_contents.html +0 -227
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2bcabba8c4d9c0e4e97fbe87c677b5a4f6cb12de
|
|
4
|
+
data.tar.gz: b41bb0dde4bf03c019bbe008242b9a56ed51043a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c24794642ae6e1ee65a52184b3e60efdfb243571307afaa2dc442c4d413171a13e0bce27bd16e130846b1718d794f668a6c184db0896aaadabbaa1bbe6f9adbb
|
|
7
|
+
data.tar.gz: '0283893f2805db378c55358ceaa15e370ab13519f7d40aa3e788b33ae430b42e4285e5acf0dfb4665054fc7e1940d1776580de3a5ac6e6b8f8c0372e7ef8d62e'
|
data/cube.gemspec
CHANGED
|
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
|
2
2
|
|
|
3
3
|
Gem::Specification.new do |spec|
|
|
4
4
|
spec.name = 'rubycube'
|
|
5
|
-
spec.version = '0.
|
|
5
|
+
spec.version = '0.4.0'
|
|
6
6
|
spec.author = 'Aditya Godbole'
|
|
7
7
|
spec.license = 'Artistic 2.0'
|
|
8
8
|
spec.email = 'code.aa@gdbl.me'
|
|
@@ -15,6 +15,8 @@ Gem::Specification.new do |spec|
|
|
|
15
15
|
|
|
16
16
|
spec.extra_rdoc_files = ['README.md', 'CHANGES', 'MANIFEST', 'examples/demo.rb']
|
|
17
17
|
|
|
18
|
+
spec.add_dependency('dry-types')
|
|
19
|
+
spec.add_development_dependency('dry-types')
|
|
18
20
|
spec.add_development_dependency('test-unit')
|
|
19
21
|
spec.add_development_dependency('rake')
|
|
20
22
|
|
data/examples/demo.rb
CHANGED
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
# run as `RUBY_CUBE_TYPECHECK= 1 ruby examples/demo.rb`
|
|
2
2
|
#require_relative '../lib/cube'
|
|
3
3
|
require 'cube'
|
|
4
|
+
require 'dry-types'
|
|
5
|
+
|
|
6
|
+
module Types
|
|
7
|
+
include Dry::Types.module
|
|
8
|
+
end
|
|
4
9
|
|
|
5
10
|
Adder = Cube.interface {
|
|
6
|
-
# sum is a method that takes an array of
|
|
7
|
-
proto(:sum, [
|
|
11
|
+
# sum is a method that takes an array of Types::Strict::Int and returns an Types::Strict::Int
|
|
12
|
+
proto(:sum, [Types::Strict::Int]) { Types::Strict::Int }
|
|
8
13
|
}
|
|
9
14
|
|
|
10
15
|
Calculator = Cube.interface {
|
|
11
16
|
# interfaces can be composed
|
|
12
17
|
extends Adder
|
|
13
|
-
# method fact takes an
|
|
14
|
-
proto(:fact,
|
|
15
|
-
# method pos takes an array of
|
|
16
|
-
proto(:pos, [
|
|
18
|
+
# method fact takes an Types::Strict::Int and returns an Types::Strict::Int
|
|
19
|
+
proto(:fact, Types::Strict::Int) { Types::Strict::Int }
|
|
20
|
+
# method pos takes an array of Types::Strict::Ints, an Types::Strict::Int, and returns either Types::Strict::Int or nil
|
|
21
|
+
proto(:pos, [Types::Strict::Array], Types::Strict::Int) { Types::Strict::Int|Types::Strict::Nil }
|
|
17
22
|
}
|
|
18
23
|
|
|
19
24
|
class SimpleCalcImpl
|
|
@@ -39,8 +44,8 @@ p c.pos([1, 2, 3], 4)
|
|
|
39
44
|
|
|
40
45
|
AdvancedCalculator = Cube.interface {
|
|
41
46
|
extend Calculator
|
|
42
|
-
proto(:product,
|
|
43
|
-
proto(:avg, [
|
|
47
|
+
proto(:product, Types::Strict::Int, Types::Strict::Int) { Types::Strict::Int }
|
|
48
|
+
proto(:avg, [Types::Strict::Int]) { Types::Strict::Float }
|
|
44
49
|
}
|
|
45
50
|
|
|
46
51
|
ProductCalcT = Cube.trait do
|
data/examples/traits.rb
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
ENV['RUBY_CUBE_TYPECHECK'] = "1"
|
|
2
2
|
#require_relative '../lib/cube'
|
|
3
3
|
require 'cube'
|
|
4
|
+
require 'dry-initializer'
|
|
5
|
+
|
|
6
|
+
module Types
|
|
7
|
+
include Dry::Types.module
|
|
8
|
+
end
|
|
9
|
+
|
|
4
10
|
EmailNotifierT = Cube.trait do
|
|
5
11
|
def notify
|
|
6
12
|
puts "email sent to #{email}"
|
|
7
13
|
end
|
|
8
14
|
requires_interface Cube.interface {
|
|
9
|
-
proto(:email) { String }
|
|
15
|
+
proto(:email) { Types::Strict::String }
|
|
10
16
|
}
|
|
11
17
|
end
|
|
12
18
|
|
|
@@ -16,7 +22,7 @@ AndroidNotifierT = Cube.trait do
|
|
|
16
22
|
end
|
|
17
23
|
|
|
18
24
|
requires_interface Cube.interface {
|
|
19
|
-
proto(:mobile_number) { String }
|
|
25
|
+
proto(:mobile_number) { Types::Strict::String }
|
|
20
26
|
}
|
|
21
27
|
end
|
|
22
28
|
|
|
@@ -26,7 +32,7 @@ IOSNotifierT = Cube.trait do
|
|
|
26
32
|
end
|
|
27
33
|
|
|
28
34
|
requires_interface Cube.interface {
|
|
29
|
-
proto(:mobile_number) { String }
|
|
35
|
+
proto(:mobile_number) { Types::Strict::String }
|
|
30
36
|
}
|
|
31
37
|
end
|
|
32
38
|
|
|
@@ -50,21 +56,31 @@ IOSCombinedNotifier = Cube.trait.with_trait(IOSNotifierT, rename: { notify: :mob
|
|
|
50
56
|
.with_trait(CombinedNotifierT)
|
|
51
57
|
|
|
52
58
|
MobileEmailUser = Cube.interface {
|
|
53
|
-
proto(:email) { String }
|
|
54
|
-
proto(:mobile_number) { String }
|
|
59
|
+
proto(:email) { Types::Strict::String }
|
|
60
|
+
proto(:mobile_number) { Types::Strict::String }
|
|
55
61
|
}
|
|
56
62
|
|
|
63
|
+
class Service
|
|
64
|
+
extend Dry::Initializer
|
|
65
|
+
option :email
|
|
66
|
+
option :mobile_number
|
|
67
|
+
option :type
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
AndroidService = Cube[Service].with_trait(AndroidCombinedNotifier)
|
|
71
|
+
.as_interface(MobileEmailUser)
|
|
72
|
+
IOSService = Cube[Service].with_trait(IOSCombinedNotifier)
|
|
73
|
+
.as_interface(MobileEmailUser)
|
|
74
|
+
|
|
57
75
|
Services = {
|
|
58
|
-
android:
|
|
59
|
-
ios:
|
|
76
|
+
android: AndroidService,
|
|
77
|
+
ios: IOSService
|
|
60
78
|
}
|
|
61
79
|
User = Struct.new(:email, :mobile_number, :type)
|
|
62
|
-
Cube.mark_interface!(User, MobileEmailUser)
|
|
63
|
-
CubeUser = Cube[User].as_interface(MobileEmailUser)
|
|
64
80
|
|
|
65
81
|
u1 = User.new('u1@foo.com', '1234567890', :android)
|
|
66
82
|
u2 = User.new('u2@foo.com', '1234567899', :ios)
|
|
67
83
|
|
|
68
84
|
[u1, u2].each do |u|
|
|
69
|
-
Services[u.type].new(u).notify
|
|
85
|
+
Services[u.type].new(u.to_h).notify
|
|
70
86
|
end
|
data/lib/cube/interfaces.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require 'securerandom'
|
|
2
2
|
require 'set'
|
|
3
|
+
require 'dry-types'
|
|
3
4
|
# A module for implementing Java style interfaces in Ruby. For more information
|
|
4
5
|
# about Java interfaces, please see:
|
|
5
6
|
#
|
|
@@ -9,28 +10,6 @@ require 'set'
|
|
|
9
10
|
# Top level module for RubyCube
|
|
10
11
|
module Cube
|
|
11
12
|
module Interface
|
|
12
|
-
|
|
13
|
-
def self.match_specs(i1specs, i2specs)
|
|
14
|
-
i1specs.each do |meth, i1spec|
|
|
15
|
-
i2spec = i2specs[meth]
|
|
16
|
-
raise InterfaceMatchError, "Method `#{meth}` not found" unless i2spec
|
|
17
|
-
i2_in = i2spec[:in]
|
|
18
|
-
i1_in = i1spec[:in]
|
|
19
|
-
if i1_in && (!i2_in || i1_in.size != i2_in.size)
|
|
20
|
-
raise InterfaceMatchError, "Method `#{meth}` prototype does not match"
|
|
21
|
-
end
|
|
22
|
-
(i1_in || []).each_index do |i|
|
|
23
|
-
Cube.check_type_spec(i1_in[i], i2_in[i]) { |t1, t2| t2 == t1 }
|
|
24
|
-
end
|
|
25
|
-
i1_out = i1spec[:out]
|
|
26
|
-
if i1_out
|
|
27
|
-
i2_out = i2spec[:out]
|
|
28
|
-
raise InterfaceMatchError, "Method `#{meth}` prototype does not match" unless i2_out
|
|
29
|
-
Cube.check_type_spec(i1_out, i2_out) { |t1, t2| t2 == t1 }
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
13
|
# Exceptions thrown while checking interfaces
|
|
35
14
|
class MethodMissing < RuntimeError; end
|
|
36
15
|
class PrivateVisibleMethodMissing < MethodMissing; end
|
|
@@ -131,28 +110,26 @@ module Cube
|
|
|
131
110
|
# replace method with a type checking wrapper
|
|
132
111
|
mod.class_exec do
|
|
133
112
|
# random alias name to avoid conflicts
|
|
134
|
-
ns_meth_name = "#{id}_#{SecureRandom.hex(3)}".to_sym
|
|
113
|
+
ns_meth_name = "#{id}_#{SecureRandom.hex(3)}".to_sym
|
|
135
114
|
alias_method ns_meth_name, id
|
|
136
115
|
# The type checking wrapper
|
|
137
116
|
define_method(id) do |*args|
|
|
138
|
-
args.
|
|
139
|
-
# the value and expected type of the arg
|
|
140
|
-
v, t = args[i], inchecks[i]
|
|
117
|
+
new_args = args.zip(inchecks).map do |v, t|
|
|
141
118
|
begin
|
|
142
|
-
Cube.check_type(t,
|
|
143
|
-
rescue
|
|
119
|
+
Cube.check_type(t,v)
|
|
120
|
+
rescue Dry::Types::ConstraintError => e
|
|
144
121
|
raise Interface::TypeMismatchError,
|
|
145
|
-
"#{mod}: #{iface}##{id}
|
|
122
|
+
"#{mod}: #{iface}##{id} : #{e.message}"
|
|
146
123
|
end
|
|
147
124
|
end
|
|
148
125
|
# types look good, call the original method
|
|
149
|
-
ret = send(ns_meth_name, *
|
|
126
|
+
ret = send(ns_meth_name, *new_args)
|
|
150
127
|
# check return type if it exists
|
|
151
128
|
begin
|
|
152
129
|
Cube.check_type(outcheck, ret) if outcheck
|
|
153
|
-
rescue
|
|
130
|
+
rescue Dry::Types::ConstraintError => e
|
|
154
131
|
raise Interface::TypeMismatchError,
|
|
155
|
-
|
|
132
|
+
"#{mod}: #{iface}##{id} (return): #{e.message}"
|
|
156
133
|
end
|
|
157
134
|
# looks good, return
|
|
158
135
|
ret
|
|
@@ -174,12 +151,8 @@ module Cube
|
|
|
174
151
|
# validate the interface spec is valid
|
|
175
152
|
def validate_spec(spec)
|
|
176
153
|
[*spec].each do |t|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
raise ArgumentError, "#{t} does not contain a Module or Interface"
|
|
180
|
-
end
|
|
181
|
-
elsif !t.is_a?(Module)
|
|
182
|
-
raise ArgumentError, "#{t} is not a Module or Interface"
|
|
154
|
+
unless t.is_a?(Dry::Types::Type) || t.is_a?(Module)
|
|
155
|
+
raise ArgumentError, "#{t} is not a Dry::Types::Type nor a Module"
|
|
183
156
|
end
|
|
184
157
|
end
|
|
185
158
|
end
|
|
@@ -203,13 +176,6 @@ module Cube
|
|
|
203
176
|
@ids.merge(inherited_specs)
|
|
204
177
|
end
|
|
205
178
|
|
|
206
|
-
def assert_match(intf)
|
|
207
|
-
raise ArgumentError, "#{intf} is not a Cube::Interface" unless intf.is_a?(Interface)
|
|
208
|
-
intf_specs = intf.to_spec
|
|
209
|
-
self_specs = to_spec
|
|
210
|
-
Interface.match_specs(self_specs, intf_specs)
|
|
211
|
-
end
|
|
212
|
-
|
|
213
179
|
def proto(meth, *args)
|
|
214
180
|
out_spec = yield if block_given?
|
|
215
181
|
validate_spec(args)
|
data/lib/cube/toplevel.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require 'dry-types'
|
|
2
|
+
|
|
1
3
|
module Cube
|
|
2
4
|
def self.mark_interface!(cls, iface)
|
|
3
5
|
Cube[cls].as_interface(iface, runtime_checks: false)
|
|
@@ -36,49 +38,36 @@ module Cube
|
|
|
36
38
|
m
|
|
37
39
|
end
|
|
38
40
|
|
|
39
|
-
def self.check_type_spec(t, v, &blk)
|
|
40
|
-
if t.is_a?(Set)
|
|
41
|
-
if v.is_a?(Set)
|
|
42
|
-
if v != t
|
|
43
|
-
raise Cube::Interface::TypeMismatchError, "#{t.to_a} is not eql to #{v.to_a}"
|
|
44
|
-
end
|
|
45
|
-
return true
|
|
46
|
-
end
|
|
47
|
-
unless t.any? { |tp| check_type(tp, v, &blk) rescue false }
|
|
48
|
-
raise Cube::Interface::TypeMismatchError,
|
|
49
|
-
"#{v.inspect} is not any of #{t.to_a}"
|
|
50
|
-
end
|
|
51
|
-
return
|
|
52
|
-
end
|
|
53
|
-
if t.is_a? Array
|
|
54
|
-
raise Cube::Interface::TypeMismatchError,
|
|
55
|
-
"#{v} is not an Array" unless v.is_a? Array
|
|
56
|
-
check_type(t.first, v.first, &blk)
|
|
57
|
-
check_type(t.first, v.last, &blk)
|
|
58
|
-
return
|
|
59
|
-
end
|
|
60
|
-
raise Cube::Interface::TypeMismatchError, "#{v.inspect} is not type #{t}" unless blk.call(t, v)
|
|
61
|
-
true
|
|
62
|
-
end
|
|
41
|
+
# def self.check_type_spec(t, v, &blk)
|
|
42
|
+
# if t.is_a?(Set)
|
|
43
|
+
# if v.is_a?(Set)
|
|
44
|
+
# if v != t
|
|
45
|
+
# raise Cube::Interface::TypeMismatchError, "#{t.to_a} is not eql to #{v.to_a}"
|
|
46
|
+
# end
|
|
47
|
+
# return true
|
|
48
|
+
# end
|
|
49
|
+
# unless t.any? { |tp| check_type(tp, v, &blk) rescue false }
|
|
50
|
+
# raise Cube::Interface::TypeMismatchError,
|
|
51
|
+
# "#{v.inspect} is not any of #{t.to_a}"
|
|
52
|
+
# end
|
|
53
|
+
# return
|
|
54
|
+
# end
|
|
55
|
+
# if t.is_a? Array
|
|
56
|
+
# raise Cube::Interface::TypeMismatchError,
|
|
57
|
+
# "#{v} is not an Array" unless v.is_a? Array
|
|
58
|
+
# check_type(t.first, v.first, &blk)
|
|
59
|
+
# check_type(t.first, v.last, &blk)
|
|
60
|
+
# return
|
|
61
|
+
# end
|
|
62
|
+
# raise Cube::Interface::TypeMismatchError, "#{v.inspect} is not type #{t}" unless blk.call(t, v)
|
|
63
|
+
# true
|
|
64
|
+
# end
|
|
63
65
|
|
|
64
66
|
if ENV['RUBY_CUBE_TYPECHECK'].to_i > 0
|
|
65
67
|
def self.check_type(t, v)
|
|
66
|
-
if t.is_a?
|
|
67
|
-
unless t.any? { |tp| check_type(tp, v) rescue false }
|
|
68
|
-
raise Cube::Interface::TypeMismatchError,
|
|
69
|
-
"#{v.inspect} is not any of #{t.to_a}"
|
|
70
|
-
end
|
|
71
|
-
return
|
|
72
|
-
end
|
|
73
|
-
if t.is_a? Array
|
|
74
|
-
raise Cube::Interface::TypeMismatchError,
|
|
75
|
-
"#{v} is not an Array" unless v.is_a? Array
|
|
76
|
-
check_type(t.first, v.first)
|
|
77
|
-
check_type(t.first, v.last)
|
|
78
|
-
return
|
|
79
|
-
end
|
|
68
|
+
return t[v] if t.is_a? Dry::Types::Type
|
|
80
69
|
raise Cube::Interface::TypeMismatchError, "#{v.inspect} is not type #{t}" unless v.is_a? t
|
|
81
|
-
|
|
70
|
+
v
|
|
82
71
|
end
|
|
83
72
|
else
|
|
84
73
|
def self.check_type(*_); end
|
data/lib/cube/traits.rb
CHANGED
|
@@ -43,38 +43,6 @@ module Cube
|
|
|
43
43
|
end
|
|
44
44
|
super
|
|
45
45
|
end
|
|
46
|
-
|
|
47
|
-
def wrap(intf)
|
|
48
|
-
assert_match(intf)
|
|
49
|
-
cls = Class.new(SimpleDelegator) do
|
|
50
|
-
define_method(:initialize) do |obj|
|
|
51
|
-
$stderr.puts "Checking with #{intf}"
|
|
52
|
-
Cube.check_type(intf, obj)
|
|
53
|
-
super(obj)
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
inc_trait = clone
|
|
57
|
-
inc_trait.instance_variable_set(:@__interface_trait_required_interface, nil)
|
|
58
|
-
inc_trait.instance_variable_set(:@__trait_cloned_from, self)
|
|
59
|
-
Cube[cls].with_trait(inc_trait)
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
def assert_match(intf)
|
|
63
|
-
self_methods = instance_methods
|
|
64
|
-
inherited = self.ancestors.select{ |x| Trait === x }
|
|
65
|
-
required_interface_spec = inherited.inject({}) { |acc, x|
|
|
66
|
-
req = x.instance_variable_get('@__interface_trait_required_interface')
|
|
67
|
-
if req
|
|
68
|
-
acc.merge(req.to_spec)
|
|
69
|
-
else
|
|
70
|
-
acc
|
|
71
|
-
end
|
|
72
|
-
}
|
|
73
|
-
self_methods.each do |sm|
|
|
74
|
-
required_interface_spec.delete(sm)
|
|
75
|
-
end
|
|
76
|
-
Interface.match_specs(required_interface_spec, intf.to_spec)
|
|
77
|
-
end
|
|
78
46
|
end
|
|
79
47
|
end
|
|
80
48
|
|
data/rubycube-0.3.0.gem
ADDED
|
Binary file
|
data/test/test_interface.rb
CHANGED
|
@@ -5,15 +5,19 @@
|
|
|
5
5
|
#####################################################
|
|
6
6
|
ENV['RUBY_CUBE_TYPECHECK'] = "1"
|
|
7
7
|
require 'test-unit'
|
|
8
|
-
|
|
8
|
+
require_relative '../lib/cube'
|
|
9
|
+
require 'dry-types'
|
|
9
10
|
|
|
11
|
+
module Types
|
|
12
|
+
include Dry::Types.module
|
|
13
|
+
end
|
|
10
14
|
|
|
11
15
|
class TC_Interface < Test::Unit::TestCase
|
|
12
16
|
def self.startup
|
|
13
17
|
alpha_interface = Cube.interface{
|
|
14
18
|
public_visible(:alpha, :beta)
|
|
15
|
-
proto(:beta) {
|
|
16
|
-
proto(:delta,
|
|
19
|
+
proto(:beta) { Types::Strict::Int|Types::Strict::Nil }
|
|
20
|
+
proto(:delta, Types::Strict::Int, Types::Strict::String, Types::Strict::Int) { Types::Strict::Int }
|
|
17
21
|
}
|
|
18
22
|
|
|
19
23
|
gamma_interface = Cube.interface{
|
|
@@ -84,9 +88,9 @@ class TC_Interface < Test::Unit::TestCase
|
|
|
84
88
|
assert_nothing_raised {
|
|
85
89
|
Cube[B].as_interface(@@alpha_interface).as_interface(@@alpha_interface)
|
|
86
90
|
}
|
|
87
|
-
assert_nothing_raised {
|
|
91
|
+
# assert_nothing_raised {
|
|
88
92
|
Cube[B].as_interface(@@alpha_interface, runtime_checks: true).new.beta
|
|
89
|
-
}
|
|
93
|
+
# }
|
|
90
94
|
assert_raise(ArgumentError) {
|
|
91
95
|
Cube[B].as_interface(@@alpha_interface).new.delta
|
|
92
96
|
}
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rubycube
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Aditya Godbole
|
|
@@ -9,8 +9,36 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain:
|
|
11
11
|
- certs/djberg96_pub.pem
|
|
12
|
-
date:
|
|
12
|
+
date: 2018-03-18 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: dry-types
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
|
+
requirements:
|
|
18
|
+
- - ">="
|
|
19
|
+
- !ruby/object:Gem::Version
|
|
20
|
+
version: '0'
|
|
21
|
+
type: :runtime
|
|
22
|
+
prerelease: false
|
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
24
|
+
requirements:
|
|
25
|
+
- - ">="
|
|
26
|
+
- !ruby/object:Gem::Version
|
|
27
|
+
version: '0'
|
|
28
|
+
- !ruby/object:Gem::Dependency
|
|
29
|
+
name: dry-types
|
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
|
31
|
+
requirements:
|
|
32
|
+
- - ">="
|
|
33
|
+
- !ruby/object:Gem::Version
|
|
34
|
+
version: '0'
|
|
35
|
+
type: :development
|
|
36
|
+
prerelease: false
|
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
38
|
+
requirements:
|
|
39
|
+
- - ">="
|
|
40
|
+
- !ruby/object:Gem::Version
|
|
41
|
+
version: '0'
|
|
14
42
|
- !ruby/object:Gem::Dependency
|
|
15
43
|
name: test-unit
|
|
16
44
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -39,8 +67,8 @@ dependencies:
|
|
|
39
67
|
- - ">="
|
|
40
68
|
- !ruby/object:Gem::Version
|
|
41
69
|
version: '0'
|
|
42
|
-
description:
|
|
43
|
-
|
|
70
|
+
description: " CUBE (Composable Units of Behaviour) implements Interfaces, Traits
|
|
71
|
+
and typechecks for Ruby.\n"
|
|
44
72
|
email: code.aa@gdbl.me
|
|
45
73
|
executables: []
|
|
46
74
|
extensions: []
|
|
@@ -56,75 +84,13 @@ files:
|
|
|
56
84
|
- Rakefile
|
|
57
85
|
- certs/djberg96_pub.pem
|
|
58
86
|
- cube.gemspec
|
|
59
|
-
- doc/Bar.html
|
|
60
|
-
- doc/CHANGES.html
|
|
61
|
-
- doc/Foo.html
|
|
62
|
-
- doc/Interface.html
|
|
63
|
-
- doc/Interface/MethodMissing.html
|
|
64
|
-
- doc/Interface/PrivateVisibleMethodMissing.html
|
|
65
|
-
- doc/Interface/PublicVisibleMethodMissing.html
|
|
66
|
-
- doc/MANIFEST.html
|
|
67
|
-
- doc/Module.html
|
|
68
|
-
- doc/MyClass.html
|
|
69
|
-
- doc/MyInterface.html
|
|
70
|
-
- doc/MySubInterface.html
|
|
71
|
-
- doc/Object.html
|
|
72
|
-
- doc/README.html
|
|
73
|
-
- doc/Rakefile.html
|
|
74
|
-
- doc/TC_Interface.html
|
|
75
|
-
- doc/certs/djberg96_pub_pem.html
|
|
76
|
-
- doc/created.rid
|
|
77
|
-
- doc/css/fonts.css
|
|
78
|
-
- doc/css/rdoc.css
|
|
79
|
-
- doc/fonts/Lato-Light.ttf
|
|
80
|
-
- doc/fonts/Lato-LightItalic.ttf
|
|
81
|
-
- doc/fonts/Lato-Regular.ttf
|
|
82
|
-
- doc/fonts/Lato-RegularItalic.ttf
|
|
83
|
-
- doc/fonts/SourceCodePro-Bold.ttf
|
|
84
|
-
- doc/fonts/SourceCodePro-Regular.ttf
|
|
85
|
-
- doc/images/add.png
|
|
86
|
-
- doc/images/arrow_up.png
|
|
87
|
-
- doc/images/brick.png
|
|
88
|
-
- doc/images/brick_link.png
|
|
89
|
-
- doc/images/bug.png
|
|
90
|
-
- doc/images/bullet_black.png
|
|
91
|
-
- doc/images/bullet_toggle_minus.png
|
|
92
|
-
- doc/images/bullet_toggle_plus.png
|
|
93
|
-
- doc/images/date.png
|
|
94
|
-
- doc/images/delete.png
|
|
95
|
-
- doc/images/find.png
|
|
96
|
-
- doc/images/loadingAnimation.gif
|
|
97
|
-
- doc/images/macFFBgHack.png
|
|
98
|
-
- doc/images/package.png
|
|
99
|
-
- doc/images/page_green.png
|
|
100
|
-
- doc/images/page_white_text.png
|
|
101
|
-
- doc/images/page_white_width.png
|
|
102
|
-
- doc/images/plugin.png
|
|
103
|
-
- doc/images/ruby.png
|
|
104
|
-
- doc/images/tag_blue.png
|
|
105
|
-
- doc/images/tag_green.png
|
|
106
|
-
- doc/images/transparent.png
|
|
107
|
-
- doc/images/wrench.png
|
|
108
|
-
- doc/images/wrench_orange.png
|
|
109
|
-
- doc/images/zoom.png
|
|
110
|
-
- doc/index.html
|
|
111
|
-
- doc/interface_gemspec.html
|
|
112
|
-
- doc/js/darkfish.js
|
|
113
|
-
- doc/js/jquery.js
|
|
114
|
-
- doc/js/navigation.js
|
|
115
|
-
- doc/js/navigation.js.gz
|
|
116
|
-
- doc/js/search.js
|
|
117
|
-
- doc/js/search_index.js
|
|
118
|
-
- doc/js/search_index.js.gz
|
|
119
|
-
- doc/js/searcher.js
|
|
120
|
-
- doc/js/searcher.js.gz
|
|
121
|
-
- doc/table_of_contents.html
|
|
122
87
|
- examples/demo.rb
|
|
123
88
|
- examples/traits.rb
|
|
124
89
|
- lib/cube.rb
|
|
125
90
|
- lib/cube/interfaces.rb
|
|
126
91
|
- lib/cube/toplevel.rb
|
|
127
92
|
- lib/cube/traits.rb
|
|
93
|
+
- rubycube-0.3.0.gem
|
|
128
94
|
- test/test_interface.rb
|
|
129
95
|
homepage: http://github.com/adityagodbole/rubycube
|
|
130
96
|
licenses:
|
|
@@ -146,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
146
112
|
version: '0'
|
|
147
113
|
requirements: []
|
|
148
114
|
rubyforge_project:
|
|
149
|
-
rubygems_version: 2.
|
|
115
|
+
rubygems_version: 2.5.2.2
|
|
150
116
|
signing_key:
|
|
151
117
|
specification_version: 4
|
|
152
118
|
summary: Interfaces for Ruby
|