Class: YamlNormalizer::Services::Check

Inherits:
Base
  • Object
show all
Includes:
Helpers::Normalize, Helpers::ParamParser
Defined in:
lib/yaml_normalizer/services/check.rb

Overview

Check is a service class that provides functionality to check if giving YAML files are already standardized (normalized).

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::ParamParser

#parse_params, #print_help, #print_version

Methods included from Helpers::Normalize

#normalize_yaml

Methods inherited from Base

call

Constructor Details

#initialize(*args) ⇒ Check

Create a Check service object by calling .new and passing one or more Strings that are interpreted as file glob pattern.

Parameters:

  • *args (Array<String>)

    a list of file glob patterns



22
23
24
25
26
# File 'lib/yaml_normalizer/services/check.rb', line 22

def initialize(*args)
  parse_params(*args)
  files = args.each_with_object([]) { |a, o| o << Dir[a.to_s] }
  @files = files.flatten.sort.uniq
end

Instance Attribute Details

#filesObject (readonly)

files is a sorted array of file path Strings



17
18
19
# File 'lib/yaml_normalizer/services/check.rb', line 17

def files
  @files
end

Instance Method Details

#callObject

Normalizes all YAML files defined on instantiation.



29
30
31
32
# File 'lib/yaml_normalizer/services/check.rb', line 29

def call
  success = files.pmap { |file| process(file) }
  success.all?
end