Sha256: eb8eae8161f8857f9d0478e55d41ee55a5afbd1d854747ec646c13f14120773d
Contents?: true
Size: 1.76 KB
Versions: 2
Compression:
Stored size: 1.76 KB
Contents
require 'fileutils' require 'rails' require 'yaml' module Chlorine class Railtie < Rails::Railtie initializer "chlorine.configure_rails_initialization" do begin @config = YAML::load_file File.expand_path('config/chlorine.yml', Rails.root) return unless @config && @config['envs'] require_clean = (@config['envs'].collect {|env| env.downcase}).include? Rails.env rescue Exception => e puts "Chlorine was unable to read its configuration: #{e}" end do_clean if require_clean end private def do_clean @config['dirs'].each do |dir_name, dir_config| begin dir_config['excludes'] = dir_config['excludes'].collect {|x| x[-1] == '/' ? x[0...-1] : x} next unless valid_dir_config? dir_config next unless Dir.exists? File.expand_path(dir_name, Rails.root) dir = Dir.new File.expand_path(dir_name, Rails.root) dir.each { |filename| unless (['.', '..'] + dir_config['excludes']).include?(filename) filepath = File.expand_path(dir_name + '/' + filename, Rails.root) if File.file?(filepath) File.delete filepath elsif File.directory?(filepath) FileUtils.rm_rf filepath end end } rescue Exception => e puts "Chlorine hit an exception while cleaning: #{e}" end end end def valid_dir_config?(dir_config) dir_config['excludes'].each do |exclude| next if exclude == '' if exclude[0...-1].match '/' puts "Invalid exclude '#{exclude}' in chlorine.yml: excludes must be root-level" return false end end return true end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
chlorine-0.1.6 | lib/chlorine/clean.rb |
chlorine-0.1.5 | lib/chlorine/clean.rb |