class YamlNormalizer::Services::IsYaml
IsYaml
is a Service Class that provides functionality to check if a file is a parseable non-scalar YAML file. @exmaple
is_yaml = YamlNormalizer::Services::IsYaml.new('path/to/file.yml') result = is_yaml.call
Attributes
file[R]
file is the file path String to be regarded
Public Class Methods
new(file)
click to toggle source
Create an IsYaml
service object by calling .new and passing a file path String. @param file [String] file path to be regarded
# File lib/yaml_normalizer/services/is_yaml.rb, line 21 def initialize(file) @file = file.to_s end
Public Instance Methods
call()
click to toggle source
Return true if given file is a valid YAML file
# File lib/yaml_normalizer/services/is_yaml.rb, line 26 def call file? && parseable? && !scalar? end
Private Instance Methods
file?()
click to toggle source
# File lib/yaml_normalizer/services/is_yaml.rb, line 32 def file? File.file? file end
parseable?()
click to toggle source
The current implementation does not require parseable? to return a boolean value
# File lib/yaml_normalizer/services/is_yaml.rb, line 38 def parseable? parse(read(file)) rescue Psych::SyntaxError false end
scalar?()
click to toggle source
# File lib/yaml_normalizer/services/is_yaml.rb, line 44 def scalar? Psych.load_file(file).instance_of? String end