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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cd59d004569dc526eda05b7ff0cfea3dab4d87aa
4
- data.tar.gz: eea265db8b1a62cc99199d5e24da12de21804316
3
+ metadata.gz: 6f6de9f9fc58a77b27a53a52795a010bf91f032e
4
+ data.tar.gz: b8944f725219774d13bf092f1dc01244fc8db3cb
5
5
  SHA512:
6
- metadata.gz: ef978d38107d68845f29d377f78b0ac7858513fb1d98efa2e0ef278d9c5407eef165c95ab3223c46e8831c73b754c9d33a2e3435520d414ede4d6f763f02ac65
7
- data.tar.gz: 00f83214a0489d1c2e7b224d97b67b9ddfa91f131bf67d06ee43b83955e17481b13bb5c416d60c2ea33e843d1402a1d3c0bd8970cfb13a65df13140f62633f42
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
- # Return a visit method name for the type +type+.
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
- # Return true if the +visit_method_name+ is a well formed
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
- # Return the type matching a visit method.
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)
@@ -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(ModuleDSL)
21
- visitor.extend(ModuleMethods)
22
- visitor.extend(ModuleMethodsWhenIncluded)
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(ModuleDSL)
27
- visitor.extend(ModuleMethods)
28
- visitor.extend(ModuleMethodsWhenExtended)
31
+ visitor.extend(DSL)
32
+ visitor.extend(MethodsWhenIncludedAndExtended)
33
+ visitor.extend(MethodsWhenExtended)
29
34
  end
30
35
  end
31
36
 
32
- # Domain-Specific Language for the module/class
33
- module ModuleDSL
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 ModuleMethods
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
- # Return a list of the visit method.
87
+ # Returns a list of the visit method.
80
88
  def visit_methods
81
89
  specialized_visit_methods
82
90
  end
83
91
 
84
- # Return a list of the types with a visit method.
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 ModuleMethodsWhenIncluded
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 ModuleMethodsWhenExtended
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.1
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: 2017-03-05 00:00:00.000000000 Z
11
+ date: 2018-01-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Make the visitor pattern accessible and flexible in Ruby.
13
+ description: Make the visitor pattern very accessible in Ruby.
14
14
  email: pierre@legall.im
15
15
  executables: []
16
16
  extensions: []