lib/dressmaker/configuration/directory_rule.rb in dressmaker-0.0.1 vs lib/dressmaker/configuration/directory_rule.rb in dressmaker-0.0.2

- old
+ new

@@ -1,34 +1,41 @@ require 'ftools' require "delegate" class Dressmaker class Configuration - class DirectoryRule + class DirectoryRule < Rule - attr_reader :directory, :action - attr_accessor :description, :name + class All < DirectoryRule - def initialize(directory, &action) - @directory = directory - @action = action + def matches?(base, target) + File.directory?(File.join(base, target)) + end + end - def matches?(target) - self.name = "Directory (#{File.join(target, directory)})" - File.directory?(File.join(target, directory)) - end + class Pattern < DirectoryRule + + attr_reader :pattern, :action + + def initialize(pattern, &action) + @pattern = pattern + @action = action + end - def execute!(target) - Dressmaker.inform(self, description) if description - dir = DirectoryDelegator.new(File.open(File.join(target, directory))) - action.call(dir) + def matches?(base, target) + File.directory?(File.join(base, target)) && File.fnmatch(pattern, target) + end + end - class DirectoryDelegator < SimpleDelegator - def for(pattern) - Dir["#{__getobj__.path}/#{pattern}"].each {|e| yield e} + attr_accessor :description, :name + + def execute!(target) + Delegators.with(File.join(target)) do |dir| + action.call(dir) end end + end end end \ No newline at end of file