Sha256: 93e0bb81b58da8ff8432625afeeecd125d75e80bcb4b17d5f963fe7a90a7e68d

Contents?: true

Size: 925 Bytes

Versions: 1

Compression:

Stored size: 925 Bytes

Contents

namespace :ci do
  namespace :config do
    desc 'Generate config files from *.ci templates'
    task :generate do
      Dir.glob('**/*.ci') do |file_name|
        target_file_name = file_name.gsub(/.ci$/, '')

        if File.exist?(target_file_name)
          error "#{target_file_name} already exists."
          # STDERR.puts("Skipping #{target_file_name} - file exists")
        else
          STDERR.puts("Creating #{target_file_name} from #{file_name}")
          File.write(target_file_name, interpolate(file_name, ENV))
        end
      end
    end

    def interpolate(file_name, variables)
      File.read(file_name).gsub(/%{[^}]+}/) do |match|
        key = match.gsub(/^%{([^}]+)}/, '\1')
        variables[key] || error("Cannot interpolate unknown environment variable '#{key}' in '#{file_name}'")
      end
    end

    def error(message)
      STDERR.puts("Error: #{message}")
      exit 1
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ci_config_generator-0.0.1 lib/ci_config_generator/tasks.rb