Class File
In: lib/facets/standard/facets/yaml.rb
Parent: Object

Methods

yaml?  

Public Class methods

File.yaml? provides a way to check if a file is a YAML formatted file:

  File.yaml?('project.yaml')  #=> true
  File.yaml?('project.xml')   #=> false

Note this isn‘t perfect. At present it depends on the use use of an initial document separator (eg. ’—’). With YAML 1.1 the %YAML delaration is supposed to be manditory, so in the future this can be adapted to fit that standard.

[Source]

# File lib/facets/standard/facets/yaml.rb, line 39
  def self.yaml?(file)
    File.open(file) do |f|
      until f.eof?
        line = f.gets
        break true if line =~ /^---/
        break false unless line =~ /^(\s*#.*?|\s*)$/
      end
    end
  end

[Validate]