protocol 1.0.1 → 2.0.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.
@@ -4,8 +4,6 @@ require 'test_helper'
4
4
 
5
5
  class ProtocolTest < Test::Unit::TestCase
6
6
  ProtocolTest_foo = Protocol do
7
- check_failure :none
8
-
9
7
  understand :foo
10
8
  end
11
9
 
@@ -33,8 +31,6 @@ class ProtocolTest < Test::Unit::TestCase
33
31
  end
34
32
 
35
33
  ProtocolTest_foo_bar_2_fail = Protocol do
36
- check_failure :error
37
-
38
34
  include ProtocolTest::ProtocolTest_foo
39
35
  include ProtocolTest::ProtocolTest_bar
40
36
  end
@@ -61,8 +57,6 @@ class ProtocolTest < Test::Unit::TestCase
61
57
  end
62
58
 
63
59
  ProtocolTestPartial = Protocol do
64
- check_failure :none
65
-
66
60
  implementation
67
61
 
68
62
  def map(&block)
@@ -77,8 +71,6 @@ class ProtocolTest < Test::Unit::TestCase
77
71
  end
78
72
 
79
73
  ProtocolTestPartial_fail = Protocol do
80
- check_failure :error
81
-
82
74
  def each(&block) end
83
75
 
84
76
  implementation
@@ -127,11 +119,11 @@ class ProtocolTest < Test::Unit::TestCase
127
119
  end
128
120
 
129
121
  ProtocolTestInheritance = Protocol do
130
- inherit ProtocolTest::MyClass, :one_with_block
122
+ infer ProtocolTest::MyClass, :one_with_block
131
123
  end
132
124
 
133
125
  ProtocolTestInheritanceC = Protocol do
134
- inherit ::Array, :each, true
126
+ infer ::Array, :each, true
135
127
  end
136
128
 
137
129
  def test_define_protocol
@@ -141,7 +133,7 @@ class ProtocolTest < Test::Unit::TestCase
141
133
  end
142
134
  assert_kind_of Protocol::ProtocolModule, foo_protocol
143
135
  assert_raises(Protocol::SpecificationError) do
144
- foo2_protocol = Protocol do
136
+ Protocol do
145
137
  understand :foo
146
138
  understand :foo
147
139
  end
@@ -183,7 +175,7 @@ class ProtocolTest < Test::Unit::TestCase
183
175
  assert_equal 1, ProtocolTest_foo_bar_1.check_failures(c1.new).size
184
176
 
185
177
  c2 = Class.new do
186
- conform_to ProtocolTest_foo
178
+ conform_to? ProtocolTest_foo
187
179
  end
188
180
  assert !c2.conform_to?(ProtocolTest_foo)
189
181
  assert !c2.new.conform_to?(ProtocolTest_foo)
@@ -207,7 +199,7 @@ class ProtocolTest < Test::Unit::TestCase
207
199
  assert !c1.new.conform_to?(ProtocolTest_bar)
208
200
 
209
201
  begin
210
- c2 = Class.new do
202
+ Class.new do
211
203
  conform_to ProtocolTest_foo_fail
212
204
  end
213
205
  assert(false)
@@ -220,7 +212,7 @@ class ProtocolTest < Test::Unit::TestCase
220
212
 
221
213
  def test_inclusion1_with_fail
222
214
  begin
223
- c = Class.new do
215
+ Class.new do
224
216
  def bar; end
225
217
  conform_to ProtocolTest_foo_bar_1_fail
226
218
  end
@@ -272,7 +264,7 @@ class ProtocolTest < Test::Unit::TestCase
272
264
  end
273
265
 
274
266
  def test_arity2
275
- c = Class.new do
267
+ Class.new do
276
268
  def bar(x, y) x + y end
277
269
  def baz(x, y, z) Math.sqrt(x * x + y * y + z * z) end
278
270
  def foo(x) x end
@@ -287,7 +279,7 @@ class ProtocolTest < Test::Unit::TestCase
287
279
  end
288
280
 
289
281
  def test_arity3
290
- c = Class.new do
282
+ Class.new do
291
283
  def bar(x, y) x + y end
292
284
  def baz(x, y, z) Math.sqrt(x * x + y * y + z * z) end
293
285
  def foo(x) x end
@@ -302,7 +294,7 @@ class ProtocolTest < Test::Unit::TestCase
302
294
 
303
295
  def test_block
304
296
  begin
305
- c1 = Class.new do
297
+ Class.new do
306
298
  def foo(x) end
307
299
 
308
300
  conform_to ProtocolTestBlock
@@ -317,7 +309,7 @@ class ProtocolTest < Test::Unit::TestCase
317
309
  end
318
310
  assert !c1b.new.conform_to?(ProtocolTestBlock)
319
311
  begin
320
- c2 = Class.new do
312
+ Class.new do
321
313
  def foo(x, &block) block[x] end
322
314
 
323
315
  conform_to ProtocolTestBlock
@@ -329,7 +321,7 @@ class ProtocolTest < Test::Unit::TestCase
329
321
  assert(false)
330
322
  end
331
323
  begin
