Class: Tokens

Inherits:
Object
  • Object
show all
Defined in:
lib/tokenr/tokens.rb

Instance Method Summary collapse

Constructor Details

#initialize(tokens_pattern = '*.master.{config,tt}', globals_file = './globals.rb', writer = TokensWriter.new, checker = TokensChecker.new) ⇒ Tokens

Returns a new instance of Tokens.



6
7
8
9
10
11
# File 'lib/tokenr/tokens.rb', line 6

def initialize(tokens_pattern='*.master.{config,tt}', globals_file='./globals.rb', writer=TokensWriter.new, checker=TokensChecker.new)
	@globals_file = globals_file
	@tokens_pattern = tokens_pattern
	@writer = writer
	@checker = checker
end

Instance Method Details

#replace(path, default_environment = 'local') ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/tokenr/tokens.rb', line 13

def replace(path, default_environment='local')
	puts " _        _                   "
	puts "| |_ ___ | | _____ _ __  _ __ "
	puts "| __/ _ \\| |/ / _ \\ '_ \\| '__|"
	puts "| || (_) |   <  __/ | | | |   "
	puts " \\__\\___/|_|\\_\\___|_| |_|_|   "
	puts
	
	find_master_files_in(path).each do |file|
		puts '', file
		read_global_variables
		read_file_variables(file)		
		only_use_environments_defined_in_tokens_rb		
		
		@checker.check_for_duplicates(@environments)
		default = set_default_environment(default_environment)
		@environments.each_pair { |environment, values| values[:Environment] = environment }

		# Write out a file for each environment
		if(@environments.keys.length > 1)
			@environments.each_pair do |environment, values| 
				@writer.write_for(environment, file, values, @globals[environment], true) 
			end
		end
		
		# Write out a file for the default environment
		puts @globals[default]
		@writer.write_for('', file, @environments[default], @globals[default])
	end
end