Sha256: 6a751cfafd9e1d7eaa60fa2307a97b1467aab5afe3d19d9eb7ab554ae297d316
Contents?: true
Size: 1.39 KB
Versions: 1
Compression:
Stored size: 1.39 KB
Contents
require 'nokogiri' require_relative 'core_ext.rb' module Vamper class VersionConfigFile def self.get_default_file File.join(File.dirname(__FILE__), 'default.version.config') end def initialize(io, tags) doc = Nokogiri::XML(io) @file_types = [] doc.xpath('/VersionConfig/FileType').each do |node| file_type_struct = Struct.new(:name, :file_specs, :updates, :write) search_replace_struct = Struct.new(:search, :replace) file_type = file_type_struct.new file_type.name = node.name file_type.file_specs = node.xpath('FileSpec').map { |sub_node| Regexp.new('^' + Regexp::escape(sub_node.text).gsub('\\*', '.*').gsub('\\?', '.') + '$') } update_node_set = node.xpath('Update') if update_node_set # Replace ${...} entries in the replace string with equivalent tags if available file_type.updates = update_node_set.map { |sub_node| s_and_r = search_replace_struct.new( %r(#{sub_node.at_xpath('Search').text.gsub(/\(\?'(\w+)'/, '(?<\\1>')}), sub_node.at_xpath('Replace').text.replace_tags(tags)) } end write_node = node.at_xpath('Write') if write_node file_type.write = write_node.text.replace_tags(tags) end @file_types.push(file_type) end end attr_reader :file_types end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
code-tools-5.0.2 | lib/code_tools/version_config_file.rb |