begin require 'active_support/core_ext/string/strip' rescue LoadError $stderr.puts 'You need to install the "activesupport"-gem to make that rake task work.' exit 1 end begin require 'erubis' rescue LoadError $stderr.puts 'You need to install the "erubis"-gem to make that rake task work.' exit 1 end require 'forwardable' require_relative 'rubygem_version_file_parser' require_relative 'version_builder' require_relative 'library_builder' module FeduxOrg module Stdlib module VersionManagement class RubygemVersionFile extend Forwardable def_delegators :@version, :bump def initialize( version, library ) @version = version @library = library end def version @version.to_s end def version=(v) @version.update( v ) end def write(path) File.write( path, to_s ) end def self.read( path, parser=RubygemVersionFileParser.new,version_builder=VersionBuilder.new, library_builder=LibraryBuilder.new ) parser.parse( path ) version = version_builder.build_from( parser.version ) library = library_builder.build_from( parser.modules ) RubygemVersionFile.new( version, library ) end def to_s klass = Class.new do attr_reader :version, :library def initialize( version, module_names ) @version = version @module_names = module_names end def prefix(n) ' ' * 2 * n end end Erubis::Eruby.new(template).evaluate( klass.new( @version, @library.module_names ) ) end private def template <<-EOF.strip_heredoc #main <%= @module_names.first %> <% @module_names.each_with_index do |m,i| -%> <%= prefix( i ) %>module <%= m %> <% end -%> <%= prefix( @module_names.size ) %>VERSION = '<%= @version %>' <% ( @module_names.size - 1 ).downto(0) do |i| -%> <%= prefix( i ) %>end <% end -%> EOF end end end end end