Skip to content

Instantly share code, notes, and snippets.

Created February 9, 2016 11:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/37638fee29789d0d40ac to your computer and use it in GitHub Desktop.
Save anonymous/37638fee29789d0d40ac to your computer and use it in GitHub Desktop.
@projects_directory = "projects"
# Structure inside "projects" at the moment is:
# projects
# -> proj1
# --> folder1
# --> folder2
# -> proj2
# --> folder1
#
# Return an Array with all the projects path.
def all_projects_paths
Dir.glob("#{@projects_directory}/*").select {|f| File.directory? f}
end
# Return an Array with all projects components paths.
def all_components_path(component = "*")
all_projects_path.map do |project|
#File.join(project, component)
# Same with this instead:
Dir.glob("#{@projects_directory}/*/#{component}").select {|f| File.directory? f}
# If I use `puts` in either option, it will print correct results, but duplicated
end
end
all_components_path("folder1")
# Returns a two-dimensional array:
# [["projects/proj1/folder1", "projects/proj2/folder1"], ["projects/proj1/folder1", "projects/proj2/folder1"]]
# Instead of an uni-dimensional array:
# ["projects/proj1/folder1", "projects/proj2/folder1"]
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment