Class: CleanUp::Folder
- Inherits:
-
Object
- Object
- CleanUp::Folder
- Defined in:
- lib/clean_up/folder.rb
Instance Attribute Summary collapse
-
#directory_rules ⇒ Object
readonly
Returns the value of attribute directory_rules.
-
#files_rules ⇒ Object
readonly
Returns the value of attribute files_rules.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#strategy ⇒ Object
readonly
Returns the value of attribute strategy.
Class Method Summary collapse
Instance Method Summary collapse
- #directory(&block) ⇒ Object
- #file(&block) ⇒ Object
-
#initialize(strategy, &block) ⇒ Folder
constructor
A new instance of Folder.
- #process_directory(directory) ⇒ Object
- #process_file(file) ⇒ Object
-
#source(folder = nil) ⇒ Object
Implement setter & getter for source folder.
-
#target(folder = nil) ⇒ Object
Implement setter & getter for target folder.
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_rules ⇒ Object (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_rules ⇒ Object (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 |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/clean_up/folder.rb', line 3 def @options end |
#strategy ⇒ Object (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) (block) do @directory_rules << directory_rule_class.new() end end |
#file(&block) ⇒ Object
24 25 26 27 28 |
# File 'lib/clean_up/folder.rb', line 24 def file(&block) (block) do @files_rules << file_rule_class.new() 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.(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.(folder) end |