Class RecursiveUtils::FullPathList
In: recursiveutils.rb
Parent: Object

Summary

重複無しのフルパスのリストを作成する.

Methods

Class Methods

初期化:new
リスト取得:get

Public Methods

リスト取得:get_list, get_exist, get_file, get_dir, get_symlink

Private Methods

対象限定:separate, flag_filter
その他:regexp, match?

Methods

flag_filter   get   get_dir   get_exist   get_file   get_list   get_symlink   match?   new   regexp   separate  

Included Modules

LocaleFilter::PrintWrapper Flag

Classes and Modules

Module RecursiveUtils::FullPathList::Flag

Attributes

pathlist  [R]  newpath を与えた際に作成されるファイルリストの配列.

Public Class methods

path を元にオプション opts に対応するリストを配列で返す.

[Source]

# File recursiveutils.rb, line 193
    def self.get(opts = {}, *path)
      self.new(opts, path).pathlist
    end

新規オブジェクトを作成する. 各オプションの意味は FlagAttributes を参照する事.

[Source]

# File recursiveutils.rb, line 199
    def initialize(opts = {}, *path)
      set_flag(opts)
      @pathlist = get_list(path)
    end

Public Instance methods

path を元にディレクトリのリストを配列で返す.

[Source]

# File recursiveutils.rb, line 244
    def get_dir(*path)
      flag_filter(get_exist(path), 'd')
    end

path を元に存在するファイルのリストを配列で返す.

[Source]

# File recursiveutils.rb, line 205
    def get_exist(*path)
      path = path.flatten
      return path  if path.empty?

      list = Hash.new
      if @prune
        lf = LocaleFilter.new('euc', nil, @file_code)
        pattern = regexp(@prune)
      end

      path.each do |i|
        unless test(?e, i)
          warn "#{i}: No such file or directory."  if @warning
          next
        end

        fullpath = File.expand_path(i)
        next  if @prune && match?(lf.tolocale(fullpath), pattern, fullpath)
        list[fullpath] = true

        Find.find(fullpath) do |j|
          Find.prune  if @prune && match?(lf.tolocale(j), pattern, j)
          list[j] = true
        end  if @recursive && test(?d, fullpath)
      end
      list.keys.sort
    end

path を元に通常ファイルのリストを配列で返す.

[Source]

# File recursiveutils.rb, line 239
    def get_file(*path)
      flag_filter(get_exist(path), 'f')
    end

path を元にオプションに対応するリストを配列で返す.

[Source]

# File recursiveutils.rb, line 234
    def get_list(*path)
      flag_filter(get_exist(path))
    end

path を元にシンボリックリンクのリストを配列で返す.

[Source]

# File recursiveutils.rb, line 249
    def get_symlink(*path)
      flag_filter(get_exist(path), 's')
    end

Private Instance methods

配列 list をオプションでフィルタリングして返す.

[Source]

# File recursiveutils.rb, line 273
    def flag_filter(list, type = @file_type)
      return list  if list.empty?
      l = list
      m = {
        :n => 'Not ',
        :f => 'Regular File',
        :d => 'Directory',
        :l => 'Symbolic Link',
        :o => 'Owner',
        :g => 'Group Owner',
        :p => ' permission denied',
        :r => 'Read',
        :w => 'Write',
        :x => 'Execute',
        :t => 'match of target'
      }

      case type.to_s[0, 1].downcase
      when 'f'
        separate(l, m[:n] + m[:f]){ |i| test(?f, i) }
      when 'd'
        separate(l, m[:n] + m[:d]){ |i| test(?d, i) }
      when 's'
        separate(l, m[:n] + m[:l]){ |i| test(?l, i) }
      else
        separate(l, m[:f]){ |i| ! test(?f, i) }  if @regular
        separate(l, m[:d]){ |i| ! test(?d, i) }  if @directory
        separate(l, m[:l]){ |i| ! test(?l, i) }  if @symlink
      end

      separate(l, m[:n] + m[:o]){ |i| test(?o, i) }  if @owner
      separate(l, m[:n] + m[:g]){ |i| test(?G, i) }  if @group
      separate(l, m[:r] + m[:p]){ |i| test(?r, i) }  if @readable
      separate(l, m[:w] + m[:p]){ |i| test(?w, i) }  if @writable
      separate(l, m[:x] + m[:p]){ |i| test(?x, i) }  if @executable

      if @target
        t = regexp(@target)
        f = LocaleFilter.new('euc', nil, @file_code)
        separate(l, m[:n] + m[:t]){ |i| f.tolocale(i) =~ t }
      end

      return l
    end

pathpattern にマッチしたら true を返す.

[Source]

# File recursiveutils.rb, line 263
    def match?(path, pattern, name)
      if path =~ pattern
        warn "#{name}: Match remove target."  if @warning
        return true
      else
        return false
      end
    end

str を元にオプションに対応する正規表現オブジェクトを作成して返す.

[Source]

# File recursiveutils.rb, line 256
    def regexp(str)
      str = LocaleFilter.convert_str(str, 'euc', @input_code)
      opt = Regexp::IGNORECASE  if @casefold
      Regexp.new(str, opt, 'e')
    end

配列 list からブロックを実行した結果が false のファイルを除く.

[Source]

# File recursiveutils.rb, line 319
    def separate(list, message)  # :yields: file
      a = list.partition{ |i| yield(i) }
      a[1].each{ |i| warn "#{i}: #{message}." }  if @warning
      list.replace(a[0])
    end

[Validate]