Class: Mergit

Inherits:
Object
  • Object
show all
Defined in:
lib/mergit.rb,
lib/mergit/errors.rb,
lib/mergit/version.rb,
lib/mergit/processor.rb

Overview

A class for merging in requirements.

Defined Under Namespace

Classes: MergitError, Processor, RequirementNotFound

Constant Summary collapse

ATTRIBUTES =

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

Returns:

  • (Hash)
{
  :search_path => [Dir.pwd],
  :replacements => {},
}.freeze
VERSION =

The version of the Mergit Library.

"1.1.1"

Instance Method Summary collapse

Constructor Details

#initialize(options = nil) ⇒ Mergit

Create a new mergit instance.

Parameters:

  • options (Hash) (defaults to: nil)

    See ATTRIBUTES for the list of options you can pass in.



23
24
25
26
27
28
29
# 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

Instance Method Details

#create_file_processor(filename) ⇒ Processor (private)

Helper to create a file processor

Parameters:

  • filename (Pathname, String)

    The file to process

Returns:



71
72
73
# File 'lib/mergit.rb', line 71

def create_file_processor filename
  Processor.new(search_path, replacements, :filename => filename)
end

#create_string_processor(string) ⇒ Processor (private)

Helper to create a string processor

Parameters:

  • string (String)

    The string to merge.

Returns:



62
63
64
# File 'lib/mergit.rb', line 62

def create_string_processor string
  Processor.new(search_path, replacements, :string => string)
end

#process(string) ⇒ String

Merge a string

Parameters:

  • string (String)

    The text that should be merged.

Returns:

  • (String)

    The merged output.



47
48
49
# File 'lib/mergit.rb', line 47

def process string
  create_string_processor(string).output
end

#process_file(filename) ⇒ String

Merge a file

Parameters:

  • filename (Pathname, String)

    The name of the file to merge.

Returns:

  • (String)

    The merged file.



35
36
37
38
39
40
41
# 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