class Mergit

A class for merging in `require`ments.

Constants

ATTRIBUTES

List of attributes accepted by {Mergit}, and the default values.

@return [Hash]

VERSION

The version of the Mergit Library.

Public Class Methods

new(options=nil) click to toggle source

Create a new mergit instance.

@param [Hash] options See {ATTRIBUTES} for the list of options you can pass in.

# File lib/mergit.rb, line 23
def initialize options=nil
  final_options = options ? ATTRIBUTES.merge(options) : ATTRIBUTES

  ATTRIBUTES.each_key do |attr|
    instance_variable_set("@#{attr}", final_options[attr])
  end
end

Public Instance Methods

process(string) click to toggle source

Merge a string

@param [String] string The text that should be merged. @return [String] The merged output.

# File lib/mergit.rb, line 47
def process string
  create_string_processor(string).output
end
process_file(filename) click to toggle source

Merge a file

@param [Pathname, String] filename The name of the file to merge. @return [String] The merged file.

# File lib/mergit.rb, line 35
def process_file filename
  if File.file? filename
    create_file_processor(filename).output
  else
    raise MergitError.new "No such file: #{filename}"
  end
end

Private Instance Methods

create_file_processor(filename) click to toggle source

Helper to create a file processor

@param [Pathname, String] filename The file to process @return [Processor] @!visibility private

# File lib/mergit.rb, line 71
def create_file_processor filename
  Processor.new(search_path, replacements, :filename => filename)
end
create_string_processor(string) click to toggle source

Helper to create a string processor

@param [String] string The string to merge. @return [Processor] @!visibility private

# File lib/mergit.rb, line 62
def create_string_processor string
  Processor.new(search_path, replacements, :string => string)
end