Class: Vamper::VersionConfigFile
- Inherits:
-
Object
- Object
- Vamper::VersionConfigFile
- Defined in:
- lib/code_tools/version_config_file.rb
Instance Attribute Summary collapse
-
#file_types ⇒ Object
readonly
Returns the value of attribute file_types.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(io, tags) ⇒ VersionConfigFile
constructor
A new instance of VersionConfigFile.
Constructor Details
#initialize(io, tags) ⇒ VersionConfigFile
Returns a new instance of VersionConfigFile.
11 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/code_tools/version_config_file.rb', line 11 def initialize(io, ) 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.()) } end write_node = node.at_xpath('Write') if write_node file_type.write = write_node.text.() end @file_types.push(file_type) end end |
Instance Attribute Details
#file_types ⇒ Object (readonly)
Returns the value of attribute file_types.
40 41 42 |
# File 'lib/code_tools/version_config_file.rb', line 40 def file_types @file_types end |
Class Method Details
.get_default_file ⇒ Object
7 8 9 |
# File 'lib/code_tools/version_config_file.rb', line 7 def self.get_default_file File.join(File.dirname(__FILE__), 'default.version.config') end |