lib/rubber/generator.rb in nirvdrum-rubber-1.1.7 vs lib/rubber/generator.rb in nirvdrum-rubber-2.0.0.rails3.beta6

- old
+ new

@@ -31,17 +31,17 @@ config_dirs.each do |dir| Dir[dir].sort.each do |f| next if f =~ /\/(CVS|\.svn)\// if File.file?(f) && (! pat || pat.match(f)) - LOGGER.info{"Transforming #{f}"} + Rubber.logger.info{"Transforming #{f}"} begin transform(IO.read(f), @options) rescue Exception => e lines = e.backtrace.grep(/^\(erb\):([0-9]+)/) {|b| Regexp.last_match(1) } - LOGGER.error{"Transformation failed for #{f}#{':' + lines.first if lines.first}"} - LOGGER.error e.message + Rubber.logger.error{"Transformation failed for #{f}#{':' + lines.first if lines.first}"} + Rubber.logger.error e.message exit 1 end end end end @@ -111,11 +111,11 @@ if orig != result || force # create dirs as needed FileUtils.mkdir_p(File.dirname(config_path)) if config_path # Write a backup of original - open("#{config_path}.bak", 'w') { |f| f.write(orig) } if config_path + open("#{config_path}.bak", 'w') { |f| f.write(orig) } if config_path && config.backup # Write out transformed file writer = config_path || "|#{config.write_cmd}" open(writer, 'w') do |pipe| pipe.write(result) @@ -128,25 +128,27 @@ FileUtils.chmod(config.perms, config_path) if config.perms && config_path FileUtils.chown(config.owner, config.group, config_path) if config_path && (config.owner || config.group) # Run post transform command if needed if config.post - if orig == result - LOGGER.info("Nothing to do, not running post command") + if fake_root + Rubber.logger.info("Not running post command as a fake root was given: #{config.post}") elsif no_post - LOGGER.info("Not running post command as no post specified") - elsif fake_root - LOGGER.info("Not running post command as a fake root was given: #{config.post}") + Rubber.logger.info("Not running post command as no post specified") else - # this lets us abort a script if a command in the middle of it errors out - # stop_on_error_cmd = "function error_exit { exit 99; }; trap error_exit ERR" - config.post = "#{stop_on_error_cmd}\n#{config.post}" if stop_on_error_cmd + if orig != result || force + # this lets us abort a script if a command in the middle of it errors out + # stop_on_error_cmd = "function error_exit { exit 99; }; trap error_exit ERR" + config.post = "#{stop_on_error_cmd}\n#{config.post}" if stop_on_error_cmd - LOGGER.info{"Transformation executing post config command: #{config.post}"} - LOGGER.info `#{config.post}` - if $?.exitstatus != 0 - raise "Post command failed execution: #{config.post}" + Rubber.logger.info{"Transformation executing post config command: #{config.post}"} + Rubber.logger.info `#{config.post}` + if $?.exitstatus != 0 + raise "Post command failed execution: #{config.post}" + end + else + Rubber.logger.info("Nothing to do, not running post command") end end end end end @@ -172,25 +174,31 @@ attr_accessor :perms # Sets transformation to be additive, only replaces between given delimiters, e/g/ additive = ["## start", "## end"] attr_accessor :additive # Lets one dynamically determine if a given file gets skipped during transformation attr_accessor :skip + # Backup file when transforming, defaults to true, set to false to prevent backup + attr_accessor :backup # use sudo to write the output file # attr_accessor :sudo # options passed in through code attr_accessor :options + def initialize + @backup = true + end + def get_binding binding - end + end - def rubber_env() - Rubber::Configuration.rubber_env - end - - def rubber_instances() - Rubber::Configuration.rubber_instances - end + def rubber_env() + Rubber::Configuration.rubber_env + end + + def rubber_instances() + Rubber::Configuration.rubber_instances + end end end end