Skip to content

Commit

Permalink
Merge pull request #162 from itamae-kitchen/recipe-plugin-default.rb
Browse files Browse the repository at this point in the history
Load itamae/plugin/recipe/plugin_name/default.rb.
  • Loading branch information
ryotarai committed Sep 7, 2015
2 parents 2d38f07 + e04306b commit a4e8691
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions lib/itamae/recipe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ class Recipe

class << self
def find_recipe_in_gem(recipe)
target = recipe.gsub('::', '/')
target += '.rb' if target !~ /\.rb$/
plugin_name = recipe.split('::')[0]
plugin_name, recipe_file = recipe.split('::')

gem_name = "itamae-plugin-recipe-#{plugin_name}"
begin
Expand All @@ -26,7 +24,20 @@ def find_recipe_in_gem(recipe)

return nil unless spec

File.join(spec.lib_dirs_glob, 'itamae', 'plugin', 'recipe', target)
candidate_files = []
if recipe_file
recipe_file += '.rb' unless recipe_file.end_with?('.rb')
candidate_files << "#{plugin_name}/#{recipe_file}"
else
candidate_files << "#{plugin_name}/default.rb"
candidate_files << "#{plugin_name}.rb"
end

candidate_files.map do |file|
File.join(spec.lib_dirs_glob, 'itamae', 'plugin', 'recipe', file)
end.find do |path|
File.exist?(path)
end
end
end

Expand Down

0 comments on commit a4e8691

Please sign in to comment.