Class: Cleaner::Directory

Inherits:
Object
  • Object
show all
Defined in:
lib/cleaner/directory.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, block) ⇒ Directory

Returns a new instance of Directory.



5
6
7
8
# File 'lib/cleaner/directory.rb', line 5

def initialize(path, block)
  @path = path
  @block = block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (protected)



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/cleaner/directory.rb', line 16

def method_missing(method, *args, &block)
  action_class = construct_action_class(method)
  # FIXME: refactor this argument parsing
  options = args.last.is_a?(Hash) ? args.last : {}
  options = options.merge(
    :pattern => args.first.is_a?(Hash) ? nil : args.first,
    :path => path
  )
  filter = FileFilter.new(options)
  action = action_class.new(filter.filterize, options)
  action.execute
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



3
4
5
# File 'lib/cleaner/directory.rb', line 3

def block
  @block
end

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/cleaner/directory.rb', line 3

def path
  @path
end

Instance Method Details

#cleanObject



10
11
12
# File 'lib/cleaner/directory.rb', line 10

def clean
  instance_eval(&block)
end