evt-virtual 2.0.1.2 → 2.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 219f86d85d6b5e37dfe30afc0819efada92c06b61fd066d59cf4c1a3eb9cb54a
4
- data.tar.gz: acf22bd74e7778178a48ddf5ba898568cceb6a4c3d9fc4a37e5c2a10edc704eb
3
+ metadata.gz: 6b99fa347649061dabcb64bea008a1d50ca99c018bcc26dc1bb95dcb3e7983fe
4
+ data.tar.gz: 78cfbfb5718dd2b60cff7011521c37bc8dab18a90d433ffd65e367d51be58c47
5
5
  SHA512:
6
- metadata.gz: af2ba6bc1fe4644ef4a2ec9b962c02f565d9c6356d2c99eb94dc0223e7bd626b156b6cbbc13c413605c2a7748746dab383703ee18437307cd2a065765b43de53
7
- data.tar.gz: a2ecc3775fc56e33a142add7e7561d60dd2e955ecb7f5236b09b68d0b3a67aa2a846ac887808e127107fd632f88c5b9a9821f1e14ab654783c60d40e22921bb6
6
+ metadata.gz: 18bb8c29bff1bfeef525735b2369250c3c177219d63aaac860aaa9debfa69c25aa43f8abe53c6dddf3e19a1a8bc8d79dd1b868bf2fc424404a4e011c772e15f5
7
+ data.tar.gz: e723b840b59c4065fcf05757b3adfcf6626b05c44fd81258a99b7ac64637585fa34f293c0f55946ce044c8527d40011e05e8c6a65f3e6e90771ac98c05172c94
@@ -12,9 +12,13 @@ module Virtual
12
12
 
13
13
  subject = subject_class(target_class)
14
14
 
15
- ['virtual', 'pure_virtual', 'abstract'].each do |mthd|
16
- fail mthd unless subject.respond_to?(mthd)
15
+ Macro.macro_methods.each do |mthd|
16
+ if not subject.respond_to?(mthd)
17
+ return false
18
+ end
17
19
  end
20
+
21
+ true
18
22
  end
19
23
 
20
24
  def self.subject_class(subject)
@@ -1,15 +1,15 @@
1
1
  module Virtual
2
2
  module Controls
3
3
  module AbstractMethod
4
+ def self.example
5
+ Example.new
6
+ end
7
+
4
8
  class Example
5
9
  include Virtual
6
10
 
7
11
  pure_virtual :some_pure_virtual_method
8
12
  end
9
-
10
- def self.example
11
- Example.new
12
- end
13
13
  end
14
14
  end
15
15
  end
@@ -1,13 +1,13 @@
1
1
  module Virtual
2
2
  module Controls
3
3
  module Extended
4
- class Example
5
- extend Virtual
6
- end
7
-
8
4
  def self.example
9
5
  Example.new
10
6
  end
7
+
8
+ class Example
9
+ extend Virtual
10
+ end
11
11
  end
12
12
  end
13
13
  end
@@ -1,13 +1,13 @@
1
1
  module Virtual
2
2
  module Controls
3
3
  module Included
4
- class Example
5
- include Virtual
6
- end
7
-
8
4
  def self.example
9
5
  Example.new
10
6
  end
7
+
8
+ class Example
9
+ include Virtual
10
+ end
11
11
  end
12
12
  end
13
13
  end
@@ -0,0 +1,40 @@
1
+ module Virtual
2
+ module Controls
3
+ module ProtocolMethod
4
+ def self.example
5
+ Example.new
6
+ end
7
+
8
+ class Example
9
+ include Virtual
10
+
11
+ protocol :some_protocol_method
12
+ end
13
+
14
+ module Implemented
15
+ def self.example
16
+ Implementer.new
17
+ end
18
+
19
+ class Implementer < Example
20
+ def some_protocol_method
21
+ end
22
+ end
23
+ end
24
+
25
+ module Override
26
+ def self.example
27
+ Class.new do
28
+ include Virtual
29
+
30
+ def some_protocol_method
31
+ end
32
+
33
+ protocol :some_protocol_method
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+
@@ -1,24 +1,37 @@
1
1
  module Virtual
2
2
  module Controls
3
3
  module PureVirtualMethod
4
+ def self.example
5
+ Example.new
6
+ end
7
+
4
8
  class Example
5
9
  include Virtual
6
10
 
7
11
  pure_virtual :some_pure_virtual_method
8
12
  end
9
13
 
10
- def self.example
11
- Example.new
12
- end
13
-
14
14
  module Implemented
15
+ def self.example
16
+ Implementer.new
17
+ end
18
+
15
19
  class Implementer < Example
16
20
  def some_pure_virtual_method
17
21
  end
18
22
  end
23
+ end
19
24
 
25
+ module Override
20
26
  def self.example
21
- Implementer.new
27
+ Class.new do
28
+ include Virtual
29
+
30
+ def some_pure_virtual_method
31
+ end
32
+
33
+ pure_virtual :some_pure_virtual_method
34
+ end
22
35
  end
23
36
  end
24
37
  end
@@ -1,17 +1,21 @@
1
1
  module Virtual
2
2
  module Controls
3
3
  module VirtualMethod
4
+ def self.example
5
+ Example.new
6
+ end
7
+
4
8
  class Example
5
9
  include Virtual
6
10
 
7
11
  virtual :some_virtual_method
8
12
  end
9
13
 
10
- def self.example
11
- Example.new
12
- end
13
-
14
14
  module Body
15
+ def self.example
16
+ Example.new
17
+ end
18
+
15
19
  class Example
16
20
  include Virtual
17
21
 
@@ -19,9 +23,18 @@ module Virtual
19
23
  :something
