Sha256: c3e1f32783a4e85030d3711bcb8f6a2e96fa649be5b2a61e4b8288d6789163c5

Contents?: true

Size: 704 Bytes

Versions: 1

Compression:

Stored size: 704 Bytes

Contents

module Codependency
  class Parser

    def initialize( options={} )
      @options = options
      @comment = options.delete( :comment ) || '#'
      @dirname = options.delete( :dirname ) || '.'
      @extname = options.delete( :extname ) || '.rb'
    end

    ##
    # determines a file's dependencies based on the configured comment pattern.
    def parse( file )
      IO.readlines( file ).take_while do |line|
        line =~ pattern
      end.map { |line| "#{@dirname}/#{line[ pattern, 1 ]}#{@extname}" }
    end

    protected

    ##
    # the comment pattern to use.
    # TODO allow this to be more configurable
    def pattern
      @pattern ||= /^#{@comment} require (.+)$/
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
codependency-1.0.0 lib/codependency/parser.rb