Skip to content

Commit

Permalink
Add aliasing of the def_visit and undef_visit DSL methods
Browse files Browse the repository at this point in the history
  • Loading branch information
pierrelegall committed Jan 15, 2021
1 parent 17f832c commit c95b974
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ module Jsonifier

alias_visit_method :serialize

def_serialize String do |object|
'"' + object.to_s + '"'
end

# […]
end

Expand Down
4 changes: 4 additions & 0 deletions lib/eavi/visitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ module MethodsWhenIncluded

def specialized_alias_visit_method(visit_method_alias)
define_method(visit_method_alias, instance_method(:visit))
define_singleton_method(('def_' + visit_method_alias.to_s).to_sym, method(:def_visit))
define_singleton_method(('undef_' + visit_method_alias.to_s).to_sym, method(:undef_visit))
end

def specialized_add_visit_method(type, block)
Expand Down Expand Up @@ -130,6 +132,8 @@ module MethodsWhenExtended

def specialized_alias_visit_method(visit_method_alias)
define_singleton_method(visit_method_alias, method(:visit))
define_singleton_method(('def_' + visit_method_alias.to_s).to_sym, method(:def_visit))
define_singleton_method(('undef_' + visit_method_alias.to_s).to_sym, method(:undef_visit))
end

def specialized_add_visit_method(type, block)
Expand Down
12 changes: 4 additions & 8 deletions test/visitor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,11 @@
it do
Reader.class_eval do
alias_visit_method :read

def_visit Page do
# [...]
end
end

assert_respond_to @reader, :read
assert_respond_to Reader, :def_read
assert_respond_to Reader, :undef_read
end
end

Expand Down Expand Up @@ -350,13 +348,11 @@
it do
Printer.class_eval do
alias_visit_method :print

def_visit Page do
# [...]
end
end

assert_respond_to Printer, :print
assert_respond_to Printer, :def_print
assert_respond_to Printer, :undef_print
end
end

Expand Down

0 comments on commit c95b974

Please sign in to comment.