332
- c3 = Class.new do
324
+ Class.new do
333
325
  def foo(x) yield x end
334
326
 
335
327
  conform_to ProtocolTestBlock
@@ -346,30 +338,6 @@ class ProtocolTest < Test::Unit::TestCase
346
338
  assert obj.conform_to?(ProtocolTestBlock)
347
339
  end
348
340
 
349
- def test_partial_without_fail
350
- c1 = Class.new do
351
- def each(&block)
352
- (1..3).each(&block)
353
- self
354
- end
355
-
356
- conform_to ProtocolTestPartial
357
- end
358
- obj = c1.new
359
- assert c1.conform_to?(ProtocolTestPartial)
360
- assert obj.conform_to?(ProtocolTestPartial)
361
- assert_equal [ 1, 4, 9], obj.map { |x| x * x }
362
- assert_equal obj, obj.each { |x| x * x }
363
-
364
- c2 = Class.new do
365
- conform_to ProtocolTestPartial
366
- end
367
- assert !c2.conform_to?(ProtocolTestPartial)
368
- assert !c2.new.conform_to?(ProtocolTestPartial)
369
- assert_raises(NoMethodError) { c2.new.map { |x| x * x } }
370
- assert_equal obj, obj.each { |x| x * x }
371
- end
372
-
373
341
  def test_partial_with_fail
374
342
  c1 = Class.new do
375
343
  def each(&block)
@@ -386,7 +354,7 @@ class ProtocolTest < Test::Unit::TestCase
386
354
  assert_equal obj, obj.each { |x| x * x }
387
355
 
388
356
  begin
389
- c2 = Class.new do
357
+ Class.new do
390
358
  conform_to ProtocolTestPartial_fail
391
359
  end
392
360
  assert(false)
@@ -552,9 +520,9 @@ class ProtocolTest < Test::Unit::TestCase
552
520
  assert_raises(Protocol::PostconditionCheckError) { o2.foo_bar(5, 7) }
553
521
  end
554
522
 
555
- def test_inheritance
523
+ def test_inference
556
524
  begin
557
- c1 = Class.new do
525
+ Class.new do
558
526
  conform_to ProtocolTestInheritance
559
527
  end
560
528
  rescue Protocol::CheckFailed
@@ -563,7 +531,7 @@ class ProtocolTest < Test::Unit::TestCase
563
531
  assert(false)
564
532
  end
565
533
  begin
566
- c2 = Class.new do
534
+ Class.new do
567
535
  def one_with_block() end
568
536
  conform_to ProtocolTestInheritance
569
537
  end
@@ -573,7 +541,7 @@ class ProtocolTest < Test::Unit::TestCase
573
541
  assert(false)
574
542
  end
575
543
  begin
576
- c3 = Class.new do
544
+ Class.new do
577
545
  def one_with_block(foo) end
578
546
  conform_to ProtocolTestInheritance
579
547
  end
@@ -583,7 +551,7 @@ class ProtocolTest < Test::Unit::TestCase
583
551
  assert(false)
584
552
  end
585
553
  begin
586
- c4 = Class.new do
554
+ Class.new do
587
555
  def one_with_block(foo, &block) end
588
556
  conform_to ProtocolTestInheritance
589
557
  end
@@ -594,7 +562,7 @@ class ProtocolTest < Test::Unit::TestCase
594
562
  assert(false)
595
563
  end
596
564
  begin
597
- c5 = Class.new do
565
+ Class.new do
598
566
  def each() end
599
567
  conform_to ProtocolTestInheritanceC
600
568
  end
@@ -604,7 +572,7 @@ class ProtocolTest < Test::Unit::TestCase
604
572
  assert(false)
605
573
  end
606
574
  begin
607
- c6 = Class.new do
575
+ Class.new do
608
576
  def each(&block) end
609
577
  conform_to ProtocolTestInheritanceC
610
578
  end
metadata CHANGED
@@ -1,55 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protocol
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-19 00:00:00.000000000 Z
11
+ date: 2019-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gem_hadar
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.3.2
19
+ version: 1.9.1
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.3.2
26
+ version: 1.9.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: simplecov
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: test-unit
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
39
53
  - !ruby/object:Gem::Version
40
54
  version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: ruby_parser
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
- - - ~>
59
+ - - "~>"
46
60
  - !ruby/object:Gem::Version
47
61
  version: '3.0'
48
62
  type: :runtime
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - ~>
66
+ - - "~>"
53
67
  - !ruby/object:Gem::Version
54
68
  version: '3.0'
55
69
  description: |
@@ -75,8 +89,9 @@ extra_rdoc_files:
75
89
  - lib/protocol/version.rb
76
90
  - lib/protocol/xt.rb
77
91
  files:
78
- - .gitignore
79
- - .travis.yml
92
+ - ".gitignore"
93
+ - ".travis.yml"
94
+ - ".utilsrc"
80
95
  - CHANGES
81
96
  - COPYING
82
97
  - Gemfile
@@ -91,9 +106,9 @@ files:
91
106
  - examples/game.rb
92
107
  - examples/hello_world_patternitis.rb
93
108
  - examples/indexing.rb
