Sha256: 950a4b9b7281890c50e5ad4a06d843f03c0ada14c348b749ef32985aacf3f8a5

Contents?: true

Size: 996 Bytes

Versions: 4

Compression:

Stored size: 996 Bytes

Contents

module Indexer

  class Importer

    # Build metadata from a Ruby script.
    #
    module RubyImportation

      #
      # Ruby script import procedure.
      #
      def import(source)
        if File.file?(source)
          case File.extname(source) 
          when '.rb'  # TODO: Other ruby extensions ?
            load_ruby(source)
            true
          else
            text = read(source)
            if text !=~ /\A---/  # not YAML
              load_ruby(source)
              true
            else
              super(source) if defined?(super)
            end         
          end
        else
          super(source) if defined?(super)
        end
      end

      #
      # Load ruby file by simply evaluating it in the context
      # of the Builder instance.
      #
      def load_ruby(file)
        instance_eval(File.read(file))
      end

    end #module RubyImportation

    # Include RubyImportation mixin into Builder class.
    include RubyImportation

  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

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