class YamlNormalizer::RakeTask
Provides Rake task integration
Attributes
files[RW]
The YAML files to process. @example Task files assignment
YamlNormalizer::RakeTask.new do |task| task.files = ['config/locale/*.yml', 'config/*.yml'] end
@return [Array<String>] a list of file globing Strings
name[RW]
The name of the task @return [String] name of the Rake task
Public Class Methods
new(name = 'yaml') { |self| ... }
click to toggle source
Create a YamlNormalizer
rake task object. Use this to @example
In your Rakefile, add: YamlNormalizer::RakeTask.new To be more specific, configure YAML Normalizer's mode and files like so: YamlNormalizer::RakeTask.new do |config| config.files = Dir[File.join(File.dirname(__FILE__), 'include.yml')] end This gives you the following tasks (run rake -T) rake yaml:check # Check if given YAML are normalized rake yaml:normalize # Normalize given YAML files
@param name [String] name of the Rake task @param &block [Proc] optional, evaluated inside the task definition
# File lib/yaml_normalizer/rake_task.rb, line 39 def initialize(name = 'yaml', &block) yield(self) if block desc 'Check if configured YAML files are normalized' task("#{name}:check") { abort(check_failed(name)) unless check } desc 'Normalize configured YAML files' task("#{name}:normalize") { normalize } end
Private Instance Methods
check()
click to toggle source
Checks if configured YAML are normalized
# File lib/yaml_normalizer/rake_task.rb, line 58 def check Services::Check.call(*files) end
check_failed(name)
click to toggle source
Error message to be printed if check fails
# File lib/yaml_normalizer/rake_task.rb, line 52 def check_failed(name) "#{name}:check failed.\n" \ "Run 'rake #{name}:normalize' to normalize YAML files.\n" end
normalize()
click to toggle source
Normalizes configured YAML files
# File lib/yaml_normalizer/rake_task.rb, line 63 def normalize Services::Normalize.call(*files) end