94
- - examples/locking.rb
95
109
  - examples/queue.rb
96
110
  - examples/stack.rb
111
+ - examples/synchronizing.rb
97
112
  - install.rb
98
113
  - lib/protocol.rb
99
114
  - lib/protocol/core.rb
@@ -107,6 +122,7 @@ files:
107
122
  - lib/protocol/version.rb
108
123
  - lib/protocol/xt.rb
109
124
  - protocol.gemspec
125
+ - tests/protocol_core_test.rb
110
126
  - tests/protocol_method_parser_test.rb
111
127
  - tests/protocol_test.rb
112
128
  - tests/test_helper.rb
@@ -116,29 +132,29 @@ licenses:
116
132
  metadata: {}
117
133
  post_install_message:
118
134
  rdoc_options:
119
- - --title
135
+ - "--title"
120
136
  - Protocol - Method Protocols for Ruby Classes
121
- - --main
137
+ - "--main"
122
138
  - README.rdoc
123
139
  require_paths:
124
140
  - lib
125
141
  required_ruby_version: !ruby/object:Gem::Requirement
126
142
  requirements:
127
- - - '>='
143
+ - - ">="
128
144
  - !ruby/object:Gem::Version
129
145
  version: '0'
130
146
  required_rubygems_version: !ruby/object:Gem::Requirement
131
147
  requirements:
132
- - - '>='
148
+ - - ">="
133
149
  - !ruby/object:Gem::Version
134
150
  version: '0'
135
151
  requirements: []
136
- rubyforge_project:
137
- rubygems_version: 2.0.4
152
+ rubygems_version: 3.0.6
138
153
  signing_key:
139
154
  specification_version: 4
140
155
  summary: Method Protocols for Ruby Classes
141
156
  test_files:
157
+ - tests/protocol_core_test.rb
142
158
  - tests/protocol_method_parser_test.rb
143
159
  - tests/protocol_test.rb
144
160
  - tests/test_helper.rb
data/examples/locking.rb DELETED
@@ -1,111 +0,0 @@
1
- require 'protocol'
2
-
3
- Locking = Protocol do
4
- specification # not necessary, because Protocol defaults to specification
5
- # mode already
6
-
7
- def lock() end
8
-
9
- def unlock() end
10
-
11
- implementation
12
-
13
- def synchronize
14
- lock
15
- begin
16
- yield
17
- ensure
18
- unlock
19
- end
20
- end
21
- end
22
-
23
- if $0 == __FILE__
24
- require 'thread'
25
- require 'tempfile'
26
-
27
- class FileMutex
28
- def initialize
29
- @tempfile = Tempfile.new 'file-mutex'
30
- end
31
-
32
- def path
33
- @tempfile.path
34
- end
35
-
36
- def lock
37
- puts "Locking '#{path}'."
38
- @tempfile.flock File::LOCK_EX
39
- end
40
-
41
- def unlock
42
- puts "Unlocking '#{path}'."
43
- @tempfile.flock File::LOCK_UN
44
- end
45
-
46
- conform_to Locking
47
- end
48
-
49
- FileMutex.conform_to? Locking # => true
50
- FileMutex.new.conform_to? Locking # => true
51
-
52
- # Outputs something like:
53
- # Locking '...'.
54
- # Synchronized with '...'..
55
- # Unlocking '...'.
56
- p mutex = FileMutex.new
57
- mutex.synchronize do
58
- puts "Synchronized with '#{mutex.path}'."
59
- end
60
-
61
- class MemoryMutex
62
- def initialize
63
- @mutex = Mutex.new
64
- end
65
-
66
- def lock
67
- @mutex.lock
68
- end
69
-
70
- def unlock
71
- @mutex.unlock
72
- end
73
-
74
- conform_to Locking # actually Mutex itself would conform as well ;)
75
- end
76
-
77
- p mutex = MemoryMutex.new
78
- mutex.synchronize do
79
- puts "Synchronized in memory."
80
- end
81
-
82
- puts MemoryMutex.conform_to?(Locking).to_s + ' (true)'
83
- puts MemoryMutex.new.conform_to?(Locking).to_s + ' (true)'
84
-
85
- class MyClass
86
- def initialize
87
- @mutex = FileMutex.new
88
- end
89
-
90
- attr_reader :mutex
91
-
92
- def mutex=(mutex)
93
- Locking =~ mutex
94
- @mutex = mutex
95
- end
96
- end
97
-
98
- obj = MyClass.new
99
- p obj.mutex # => #<FileMutex:0xb788f9ac @tempfile=#<File:/tmp/file-mutex.26553.2>>
100
- begin
101
- obj.mutex = Object.new
102
- puts "Should have thrown Protocol::CheckFailed!"
103
- rescue Protocol::CheckFailed => e
104
- p e
105
- end
106
- p obj.mutex = MemoryMutex.new # => #<MemoryMutex:0xb788f038 @mutex=#<Mutex:0xb788eea8>>
107
- # This works as well:
108
- obj.mutex = Mutex.new
109
- puts Locking.check(Mutex).to_s + ' (true)'
110
- puts Mutex.conform_to?(Locking).to_s + ' (true)'
111
- end