Class: Tokens
- Inherits:
-
Object
- Object
- Tokens
- Defined in:
- lib/rakeoff/tokens.rb
Instance Method Summary collapse
- #find_and_replace(path, default) ⇒ Object
-
#initialize(globals_file, tokens_pattern, writer) ⇒ Tokens
constructor
A new instance of Tokens.
Constructor Details
#initialize(globals_file, tokens_pattern, writer) ⇒ Tokens
Returns a new instance of Tokens.
5 6 7 8 9 10 |
# File 'lib/rakeoff/tokens.rb', line 5 def initialize(globals_file, tokens_pattern, writer) @globals_file = globals_file @tokens_pattern = tokens_pattern @writer = writer @globals = {} end |
Instance Method Details
#find_and_replace(path, default) ⇒ Object
12 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 |
# File 'lib/rakeoff/tokens.rb', line 12 def find_and_replace(path, default) print_heading 'Tokenising' read_tokens_file(@globals_file) @files = Dir.glob("#{path}/**/#{@tokens_pattern}", File::FNM_CASEFOLD) puts "#{@files.length} config(s) found for tokenising" puts '' @files.each do |file| @environments = {} read_tokens_file(file.gsub('.master.', '.tokens.')) puts "Tokensing - #{file}" puts "Environments - #{@environments.keys.join(', ')}" if !@environments.has_key?(default) raise InvalidEnvironment, "Environment #{default} is not recognised. Possible environments are #{@environments.keys.join(', ')}".red end @environments.each_pair do |environment, values| @writer.write_for(environment, file, values, @globals, true) end @writer.write_for('', file, @environments[default], @globals, false) puts '' end end |