Skip to content
This repository has been archived by the owner on Sep 19, 2020. It is now read-only.

Add a more robust cookbook_base_path helper to the API #520

Merged
merged 9 commits into from
Mar 21, 2017
Merged

Conversation

tas50
Copy link
Contributor

@tas50 tas50 commented Mar 16, 2017

The current methods of discovering the base path are flawed as they fail if the cookbook is within a directory named the same as a cookbook directory (templates, recipes, files, etc). This gives us an actual helper for finding the base path of a cookbook. We can migrate existing api calls and rules over to this in the future.

Signed-off-by: Tim Smith [email protected]

# get list of items in the dir and intersect with metadata array.
# until we get an interfact (we have a metadata) walk up the dir structure
until (Dir.entries(file) & %w(metadata.rb metadata.json)).any?
file = File.absolute_path(File.dirname(file.to_s))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can skip the File.absolute_path since we've run File.expand_path on its descendant

#
# @author Tim Smith - [email protected]
# @since 11.0
# @param file [String, Pathname] relative or absolute path to a file in the cookbook

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it probably works with a Pathname but we should test to be sure ;-)

Copy link

@josephholsten josephholsten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just needs tests. Which will require exciting mocking!

tas50 added 6 commits March 16, 2017 21:17
These aren’t used by core Foodcritic and will be removed in the next release. This will allow anyone using them internally to know so they can pull them into their own rules.

Signed-off-by: Tim Smith <[email protected]>
Signed-off-by: Tim Smith <[email protected]>
@tas50 tas50 force-pushed the path_helper branch 2 times, most recently from 48c53f4 to b30c2d4 Compare March 21, 2017 06:44
tas50 added 2 commits March 20, 2017 23:46
Signed-off-by: Tim Smith <[email protected]>
I can’t find a reason why we need this

Signed-off-by: Tim Smith <[email protected]>
@tas50 tas50 force-pushed the path_helper branch 3 times, most recently from 9c6b303 to 27904bb Compare March 21, 2017 06:56
@tas50 tas50 changed the title WIP: Add a more robust base path helper to the API Add a more robust base path helper to the API Mar 21, 2017
@tas50
Copy link
Contributor Author

tas50 commented Mar 21, 2017

@josephholsten Fixed specs that haven't been running for a super long time and added a test of a few different scenarios

Signed-off-by: Tim Smith <[email protected]>
@josephholsten
Copy link

¡super approval!

@tas50 tas50 merged commit 15ce095 into master Mar 21, 2017
@tas50 tas50 deleted the path_helper branch March 21, 2017 18:29
@tas50 tas50 changed the title Add a more robust base path helper to the API Add a more robust cookbook_base_path helper to the API Mar 29, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants