Class: CleanUp::Folder

Inherits:
Object
  • Object
show all
Defined in:
lib/clean_up/folder.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(strategy, &block) ⇒ Folder

Returns a new instance of Folder.



9
10
11
12
# File 'lib/clean_up/folder.rb', line 9

def initialize(strategy, &block)
  @strategy, @files_rules, @directory_rules = strategy, [], []
  instance_eval(&block)
end

Instance Attribute Details

#directory_rulesObject (readonly)

Returns the value of attribute directory_rules.



3
4
5
# File 'lib/clean_up/folder.rb', line 3

def directory_rules
  @directory_rules
end

#files_rulesObject (readonly)

Returns the value of attribute files_rules.



3
4
5
# File 'lib/clean_up/folder.rb', line 3

def files_rules
  @files_rules
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/clean_up/folder.rb', line 3

def options
  @options
end

#strategyObject (readonly)

Returns the value of attribute strategy.



3
4
5
# File 'lib/clean_up/folder.rb', line 3

def strategy
  @strategy
end

Class Method Details

.collect(strategy, &block) ⇒ Object



5
6
7
# File 'lib/clean_up/folder.rb', line 5

def self.collect(strategy, &block)
  new(strategy, &block)
end

Instance Method Details

#directory(&block) ⇒ Object



30
31
32
33
34
# File 'lib/clean_up/folder.rb', line 30

def directory(&block)
  with_options(block) do
    @directory_rules << directory_rule_class.new(options)
  end
end

#file(&block) ⇒ Object



24
25
26
27
28
# File 'lib/clean_up/folder.rb', line 24

def file(&block)
  with_options(block) do
    @files_rules << file_rule_class.new(options)
  end
end

#process_directory(directory) ⇒ Object



36
37
38
39
40
# File 'lib/clean_up/folder.rb', line 36

def process_directory(directory)
  directory_rules.detect do |rule|
    rule.call(directory, target)
  end
end

#process_file(file) ⇒ Object



42
43
44
45
46
# File 'lib/clean_up/folder.rb', line 42

def process_file(file)
  files_rules.detect do |rule|
    rule.call(file, target)
  end
end

#source(folder = nil) ⇒ Object

Implement setter & getter for source folder.



15
16
17
# File 'lib/clean_up/folder.rb', line 15

def source(folder = nil)
  @source ||= File.expand_path(folder)
end

#target(folder = nil) ⇒ Object

Implement setter & getter for target folder.



20
21
22
# File 'lib/clean_up/folder.rb', line 20

def target(folder = nil)
  @target ||= File.expand_path(folder)
end