risitor 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/risitor/visitor.rb +30 -30
- data/lib/risitor.rb +1 -1
- 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: 70d52045e6c628add8c42a72446ada650c0250f8
|
4
|
+
data.tar.gz: 39df16889e7ab8c555367b71bb97a970bf255641
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c890215f979700b1353c17f68ef1fa40fb8deecffbb588c1ed8427a751ce3b239a8c9d3a19494ec50ef3730ea99ee1e05451201d2e197b4946e7c02a3158caf
|
7
|
+
data.tar.gz: 865d8d94ccf2575f89d2f7a84a1d61d4bf2f555ac5a799ab882f71f059e06854e658e243268fc68048e578a1e7433be17a777b31840fbee2091f7ee3832f85c5
|
data/lib/risitor/visitor.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require_relative '
|
2
|
-
require_relative '
|
1
|
+
require_relative 'visit_method_helper'
|
2
|
+
require_relative 'no_visit_method_error'
|
3
3
|
|
4
4
|
module Risitor
|
5
5
|
# The Visitor module can extend a module or include a class
|
@@ -16,32 +16,44 @@ module Risitor
|
|
16
16
|
raise NoVisitMethodError.new(self, object, as)
|
17
17
|
end
|
18
18
|
|
19
|
-
|
19
|
+
class << self
|
20
|
+
def included(visitor)
|
21
|
+
visitor.extend ClassMethods
|
22
|
+
visitor.extend ClassMethodsWhenIncluded
|
23
|
+
end
|
24
|
+
|
25
|
+
def extended(visitor)
|
26
|
+
visitor.extend ClassMethods
|
27
|
+
visitor.extend ClassMethodsWhenExtended
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# List of the methods extended by a Visitor.
|
20
32
|
module ClassMethods
|
21
|
-
# Alias the `visit` method
|
33
|
+
# Alias the `visit` method.
|
22
34
|
def alias_visit_method(visit_method_alias)
|
23
|
-
|
35
|
+
specialized_alias_visit_method(visit_method_alias)
|
24
36
|
end
|
25
37
|
|
26
38
|
# Add/override a visit method for the types +types+.
|
27
39
|
def add_visit_method(*types, &block)
|
28
40
|
block = block.curry(1) if block.arity == 0
|
29
41
|
types.each do |type|
|
30
|
-
|
42
|
+
specialized_add_visit_method(type, &block)
|
31
43
|
end
|
32
44
|
end
|
33
45
|
|
34
46
|
# Remove the visit methods for the types +types+.
|
35
47
|
def remove_visit_method(*types)
|
36
48
|
types.each do |type|
|
37
|
-
|
49
|
+
specialized_remove_visit_method(type)
|
38
50
|
end
|
39
51
|
end
|
40
52
|
|
41
53
|
# Remove all the visit methods.
|
42
54
|
def reset_visit_methods
|
43
55
|
visit_methods.each do |visit_method|
|
44
|
-
|
56
|
+
specialized_remove_method(visit_method)
|
45
57
|
end
|
46
58
|
end
|
47
59
|
|
@@ -66,19 +78,19 @@ module Risitor
|
|
66
78
|
module ClassMethodsWhenIncluded
|
67
79
|
private
|
68
80
|
|
69
|
-
def
|
70
|
-
define_method
|
81
|
+
def specialized_alias_visit_method(visit_method_alias)
|
82
|
+
define_method visit_method_alias, instance_method(:visit)
|
71
83
|
end
|
72
84
|
|
73
|
-
def
|
85
|
+
def specialized_add_visit_method(klass, &block)
|
74
86
|
define_method VisitMethodHelper.gen_name(klass), block
|
75
87
|
end
|
76
88
|
|
77
|
-
def
|
89
|
+
def specialized_remove_visit_method(klass)
|
78
90
|
remove_method VisitMethodHelper.gen_name(klass)
|
79
91
|
end
|
80
92
|
|
81
|
-
def
|
93
|
+
def specialized_remove_method(visit_method)
|
82
94
|
remove_method visit_method
|
83
95
|
end
|
84
96
|
end
|
@@ -87,34 +99,22 @@ module Risitor
|
|
87
99
|
module ClassMethodsWhenExtended
|
88
100
|
private
|
89
101
|
|
90
|
-
def
|
91
|
-
define_singleton_method
|
102
|
+
def specialized_alias_visit_method(visit_method_alias)
|
103
|
+
define_singleton_method visit_method_alias, method(:visit)
|
92
104
|
end
|
93
105
|
|
94
|
-
def
|
106
|
+
def specialized_add_visit_method(klass, &block)
|
95
107
|
define_singleton_method VisitMethodHelper.gen_name(klass), block
|
96
108
|
end
|
97
109
|
|
98
|
-
def
|
110
|
+
def specialized_remove_visit_method(klass)
|
99
111
|
self.singleton_class.send :remove_method, VisitMethodHelper.gen_name(klass)
|
100
112
|
end
|
101
113
|
|
102
|
-
def
|
114
|
+
def specialized_remove_method(visit_method)
|
103
115
|
self.singleton_class.send :remove_method, visit_method
|
104
116
|
end
|
105
117
|
end
|
106
|
-
|
107
|
-
class << self
|
108
|
-
def included(visitor)
|
109
|
-
visitor.extend ClassMethods
|
110
|
-
visitor.extend ClassMethodsWhenIncluded
|
111
|
-
end
|
112
|
-
|
113
|
-
def extended(visitor)
|
114
|
-
visitor.extend ClassMethods
|
115
|
-
visitor.extend ClassMethodsWhenExtended
|
116
|
-
end
|
117
|
-
end
|
118
118
|
end
|
119
119
|
|
120
120
|
Base = Visitor
|
data/lib/risitor.rb
CHANGED
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: risitor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
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: 2016-09-
|
11
|
+
date: 2016-09-19 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: Make the visitor pattern accessible and flexible
|
13
|
+
description: Make the visitor pattern accessible and flexible in Ruby.
|
14
14
|
email: pierre@legall.im
|
15
15
|
executables: []
|
16
16
|
extensions: []
|