Sha256: c80c01b2ab9f1887bc109a794672417426c0e1877db0702c67d81e31809c462b

Contents?: true

Size: 872 Bytes

Versions: 4

Compression:

Stored size: 872 Bytes

Contents

module Indexer

  class Importer

    # Import metadata from a YAML source.
    #
    module YAMLImportation

      #
      # YAML import procedure.
      #
      def import(source)
        if File.file?(source)
          case File.extname(source)
          when '.yaml', '.yml'
            load_yaml(source)
            true
          else
            text = read(source)
            if text =~ /\A---/
              load_yaml(source)
              true
            else
              super(source) if defined?(super)
            end
          end
        else
          super(source) if defined?(super)
        end
      end

      #
      # Import metadata from YAML file.
      #
      def load_yaml(file)
        metadata.merge!(YAML.load_file(file))
      end

    end

    # Include YAMLImportation mixin into Builder class.
    include YAMLImportation

  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
indexer-0.3.1 lib/indexer/importer/yaml.rb
indexer-0.3.0 lib/indexer/importer/yaml.rb
indexer-0.2.0 lib/indexer/importer/yaml.rb
indexer-0.1.0 lib/indexer/importer/yaml.rb