# root of my dato_config.rb
def my_helper_method
puts "Awesome"
end
directory 'src/posts' do
I18n.available_locales.each do |locale|
I18n.with_locale(locale) do
# This will fail
my_helper_method
# NameError: undefined local variable or method `my_helper_method' for #<Dato::Dump::Dsl::Directory:0x007fa5cf5c2b60>
end
end
end
In the same article recommends doing something like this:
class Directory
def initialize(&block)
@self_before_instance_eval = eval "self", block.binding
instance_eval &block
end
def method_missing(method, *args, &block)
@self_before_instance_eval.send method, *args, &block
end
end
Coverage decreased (-0.03%) to 93.47% when pulling f0d5169aaafd4d6853559a05325ceb93a9cfe2a8 on andresgutgon:fix/allow-external-methods-inside-directory-blocks into a240de18d0c39dc0bcabfc81b0f688cc53f6b64d on datocms:master.
Coverage increased (+0.008%) to 93.511% when pulling 7d5c9d714b143c1092f66348cba56dfa1861d0e9 on andresgutgon:fix/allow-external-methods-inside-directory-blocks into a240de18d0c39dc0bcabfc81b0f688cc53f6b64d on datocms:master.
What is this?
This issue is that I'm wrapping my Dato content inside a
directory
. Which is using instance_eval. I'm reading here that methods outside of instance are not accessibleHere is what I'm trying to do:
In the same article recommends doing something like this: