module RSpecApib::Transcluder

Constants

REGEX

Public Class Methods

each_line(file) { |line| ... } click to toggle source
# File lib/rspec_apib/transcluder.rb, line 4
def self.each_line(file, &block)
  File.readlines(file, encoding: "UTF-8").each do |line|
    if needs_transclude?(line)
      transclude(file, line, &block)
    else
      yield line
    end
  end
end
needs_transclude?(line) click to toggle source
# File lib/rspec_apib/transcluder.rb, line 14
def self.needs_transclude?(line)
  line =~ REGEX
end
transclude(file, line) { |line| ... } click to toggle source
# File lib/rspec_apib/transcluder.rb, line 18
def self.transclude(file, line, &block)
  line.gsub!(REGEX) do |_match|
    transclude_file = $1
    unless transclude_file =~ /^\//
      transclude_file = File.expand_path(transclude_file, File.dirname(file))
    end
    each_line(transclude_file, &block)
    ""
  end
  yield line
end