evt-template_method 2.0.0.0 → 2.1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7df86eec2be2b5378f682b6c8b32b5f80c41d20b28ce0f99559e5c584d047b68
4
- data.tar.gz: bdc177a975ef3948d23d1593247066c3e5bcaefbc52ab482333ffa62b77e9e65
3
+ metadata.gz: db75f4fd8781df4281c127d328cedd7a880a864fb90ccf63a54c75381f826ff9
4
+ data.tar.gz: 142d04dfdb9132755df14728cdd2bcb404af679ca084421331409516cdcecc9f
5
5
  SHA512:
6
- metadata.gz: 3f29692f4c50d16bcbaeb1d717ad40a578be5506281d99e462efc3902e52482ae6fa2230022778288b803a0d92da8ae2d07363c49680af7cf94705f4b0b34070
7
- data.tar.gz: 9cdee8a69ff9a491c3de205413911fd0803670dd5018177fda206fc479bc487e891eca785cf9f04ad70a30e65230842403e5824f08e9b7d3df40ca8776cad8df
6
+ metadata.gz: 5ae9b6a20a68658cd36e82aefe2ae1101c931acef52fc33a0298e0b5b5f0a8eee95b0b4c10df54f72df45a87bb8803caec8a19e8a9b7120664d7b4e445cfbeef
7
+ data.tar.gz: '09066d162ea998a369f922045c10a5cd9be4e013b6e283dfa3df12be62228280902e20cc086454d102266c9aecf93435c49cb07a3ad5237fafaf882441f66fbf'
@@ -1,9 +1,6 @@
1
1
  module TemplateMethod
2
2
  def self.activate(target_class=nil)
3
3
  target_class ||= Object
4
-
5
- return if target_class.ancestors.include?(TemplateMethod::Macro)
6
-
7
4
  target_class.extend(TemplateMethod::Macro)
8
5
  end
9
6
 
@@ -22,10 +19,11 @@ module TemplateMethod
22
19
  end
23
20
 
24
21
  def self.subject_class(subject)
25
- if [Module, Class].include?(subject)
26
- return subject
22
+ case subject
23
+ when Module, Class
24
+ subject
27
25
  else
28
- return subject.class
26
+ subject.class
29
27
  end
30
28
  end
31
29
  end
@@ -0,0 +1,18 @@
1
+ module TemplateMethod
2
+ module Controls
3
+ module TemplateMethod
4
+ module Body
5
+ def self.example
6
+ Example.new
7
+ end
8
+
9
+ class Example
10
+ include ::TemplateMethod
11
+ template_method :some_method do |*|
12
+ :something
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,84 @@
1
+ module TemplateMethod
2
+ module Controls
3
+ module TemplateMethod
4
+ module Implemented
5
+ def self.example
6
+ Example.new
7
+ end
8
+
9
+ class Example
10
+ include ::TemplateMethod
11
+ template_method :some_method
12
+
13
+ def some_method
14
+ 'some value'
15
+ end
16
+ end
17
+
18
+ module Prior
19
+ def self.example
20
+ Example.new
21
+ end
22
+
23
+ class Example
24
+ def some_method
25
+ 'some value'
26
+ end
27
+
28
+ include ::TemplateMethod
29
+ template_method :some_method
30
+ end
31
+ end
32
+
33
+ module Module
34
+ def self.example
35
+ Example.new
36
+ end
37
+
38
+ class Example
39
+ include ::TemplateMethod
40
+ template_method :some_method
41
+
42
+ module SomeModule
43
+ def some_method
44
+ 'some value'
45
+ end
46
+ end
47
+ include SomeModule
48
+ end
49
+ end
50
+
51
+ module PrependedModule
52
+ def self.example
53
+ Example.new
54
+ end
55
+
56
+ class Example
57
+ module PrependedModule
58
+ def self.included(cls)
59
+ cls.class_exec do
60
+ include ::TemplateMethod
61
+
62
+ prepend SomeMethod
63
+
64
+ template_method :some_method do
65
+ 'some value'
66
+ end
67
+ end
68
+ end
69
+
70
+ module SomeMethod
71
+ def some_method
72
+ return super
73
+ rescue NoMethodError
74
+ return nil
75
+ end
76
+ end
77
+ end
78
+ include PrependedModule
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,31 @@
1
+ module TemplateMethod
2
+ module Controls
3
+ module TemplateMethod
4
+ module Variant
5
+ def self.example
6
+ Example.new
7
+ end
8
+
9
+ class Example
10
+ include ::TemplateMethod
11
+ template_method! :some_method
12
+ end
13
+
14
+ module Implemented
15
+ def self.example
16
+ Example.new
17
+ end
18
+
19
+ class Example
20
+ include ::TemplateMethod
21
+ template_method! :some_method
22
+
23
+ def some_method
24
+ 'some value'
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -9,93 +9,6 @@ module TemplateMethod
9
9
  include ::TemplateMethod
