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

[#puppethack] Adding replace attribute to file_line #494

Merged
merged 1 commit into from
Jul 30, 2015

Conversation

rmaika
Copy link
Contributor

@rmaika rmaika commented Jul 30, 2015

Adding tests and minor changes to make @WhatsARanjit's PR #451 work.

The patch adds the optional replace attribute to file_line. It defaults to true, which maintains current behavior. Setting the attribute to false will allow users to ensure that a line matching the match attribute exists without overwriting it with the contents of line if the matching lines exists

@@ -43,7 +52,7 @@ def handle_create_with_match()

File.open(resource[:path], 'w') do |fh|
lines.each do |l|
fh.puts(regex.match(l) ? resource[:line] : l)
fh.puts(match_regex.match(l) ? resource[:line] : l)
Copy link
Contributor

Choose a reason for hiding this comment

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

If match_regex returns nil... this will result in a NoMethodError

Copy link
Contributor

Choose a reason for hiding this comment

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

On second look, given this code path, you should be able to assume that match_regex is not nil.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, the handle_create_with_match function will not be used to write the line unless resource[:match] is not nil. So the creation of the regex that match_regex returns should not fail in this block.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it also isn't a new behavior with this patch. The line only changes because where the Regexp is created is moved and renamed from regex to match_regex

bmjen added a commit that referenced this pull request Jul 30, 2015
[#puppethack] Adding replace attribute to file_line
@bmjen bmjen merged commit ebf7348 into puppetlabs:master Jul 30, 2015
@bmjen bmjen mentioned this pull request Jul 30, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants