class Prune::RetentionPolicy
Represents a retention policy, whether loaded from the core retention policy or from a project-specific configured retention policy. It defines all the categories, the actions associated with them and some other elements. It is the primary form of prune Configuration.
Constants
- DEFAULT_OPTIONS
Attributes
categories[RW]
Public Class Methods
new( folder_name, options = {} )
click to toggle source
# File lib/prune/retention.rb, line 16 def initialize( folder_name, options = {} ) options = DEFAULT_OPTIONS.merge( options ) @folder_name = folder_name @today = Date.today @categories = Array.new @default_category = Category.new "Unmatched Files", :retain, true load_retention_dsl if options[:load_dsl] end
Public Instance Methods
categorize( file_name )
click to toggle source
# File lib/prune/retention.rb, line 29 def categorize( file_name ) file_context = FileContext.new( @folder_name, file_name, @preprocessor ) @categories.find { |cat| cat.includes? file_context } || @default_category end
category( description, &block )
click to toggle source
# File lib/prune/retention.rb, line 49 def category( description, &block ) builder = CategoryBuilder.new( description ) builder.instance_eval &block @categories << builder.build end
get_dsl( dsl_folder, dsl_file, human_name=nil )
click to toggle source
# File lib/prune/retention.rb, line 38 def get_dsl( dsl_folder, dsl_file, human_name=nil ) dsl = File.join( dsl_folder, dsl_file ) human_name = Pathname.new( dsl ).cleanpath.to_s if human_name.nil? if File.exists?( dsl ) then puts "Loading retention policy from: #{human_name}" return File.read( dsl ), dsl_file else return nil end end
get_retention_dsl( folder_name )
click to toggle source
# File lib/prune/retention.rb, line 34 def get_retention_dsl( folder_name ) get_dsl( folder_name, '.prune' ) || get_dsl( File.dirname(__FILE__), 'default_retention.rb', 'core retention policy' ) end
load_retention_dsl()
click to toggle source
# File lib/prune/retention.rb, line 25 def load_retention_dsl() instance_eval *get_retention_dsl( @folder_name ) end
preprocess( &block )
click to toggle source
# File lib/prune/retention.rb, line 55 def preprocess( &block ) @preprocessor = Proc.new &block end