eavi 2.0.1 → 2.0.2
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/lib/eavi/visit_method_helper.rb +3 -3
- data/lib/eavi/visitor.rb +23 -15
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f6de9f9fc58a77b27a53a52795a010bf91f032e
|
4
|
+
data.tar.gz: b8944f725219774d13bf092f1dc01244fc8db3cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0bc369b4c2d793bb7ec9fe8eb52e14f4bdc7e123bb3fc6e641fef46271b1a9ff603a9eb047f94e94d631483796fe2b3a17b43e604880a642ca7d6fad8c73990e
|
7
|
+
data.tar.gz: 7e0c0bfed62fe5a16ffcce7ef1f23bb44d8e0028241fc4674f210bda5ffe7653e0281671d91fa2ae2f41d58ba0e3a7c8b72374adada8d44940c2a7fb083aff43
|
@@ -4,18 +4,18 @@ module Eavi
|
|
4
4
|
TEMPLATE = 'visit[%s]'.freeze
|
5
5
|
REGEXP = /^visit\[(.*)\]$/
|
6
6
|
|
7
|
-
#
|
7
|
+
# Returns a visit method name for the type +type+.
|
8
8
|
def self.gen_name(type)
|
9
9
|
return TEMPLATE % type.name
|
10
10
|
end
|
11
11
|
|
12
|
-
#
|
12
|
+
# Returns true if the +visit_method_name+ is a well formed
|
13
13
|
# visit method name, else false.
|
14
14
|
def self.match(visit_method_name)
|
15
15
|
return REGEXP.match(visit_method_name)
|
16
16
|
end
|
17
17
|
|
18
|
-
#
|
18
|
+
# Returns the type matching a visit method.
|
19
19
|
def self.get_type(visit_method)
|
20
20
|
type_symbol = match(visit_method).captures[0]
|
21
21
|
return const_get(type_symbol)
|
data/lib/eavi/visitor.rb
CHANGED
@@ -6,6 +6,11 @@ module Eavi
|
|
6
6
|
# to make it a dynamic visitor (see the OOP visitor pattern).
|
7
7
|
module Visitor
|
8
8
|
# Call the visit method associated with the type of +object+.
|
9
|
+
#
|
10
|
+
# @param [Object] object The object to visit
|
11
|
+
# @param [Object] *args The arguments passed to the called visit method
|
12
|
+
# @param [Class] as: The class which the visit method is attached
|
13
|
+
# @returns The result of the called visit method
|
9
14
|
def visit(object, *args, as: object.class)
|
10
15
|
as.ancestors.each do |type|
|
11
16
|
visit_method_name = VisitMethodHelper.gen_name(type)
|
@@ -17,35 +22,38 @@ module Eavi
|
|
17
22
|
|
18
23
|
class << self
|
19
24
|
def included(visitor)
|
20
|
-
visitor.extend(
|
21
|
-
visitor.extend(
|
22
|
-
visitor.extend(
|
25
|
+
visitor.extend(DSL)
|
26
|
+
visitor.extend(MethodsWhenIncludedAndExtended)
|
27
|
+
visitor.extend(MethodsWhenIncluded)
|
23
28
|
end
|
24
29
|
|
25
30
|
def extended(visitor)
|
26
|
-
visitor.extend(
|
27
|
-
visitor.extend(
|
28
|
-
visitor.extend(
|
31
|
+
visitor.extend(DSL)
|
32
|
+
visitor.extend(MethodsWhenIncludedAndExtended)
|
33
|
+
visitor.extend(MethodsWhenExtended)
|
29
34
|
end
|
30
35
|
end
|
31
36
|
|
32
|
-
#
|
33
|
-
module
|
34
|
-
# protected
|
35
|
-
|
37
|
+
# DSL methods
|
38
|
+
module DSL
|
36
39
|
# DSL method to add visit methods on types +types+.
|
40
|
+
#
|
41
|
+
# @param [Array<Class>] *types Types attached to the new visit method
|
42
|
+
# @param [Proc] block The content of the visit method
|
37
43
|
def def_visit(*types, &block)
|
38
44
|
add_visit_method(*types, &block)
|
39
45
|
end
|
40
46
|
|
41
47
|
# DSL method to remove visit methods on types +types+.
|
48
|
+
#
|
49
|
+
# @param [Array<Class>] *types Types attached to the removed visit method
|
42
50
|
def undef_visit(*types)
|
43
51
|
remove_visit_method(*types)
|
44
52
|
end
|
45
53
|
end
|
46
54
|
|
47
55
|
# Extends if included or extended
|
48
|
-
module
|
56
|
+
module MethodsWhenIncludedAndExtended
|
49
57
|
# Alias the `visit` method.
|
50
58
|
def alias_visit_method(visit_method_alias)
|
51
59
|
specialized_alias_visit_method(visit_method_alias)
|
@@ -76,12 +84,12 @@ module Eavi
|
|
76
84
|
end
|
77
85
|
end
|
78
86
|
|
79
|
-
#
|
87
|
+
# Returns a list of the visit method.
|
80
88
|
def visit_methods
|
81
89
|
specialized_visit_methods
|
82
90
|
end
|
83
91
|
|
84
|
-
#
|
92
|
+
# Returns a list of the types with a visit method.
|
85
93
|
def visitable_types
|
86
94
|
return visit_methods.collect do |visit_method|
|
87
95
|
VisitMethodHelper.get_type(visit_method)
|
@@ -90,7 +98,7 @@ module Eavi
|
|
90
98
|
end
|
91
99
|
|
92
100
|
# Extends only when included
|
93
|
-
module
|
101
|
+
module MethodsWhenIncluded
|
94
102
|
private
|
95
103
|
|
96
104
|
def specialized_alias_visit_method(visit_method_alias)
|
@@ -117,7 +125,7 @@ module Eavi
|
|
117
125
|
end
|
118
126
|
|
119
127
|
# Extends only when extended
|
120
|
-
module
|
128
|
+
module MethodsWhenExtended
|
121
129
|
private
|
122
130
|
|
123
131
|
def specialized_alias_visit_method(visit_method_alias)
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eavi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pierre Le Gall
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-14 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: Make the visitor pattern accessible
|
13
|
+
description: Make the visitor pattern very accessible in Ruby.
|
14
14
|
email: pierre@legall.im
|
15
15
|
executables: []
|
16
16
|
extensions: []
|