Class: Tokens
- Inherits:
-
Object
- Object
- Tokens
- Defined in:
- lib/tokenr/tokens.rb
Instance Method Summary collapse
-
#initialize(tokens_pattern = '*.master.{config,tt}', globals_file = './globals.rb', writer = TokensWriter.new, checker = TokensChecker.new) ⇒ Tokens
constructor
A new instance of Tokens.
- #replace(path, default_environment = 'local') ⇒ Object
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 43 44 45 46 47 48 49 50 |
# 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| # Read global variables read_tokens(@globals_file) @globals = @environments.dup # Read file variables read_tokens(file.gsub('.master' + File.extname(file), '.tokens.rb')) only_use_environments_defined_in_tokens_rb puts "Environments found - #{@environments.keys.join(', ')}" # Check for duplicates @checker.check(@environments) if !@environments.has_key?(default_environment) puts "Unable to find default environment #{default_environment}" puts "Setting default environment to #{@environments.keys.first}" default_environment = @environments.keys.first end # Write out a file for each environment @environments.each_pair do |environment, values| values[:Environment] = environment # Add the environment as a token @writer.write_for(environment, file, values, @globals[environment], true) end # Write out a file for the default environment @writer.write_for('', file, @environments[default_environment], @globals[default_environment]) end end |