Class: Prune::RetentionPolicy

Inherits:
Object
  • Object
show all
Defined in:
lib/prune/retention.rb

Overview

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.

Constant Summary collapse

DEFAULT_OPTIONS =
{ :load_dsl => true }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(folder_name, options = {}) ⇒ RetentionPolicy

Returns a new instance of RetentionPolicy.



16
17
18
19
20
21
22
23
# 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

Instance Attribute Details

#categoriesObject

Returns the value of attribute categories.



14
15
16
# File 'lib/prune/retention.rb', line 14

def categories
  @categories
end

Instance Method Details

#categorize(file_name) ⇒ Object



29
30
31
32
# 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) ⇒ Object



49
50
51
52
53
# 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) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# 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) ⇒ Object



34
35
36
# 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_dslObject



25
26
27
# File 'lib/prune/retention.rb', line 25

def load_retention_dsl()
  instance_eval *get_retention_dsl( @folder_name )
end

#preprocess(&block) ⇒ Object



55
56
57
# File 'lib/prune/retention.rb', line 55

def preprocess( &block )
  @preprocessor = Proc.new &block
end