Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load itamae/plugin/recipe/plugin_name/default.rb. #162

Merged
merged 1 commit into from
Sep 7, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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