Sha256: 0a5bfe64e7e03ce76d58bd2d7a0dc950ec473914840f3d51c6a4cd0f7e49ff4d

Contents?: true

Size: 949 Bytes

Versions: 6

Compression:

Stored size: 949 Bytes

Contents

# -*- encoding: utf-8 -*-

require 'yaml'

# YAML extensions

module YAML

  # Specify one or more directory patterns and pass each YAML file in the matching directories to a block.
  #
  # See [Dir#glob](http://www.ruby-doc.org/core/classes/Dir.html#M002347) for pattern details.
  #
  # ==Example
  #   YAML.load_dir('/tmp/*.yaml'){|yaml_document|
  #     #...whatever you want to do with each yaml document
  #   }
  #
  # ==Example to load documents in files ending in ".yaml" and ".yml"
  #   YAML.load_dir('/tmp/*.yaml','/tmp/*.yml','){|yaml_document|
  #     #...whatever you want to do with the yaml document
  #   }
  
  def YAML.load_dir(*dirpaths)
    dirpaths=[*dirpaths.flatten]
    dirpaths.each do |dirpath|
      Dir[dirpath].each do |filename|
        File.open(filename) do |file|
          YAML.load_documents(file) do |doc|
            yield doc
          end #load
        end #file
      end #dir
    end #each
  end #def

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
webget_ruby_ramp-1.8.0 lib/webget_ruby_ramp/yaml.rb
webget_ruby_ramp-1.7.8 lib/webget_ruby_ramp/yaml.rb
webget_ruby_ramp-1.7.7 lib/webget_ruby_ramp/yaml.rb
webget_ruby_ramp-1.7.6 lib/webget_ruby_ramp/yaml.rb
webget_ruby_ramp-1.7.5 lib/webget_ruby_ramp/yaml.rb
webget_ruby_ramp-1.7.4 lib/webget_ruby_ramp/yaml.rb