braintree / runbook

A framework for gradual system automation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"Unable to retrieve source code" when using Runbook::Viewer

fwolfst opened this issue · comments

I want to create and save markdown-rendered versions of my runbook.
The runbook is defined in it/add_ldap_user.rb. Running runbook view it/it/add_ldap_user.rb works fine, but if I use md = Runbook::Viewer.new(eval(File.read book)).generate(view: :markdown) (where book is 'it/add_ldap_user.rb`) the markdown output contains "Unable to retrieve source code" instead of the relevant Ruby Code.

The project can be found here (last file in the commit is the relevant source)
ecovillage/operations@6c2dd14 .

Now, I could easily fire up the runbook view commands, but I thought there might be a bug hidden here. Alternatively it could have something to do with the load path and stuff. ./require 'it/add_ldap_user' in the file worked but didnt help.

This is a known issue with using eval to load the runbook code (it is a shortcoming of https://github.com/banister/method_source). See https://github.com/braintree/runbook#load-vs-eval for more details. Essentially, you need to do the following in order to have the ruby source show up in views:

load book
md = Runbook::Viewer.new(Runbook.books.last).generate(view: :markdown)

Damn, sorry for not rtfm.

Ah, but I remember why I didnt load and then loop over the runbooks via Runbook.books.each {...}:
I want to know the name of the original runbooks definition file name, to create a .md file with the same name (more or less).
Is there a way to access the "source" location from Runbook.books.last? Inspecting the object (p Runbook.last.inspect), I see the source location in the blocks but do not know how to programmatically access it.

I guess ecovillage/operations@2313250#diff-ccbed9de3d03765bf1528a07c80646ee is a workaround for that. Loop over the books file locations, load them and inspect the respectively last Runbook.
Thanks again.