Class: YamlNormalizer::RakeTask

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/yaml_normalizer/rake_task.rb

Overview

Provides Rake task integration

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = 'yaml') {|_self| ... } ⇒ RakeTask

Create a YamlNormalizer rake task object. Use this to

Examples:

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

Parameters:

  • name (String) (defaults to: 'yaml')

    name of the Rake task

  • &block (Proc)

    optional, evaluated inside the task definition

Yields:

  • (_self)

Yield Parameters:



39
40
41
42
43
44
45
46
47
# 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

Instance Attribute Details

#filesArray<String>

The YAML files to process.

Examples:

Task files assignment

YamlNormalizer::RakeTask.new do |task|
  task.files = ['config/locale/*.yml', 'config/*.yml']
end

Returns:

  • (Array<String>)

    a list of file globing Strings



21
22
23
# File 'lib/yaml_normalizer/rake_task.rb', line 21

def files
  @files
end

#nameString

The name of the task

Returns:

  • (String)

    name of the Rake task



13
14
15
# File 'lib/yaml_normalizer/rake_task.rb', line 13

def name
  @name
end