10
10
  template_method :some_method
11
11
  end
12
-
13
- module Body
14
- def self.example
15
- Example.new
16
- end
17
-
18
- class Example
19
- include ::TemplateMethod
20
- template_method :some_method do |*|
21
- :something
22
- end
23
- end
24
- end
25
-
26
- module Implemented
27
- def self.example
28
- Example.new
29
- end
30
-
31
- class Example
32
- include ::TemplateMethod
33
- template_method :some_method
34
-
35
- def some_method
36
- "some concrete result"
37
- end
38
- end
39
-
40
- module AlreadyImplemented
41
- def self.example
42
- Example.new
43
- end
44
-
45
- class Example
46
- def some_method
47
- "some concrete result"
48
- end
49
-
50
- include ::TemplateMethod
51
- template_method :some_method
52
- end
53
- end
54
-
55
- module Module
56
- def self.example
57
- Example.new
58
- end
59
-
60
- class Example
61
- include ::TemplateMethod
62
- template_method :some_method
63
-
64
- module SomeModule
65
- def some_method
66
- "some module concrete result"
67
- end
68
- end
69
- include SomeModule
70
- end
71
- end
72
- end
73
-
74
- module Variant
75
- def self.example
76
- Example.new
77
- end
78
-
79
- class Example
80
- include ::TemplateMethod
81
- template_method! :some_method
82
-
83
- def some_method
84
- 'some concrete result'
85
- end
86
- end
87
-
88
- module NotImplemented
89
- def self.example
90
- Example.new
91
- end
92
-
93
- class Example
94
- include ::TemplateMethod
95
- template_method! :some_method
96
- end
97
- end
98
- end
99
12
  end
100
13
  end
101
14
  end
@@ -1,4 +1,8 @@
1
1
  require 'template_method/controls/template_method'
2
+ require 'template_method/controls/template_method/body'
3
+ require 'template_method/controls/template_method/implemented'
4
+ require 'template_method/controls/template_method/variant'
5
+
2
6
  require 'template_method/controls/clean'
3
7
  require 'template_method/controls/extended'
4
8
  require 'template_method/controls/included'
@@ -13,8 +13,15 @@ module TemplateMethod
13
13
  def template_method_macro(method_name, &implementation)
14
14
  implementation ||= proc { |*| nil }
15
15
 
16
- inherit = true
17
- concrete_implementation_exists = method_defined?(method_name, inherit)
16
+ ancestors_without_prepended_modules = ancestors.drop_while do |ancestor|
17
+ ancestor != self
18
+ end
19
+
20
+ concrete_implementation_exists = ancestors_without_prepended_modules.any? do |ancestor|
21
+ ancestor.method_defined?(method_name, false) ||
22
+ ancestor.private_method_defined?(method_name, false)
23
+ end
24
+
18
25
  if concrete_implementation_exists
19
26
  return
20
27
  end
@@ -24,7 +31,7 @@ module TemplateMethod
24
31
  alias :template_method :template_method_macro
25
32
 
26
33
  def template_method_variant_macro(method_name)
27
- template_method_macro(method_name) do
34
+ template_method_macro(method_name) do |*|
28
35
  raise TemplateMethod::Error, "Implementation is required (Method name: #{method_name})"
29
36
  end
30
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evt-template_method
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.0
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: 2024-03-14 00:00:00.000000000 Z
11
+ date: 2024-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test_bench
@@ -37,6 +37,9 @@ files:
37
37
  - lib/template_method/controls/extended.rb
38
38
  - lib/template_method/controls/included.rb
39
39
  - lib/template_method/controls/template_method.rb
40
+ - lib/template_method/controls/template_method/body.rb
41
+ - lib/template_method/controls/template_method/implemented.rb
42
+ - lib/template_method/controls/template_method/variant.rb
40
43
  - lib/template_method/error.rb
41
44
  - lib/template_method/macro.rb
42
45
  - lib/template_method/template_method.rb
@@ -59,7 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
62
  - !ruby/object:Gem::Version
60
63
  version: '0'
61
64
  requirements: []
62
- rubygems_version: 3.5.6
65
+ rubygems_version: 3.4.10
63
66
  signing_key:
64
67
  specification_version: 4
65
68
  summary: Template method declaration