20
24
  end
21
25
  end
26
+ end
22
27
 
28
+ module Override
23
29
  def self.example
24
- Example.new
30
+ Class.new do
31
+ include Virtual
32
+
33
+ def some_virtual_method
34
+ end
35
+
36
+ virtual :some_virtual_method
37
+ end
25
38
  end
26
39
  end
27
40
  end
@@ -4,3 +4,4 @@ require 'virtual/controls/extended'
4
4
  require 'virtual/controls/virtual_method'
5
5
  require 'virtual/controls/pure_virtual_method'
6
6
  require 'virtual/controls/abstract_method'
7
+ require 'virtual/controls/protocol_method'
data/lib/virtual/macro.rb CHANGED
@@ -1,19 +1,28 @@
1
1
  module Virtual
2
2
  module Macro
3
3
  def virtual_macro(method_name, &blk)
4
- Virtual::Method.define self, method_name, &blk
4
+ Virtual::VirtualMethod.define(self, method_name, &blk)
5
5
  end
6
6
  alias :virtual :virtual_macro
7
7
 
8
8
  def pure_macro(method_name)
9
- Virtual::PureMethod.define self, method_name
9
+ Virtual::PureMethod.define(self, method_name)
10
10
  end
11
11
  alias :pure_virtual :pure_macro
12
12
  alias :abstract :pure_macro
13
13
 
14
14
  def protocol_macro(method_name)
15
- Virtual::ProtocolMethod.define self, method_name
15
+ Virtual::ProtocolMethod.define(self, method_name)
16
16
  end
17
17
  alias :protocol :protocol_macro
18
+
19
+ def self.macro_methods
20
+ [
21
+ 'virtual',
22
+ 'pure_virtual',
23
+ 'abstract',
24
+ 'protocol'
25
+ ]
26
+ end
18
27
  end
19
28
  end
@@ -1,18 +1,14 @@
1
1
  module Virtual
2
2
  module ProtocolMethod
3
- class Error < RuntimeError
4
- def initialize(message)
5
- super("Pure virtual (abstract) protocol method #{message} must be implemented")
6
- end
7
- end
3
+ Error = Class.new(RuntimeError)
8
4
 
9
5
  def self.define(target_class, method_name)
10
6
  method_defined = target_class.method_defined?(method_name, true) ||
11
7
  target_class.private_method_defined?(method_name, true)
12
8
 
13
9
  if not method_defined
14
- target_class.send :define_method, method_name do |*args|
15
- raise Error, "\"#{method_name}\" of #{self.class.name}"
10
+ target_class.send(:define_method, method_name) do |*args|
11
+ raise Error, "Pure virtual (abstract) protocol method #{method_name} of #{self.class.name} must be implemented"
16
12
  end
17
13
  end
18
14
  end
@@ -1,14 +1,14 @@
1
1
  module Virtual
2
2
  module PureMethod
3
- class Error < RuntimeError
4
- def initialize(message)
5
- super("Pure virtual (abstract) method #{message} must be implemented")
6
- end
7
- end
3
+ Error = Class.new(RuntimeError)
8
4
 
9
5
  def self.define(target_class, method_name)
10
- target_class.send :define_method, method_name do |*args|
11
- raise Error, "\"#{method_name}\" of #{self.class.name}"
6
+ if target_class.method_defined?(method_name)
7
+ raise Error, "#{target_class} already has an implementation of the #{method_name} method"
8
+ end
9
+
10
+ target_class.send(:define_method, method_name) do |*args|
11
+ raise Error, "Pure virtual (abstract) method #{method_name} of #{self.class.name} must be implemented"
12
12
  end
13
13
  end
14
14
  end
@@ -0,0 +1,16 @@
1
+ module Virtual
2
+ module VirtualMethod
3
+ Error = Class.new(RuntimeError)
4
+
5
+ def self.define(target_class, method_name, &blk)
6
+ if target_class.method_defined?(method_name)
7
+ raise Error, "#{target_class} already has an implementation of the #{method_name} method"
8
+ end
9
+
10
+ blk ||= proc do |*|
11
+ end
12
+
13
+ target_class.send(:define_method, method_name, &blk)
14
+ end
15
+ end
16
+ end
data/lib/virtual.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'virtual/method'
1
+ require 'virtual/virtual_method'
2
2
  require 'virtual/pure_method'
3
3
  require 'virtual/protocol_method'
4
4
  require 'virtual/macro'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evt-virtual
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1.2
4
+ version: 2.1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - The Eventide Project
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-06 00:00:00.000000000 Z
11
+ date: 2023-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test_bench
@@ -37,13 +37,14 @@ files:
37
37
  - lib/virtual/controls/clean.rb
38
38
  - lib/virtual/controls/extended.rb
39
39
  - lib/virtual/controls/included.rb
40
+ - lib/virtual/controls/protocol_method.rb
40
41
  - lib/virtual/controls/pure_virtual_method.rb
41
42
  - lib/virtual/controls/virtual_method.rb
42
43
  - lib/virtual/macro.rb
43
- - lib/virtual/method.rb
44
44
  - lib/virtual/protocol_method.rb
45
45
  - lib/virtual/pure_method.rb
46
46
  - lib/virtual/virtual.rb
47
+ - lib/virtual/virtual_method.rb
47
48
  homepage: https://github.com/eventide-project/virtual
48
49
  licenses:
49
50
  - MIT
@@ -1,10 +0,0 @@
1
- module Virtual
2
- module Method
3
- def self.define(target_class, method_name, &blk)
4
- blk ||= proc do |*|
5
- end
6
-
7
- target_class.send :define_method, method_name, &blk
8
- end
9
- end
10
- end