eavi 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/eavi/visitor.rb +22 -7
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 89417f14ff76e2a1a025877ffc8f421da4efe828
4
- data.tar.gz: f80ca41d54257abd0c2abd75943b29effce8fb2d
3
+ metadata.gz: cd59d004569dc526eda05b7ff0cfea3dab4d87aa
4
+ data.tar.gz: eea265db8b1a62cc99199d5e24da12de21804316
5
5
  SHA512:
6
- metadata.gz: 616c403446a6fae16c540b058bee183a57de7884b9b749eba4b6aaac78786e4503b5dc438e3650a5d63ee8ddf76a4c07d20d59ceecb2c4f3bd3fa9b89e798aea
7
- data.tar.gz: beb4d9dff7a5833de44466f2ad383b3774cd3a6d0b0c06bfc5ceb12dd83e423e43751f7270b2ab5b026bf8dbc5f364db55c631a06650b1c3f15e37ab1cdecb7b
6
+ metadata.gz: ef978d38107d68845f29d377f78b0ac7858513fb1d98efa2e0ef278d9c5407eef165c95ab3223c46e8831c73b754c9d33a2e3435520d414ede4d6f763f02ac65
7
+ data.tar.gz: 00f83214a0489d1c2e7b224d97b67b9ddfa91f131bf67d06ee43b83955e17481b13bb5c416d60c2ea33e843d1402a1d3c0bd8970cfb13a65df13140f62633f42
data/lib/eavi/visitor.rb CHANGED
@@ -31,6 +31,8 @@ module Eavi
31
31
 
32
32
  # Domain-Specific Language for the module/class
33
33
  module ModuleDSL
34
+ # protected
35
+
34
36
  # DSL method to add visit methods on types +types+.
35
37
  def def_visit(*types, &block)
36
38
  add_visit_method(*types, &block)
@@ -51,9 +53,12 @@ module Eavi
51
53
 
52
54
  # Add/override a visit method for the types +types+.
53
55
  def add_visit_method(*types, &block)
54
- block = block.curry(1) if block.arity.zero?
56
+ if block.arity.zero?
57
+ original_block = block
58
+ block = proc { |_| instance_exec(&original_block) }
59
+ end
55
60
  types.each do |type|
56
- specialized_add_visit_method(type, &block)
61
+ specialized_add_visit_method(type, block)
57
62
  end
58
63
  end
59
64
 
@@ -73,9 +78,7 @@ module Eavi
73
78
 
74
79
  # Return a list of the visit method.
75
80
  def visit_methods
76
- return methods.select do |method|
77
- VisitMethodHelper.match(method)
78
- end
81
+ specialized_visit_methods
79
82
  end
80
83
 
81
84
  # Return a list of the types with a visit method.
@@ -94,7 +97,7 @@ module Eavi
94
97
  define_method(visit_method_alias, instance_method(:visit))
95
98
  end
96
99
 
97
- def specialized_add_visit_method(type, &block)
100
+ def specialized_add_visit_method(type, block)
98
101
  define_method(VisitMethodHelper.gen_name(type), block)
99
102
  end
100
103
 
@@ -105,6 +108,12 @@ module Eavi
105
108
  def specialized_remove_method(visit_method)
106
109
  remove_method(visit_method)
107
110
  end
111
+
112
+ def specialized_visit_methods
113
+ return instance_methods.select do |method|
114
+ VisitMethodHelper.match(method)
115
+ end
116
+ end
108
117
  end
109
118
 
110
119
  # Extends only when extended
@@ -115,7 +124,7 @@ module Eavi
115
124
  define_singleton_method(visit_method_alias, method(:visit))
116
125
  end
117
126
 
118
- def specialized_add_visit_method(type, &block)
127
+ def specialized_add_visit_method(type, block)
119
128
  define_singleton_method(VisitMethodHelper.gen_name(type), block)
120
129
  end
121
130
 
@@ -126,6 +135,12 @@ module Eavi
126
135
  def specialized_remove_method(visit_method)
127
136
  singleton_class.send(:remove_method, visit_method)
128
137
  end
138
+
139
+ def specialized_visit_methods
140
+ return methods.select do |method|
141
+ VisitMethodHelper.match(method)
142
+ end
143
+ end
129
144
  end
130
145
  end
131
146
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eavi
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
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: 2017-02-11 00:00:00.000000000 Z
11
+ date: 2017-03-05 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Make the visitor pattern accessible and flexible in Ruby.
14
14
  email: pierre@legall.im