forked from faker-ruby/faker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update yaml format in docs (faker-ruby#1496)
- Loading branch information
Showing
5 changed files
with
98 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'yaml' | ||
|
||
desc 'Reformat a yaml file into a common format' | ||
task :reformat_yaml, [:filename] do |_, args| | ||
args.with_defaults(filename: nil) | ||
|
||
if args[:filename].nil? | ||
raise ArgumentError, 'A filename is required. `bundle exec rake reformat_yaml["lib/path/to/fil"]`' | ||
end | ||
|
||
root_dir = File.absolute_path(File.join(__dir__, '..')) | ||
target_file = File.join(root_dir, args[:filename]) | ||
reformat_file(target_file) | ||
end | ||
|
||
def reformat_file(filename) | ||
puts "reformatting #{filename}" | ||
|
||
input = YAML.load_file(filename) | ||
output = input.to_yaml | ||
|
||
output.sub!(/^---\n/, '') # remove header | ||
|
||
File.write(filename, output) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters