I'm trying to use a Gem that provides me with a DSL i need to apply on some of my classes. But using it directly makes my class definitions not as clean as i want them to be, so i want to move the code that uses the DSL somewhere else, which bring me to this problem, that i will describe in an abstract/general way:
If i have a ruby class that includes methods from another gem as private, and in the docs they tell to call those methods inside class definition.
for example:
class A
include ModuleB::PrivateMethods
end
class B < A
do_z :param do
set_property 'a', :x, :y, false
set_property 'b', :x, :y, false
set_property 'only for class B', :x, :y, true
end
def whatever
end
end
# this is from the gem
module ModuleZ
module PrivateMethods
def self.included(base)
base.extend Zmethods
end
module Zmethods
private
def do_z(param1, &block)
# this method do something and calls the block
end
end
end
end
Is there a way to DRY up those calls to do_z if, for example any class that inherit from A have to do this:
do_z :param do
set_property 'a', :x, :y, false
set_property 'b', :x, :y, false
end
and
do_z :param do
set_property 'only for class B', :x, :y, true
end
is only needed for class B and i don't want to write this calls inside the class definition but somewhere else?
Like another module that, when included make those calls even when those methods are private?
So i can write the class definition with something like this?
class B < A
include TheModuleForAllClases::AndTheOneForBclass
def whatever
end
end
I could call #do_z on the base class, and then again for each specialized class to only make the calls needed on each implementation, but they are still many and the blocks are very large, so my class definitions get really long, and the actual method implementation of the class get buried behind those calls.
if wondering, the Gem is swagger-docs look: documenting-a-controller on Rails.
Greetings!