Class: TokensWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/rakeoff/tokens_writer.rb

Instance Method Summary collapse

Instance Method Details

#write_for(environment, master_file, tokens, globals, check_usage) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rakeoff/tokens_writer.rb', line 4

def write_for(environment, master_file, tokens, globals, check_usage)		
		@master_file = master_file
		@environment = environment

		output_file = @master_file.gsub('.master', environment.empty? ? '' : ".#{environment}")
		text = File.read(@master_file)
		
		check_if_tokens_are_used(text, tokens) if check_usage
		text = replace_tokens(text, tokens)
		text = replace_tokens(text, globals)

    write_to_file(output_file, text)        

		matches = text.scan(/(\$[\w\d\-_\.]+\$)/)
    
    if (matches.any?)
        raise UnReplacedTokenException, "There are untokenised value(s): #{matches.join(', ').strip} still in #{@output_file}!".red
    end
end