Skip to content

Commit

Permalink
Merge pull request #5 from ByteSource-net/version_file
Browse files Browse the repository at this point in the history
Add ability to evaluate ruby code in metadata.rb
  • Loading branch information
aleksey-hariton committed Dec 2, 2015
2 parents a6eefb6 + ca09441 commit bb7452f
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions lib/yard-chef/handlers/cookbook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,20 @@ def process
#
def name
string = ""
# YARD builds an abstract syntax tree (AST) which we need to traverse
# to obtain the complete docstring
statement.parameters.first.traverse do |child|
string << child.jump(:string_content).source if child.type == :string_content
value = statement.parameters.first
if value.is_a?(YARD::Parser::Ruby::MethodCallNode)
# The content is code, so evaluate it in the correct directory
# This handles ruby code like File.read in metadata.rb
current_directory = Dir.getwd
Dir.chdir(File.expand_path(File.dirname(statement.file)))
string << eval(value.source)
Dir.chdir current_directory
else
# YARD builds an abstract syntax tree (AST) which we need to traverse
# to obtain the complete docstring
value.traverse do |child|
string << child.jump(:string_content).source if child.type == :string_content
end
end
string
end
Expand Down

0 comments on commit bb7452f

Please sign in to comment.