evt-template_method 2.0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/template_method/activate.rb +31 -0
- data/lib/template_method/controls/clean.rb +12 -0
- data/lib/template_method/controls/extended.rb +14 -0
- data/lib/template_method/controls/included.rb +13 -0
- data/lib/template_method/controls/template_method.rb +101 -0
- data/lib/template_method/controls.rb +4 -0
- data/lib/template_method/error.rb +3 -0
- data/lib/template_method/macro.rb +40 -0
- data/lib/template_method/template_method.rb +9 -0
- data/lib/template_method.rb +4 -0
- metadata +66 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7df86eec2be2b5378f682b6c8b32b5f80c41d20b28ce0f99559e5c584d047b68
|
4
|
+
data.tar.gz: bdc177a975ef3948d23d1593247066c3e5bcaefbc52ab482333ffa62b77e9e65
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3f29692f4c50d16bcbaeb1d717ad40a578be5506281d99e462efc3902e52482ae6fa2230022778288b803a0d92da8ae2d07363c49680af7cf94705f4b0b34070
|
7
|
+
data.tar.gz: 9cdee8a69ff9a491c3de205413911fd0803670dd5018177fda206fc479bc487e891eca785cf9f04ad70a30e65230842403e5824f08e9b7d3df40ca8776cad8df
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module TemplateMethod
|
2
|
+
def self.activate(target_class=nil)
|
3
|
+
target_class ||= Object
|
4
|
+
|
5
|
+
return if target_class.ancestors.include?(TemplateMethod::Macro)
|
6
|
+
|
7
|
+
target_class.extend(TemplateMethod::Macro)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.activated?(target_class=nil)
|
11
|
+
target_class ||= Object
|
12
|
+
|
13
|
+
subject = subject_class(target_class)
|
14
|
+
|
15
|
+
Macro.macro_methods.each do |mthd|
|
16
|
+
if not subject.respond_to?(mthd)
|
17
|
+
return false
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
true
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.subject_class(subject)
|
25
|
+
if [Module, Class].include?(subject)
|
26
|
+
return subject
|
27
|
+
else
|
28
|
+
return subject.class
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
module TemplateMethod
|
2
|
+
module Controls
|
3
|
+
module TemplateMethod
|
4
|
+
def self.example
|
5
|
+
Example.new
|
6
|
+
end
|
7
|
+
|
8
|
+
class Example
|
9
|
+
include ::TemplateMethod
|
10
|
+
template_method :some_method
|
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
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module TemplateMethod
|
2
|
+
module Macro
|
3
|
+
def template_method_module
|
4
|
+
@template_method_module ||= include_template_method_module
|
5
|
+
end
|
6
|
+
|
7
|
+
def include_template_method_module
|
8
|
+
mod = Module.new
|
9
|
+
include mod
|
10
|
+
mod
|
11
|
+
end
|
12
|
+
|
13
|
+
def template_method_macro(method_name, &implementation)
|
14
|
+
implementation ||= proc { |*| nil }
|
15
|
+
|
16
|
+
inherit = true
|
17
|
+
concrete_implementation_exists = method_defined?(method_name, inherit)
|
18
|
+
if concrete_implementation_exists
|
19
|
+
return
|
20
|
+
end
|
21
|
+
|
22
|
+
template_method_module.define_method(method_name, &implementation)
|
23
|
+
end
|
24
|
+
alias :template_method :template_method_macro
|
25
|
+
|
26
|
+
def template_method_variant_macro(method_name)
|
27
|
+
template_method_macro(method_name) do
|
28
|
+
raise TemplateMethod::Error, "Implementation is required (Method name: #{method_name})"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
alias :template_method! :template_method_variant_macro
|
32
|
+
|
33
|
+
def self.macro_methods
|
34
|
+
[
|
35
|
+
'template_method',
|
36
|
+
'template_method!'
|
37
|
+
]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: evt-template_method
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- The Eventide Project
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-03-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: test_bench
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: " "
|
28
|
+
email: opensource@eventide-project.org
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/template_method.rb
|
34
|
+
- lib/template_method/activate.rb
|
35
|
+
- lib/template_method/controls.rb
|
36
|
+
- lib/template_method/controls/clean.rb
|
37
|
+
- lib/template_method/controls/extended.rb
|
38
|
+
- lib/template_method/controls/included.rb
|
39
|
+
- lib/template_method/controls/template_method.rb
|
40
|
+
- lib/template_method/error.rb
|
41
|
+
- lib/template_method/macro.rb
|
42
|
+
- lib/template_method/template_method.rb
|
43
|
+
homepage: https://github.com/eventide-project/template-method
|
44
|
+
licenses:
|
45
|
+
- MIT
|
46
|
+
metadata: {}
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 2.7.0
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
requirements: []
|
62
|
+
rubygems_version: 3.5.6
|
63
|
+
signing_key:
|
64
|
+
specification_version: 4
|
65
|
+
summary: Template method declaration
|
66
|
+
test_files: []
|