Class: Mergit
- Inherits:
-
Object
- Object
- Mergit
- Defined in:
- lib/mergit.rb,
lib/mergit/errors.rb,
lib/mergit/version.rb,
lib/mergit/processor.rb
Overview
A class for merging in require
ments.
Defined Under Namespace
Classes: MergitError, Processor, RequirementNotFound
Constant Summary collapse
- ATTRIBUTES =
List of attributes accepted by Mergit, and the default values.
{ :search_path => [Dir.pwd], :replacements => {}, }.freeze
- VERSION =
The version of the Mergit Library.
"1.1.1"
Instance Method Summary collapse
-
#create_file_processor(filename) ⇒ Processor
private
Helper to create a file processor.
-
#create_string_processor(string) ⇒ Processor
private
Helper to create a string processor.
-
#initialize(options = nil) ⇒ Mergit
constructor
Create a new mergit instance.
-
#process(string) ⇒ String
Merge a string.
-
#process_file(filename) ⇒ String
Merge a file.
Constructor Details
#initialize(options = nil) ⇒ Mergit
Create a new mergit instance.
23 24 25 26 27 28 29 |
# File 'lib/mergit.rb', line 23 def initialize =nil = ? ATTRIBUTES.merge() : ATTRIBUTES ATTRIBUTES.each_key do |attr| instance_variable_set("@#{attr}", [attr]) end end |
Instance Method Details
#create_file_processor(filename) ⇒ Processor (private)
Helper to create a file processor
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
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
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
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 |