risitor 1.0.1 → 1.1.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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/risitor/visitor.rb +30 -30
  3. data/lib/risitor.rb +1 -1
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f83e529945dc5da5ac952f4e85b6eb454f4b0e2c
4
- data.tar.gz: e2cba098ab838db018aeef47091e8d16bd5bb2e5
3
+ metadata.gz: 70d52045e6c628add8c42a72446ada650c0250f8
4
+ data.tar.gz: 39df16889e7ab8c555367b71bb97a970bf255641
5
5
  SHA512:
6
- metadata.gz: 48653f25fe5a6c89dd95c86ee16198be29c69edfa0a5b160ad3b10833f97517ba7f86ab0e1abb287f2807f02c622ad4ca3afe6aa1ef3ef966e42c336101950f0
7
- data.tar.gz: 97a61929cba44373c0ee32e6c7acd490ad5fc9c19e3343c44524d1e079494d2ee4c9c74640fd4e38763c24e68303c0a23d8ad69528833288a6906a68239652e4
6
+ metadata.gz: 8c890215f979700b1353c17f68ef1fa40fb8deecffbb588c1ed8427a751ce3b239a8c9d3a19494ec50ef3730ea99ee1e05451201d2e197b4946e7c02a3158caf
7
+ data.tar.gz: 865d8d94ccf2575f89d2f7a84a1d61d4bf2f555ac5a799ab882f71f059e06854e658e243268fc68048e578a1e7433be17a777b31840fbee2091f7ee3832f85c5
@@ -1,5 +1,5 @@
1
- require_relative './no_visit_method_error'
2
- require_relative './visit_method_helper'
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
- # List of the methods extended by a Visitor
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
- define_new_visit_method(visit_method_alias)
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
- define_visit_method_for type, &block
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
- undefine_visit_method_for type
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
- undefine_visit_method visit_method
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 define_new_visit_method(new_visit_method)
70
- define_method new_visit_method, instance_method(:visit)
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 define_visit_method_for(klass, &block)
85
+ def specialized_add_visit_method(klass, &block)
74
86
  define_method VisitMethodHelper.gen_name(klass), block
75
87
  end
76
88
 
77
- def undefine_visit_method_for(klass)
89
+ def specialized_remove_visit_method(klass)
78
90
  remove_method VisitMethodHelper.gen_name(klass)
79
91
  end
80
92
 
81
- def undefine_visit_method(visit_method)
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 define_new_visit_method(new_visit_method)
91
- define_singleton_method new_visit_method, method(:visit)
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 define_visit_method_for(klass, &block)
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 undefine_visit_method_for(klass)
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 undefine_visit_method(visit_method)
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
@@ -2,4 +2,4 @@
2
2
  module Risitor
3
3
  end
4
4
 
5
- require_relative './risitor/visitor'
5
+ require_relative 'risitor/visitor'
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.1
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-08 00:00:00.000000000 Z
11
+ date: 2016-09-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Make the visitor pattern accessible and flexible inside Ruby.
13
+ description: Make the visitor pattern accessible and flexible in Ruby.
14
14
  email: pierre@legall.im
15
15
  executables: []
16
16
  extensions: []