I’m trying not to repeat myself in all my different batch connect apps. So I created /var/www/ood/apps/common/attributes.yml
and I import that file into all the form.yml
:
attributes:
<%= File.read('/var/www/ood/apps/common/attributes.yml') %>
This works well.
I have logic in submit.yml
that checks if a field is blank and changes that field to a default value. So I created /var/www/ood/apps/common/form_default_values.rb
:
def default(x, default_value)
return x.blank? ? default_value : x
end
partition = default(_partition, "cpu-preempt")
cpus_per_task = default(cpus_per_task, 2)
time_limit = default(time_limit, "1:00:00")
mem = "#{default(mem_gigs, 8)}GB"
gpus = default(gpus, 0)
What I thought should work but didn’t was this:
---
batch_connect:
<%
eval(File.read('/var/www/ood/apps/common/form_default_values.rb'))
%>
script:
native:
- --partition=<%=partition%>
- --cpus-per-task=<%=cpus_per_task%>
- --time=<%=time_limit%>
- --mem=<%=mem%>
- --gpus=<%=gpus%>
All those variables which are defined in form_default_values.rb
come out as empty strings. I assume that they’re undefined and that <%=undefined%> just comes out as nothing.
What does work for some reason is this:
---
batch_connect:
<%
eval(File.read('/var/www/ood/apps/common/form_default_values.rb'))
partition=partition
cpus_per_task=cpus_per_task
time_limit=time_limit
mem=mem
gpus=gpus
%>
script:
native:
- --partition=<%=partition%>
- --cpus-per-task=<%=cpus_per_task%>
- --time=<%=time_limit%>
- --mem=<%=mem%>
- --gpus=<%=gpus%>
By adding the pointless instruction foobar=foobar
, I can now reference foobar
a few lines later. Am I crazy? Can anyone else reproduce this?