duplicated_filename_checker 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/.travis.yml +1 -1
 - data/README.md +11 -1
 - data/bin/dup-filename +17 -24
 - data/lib/duplicated_filename_checker.rb +1 -0
 - data/lib/duplicated_filename_checker/check.rb +38 -11
 - data/lib/duplicated_filename_checker/file_profile.rb +1 -1
 - data/lib/duplicated_filename_checker/formatter.rb +58 -0
 - data/lib/duplicated_filename_checker/version.rb +1 -1
 - data/test/sample_for_test/dir_a1/{duplicate_filename.sample → duplicate_filename_1.sample} +0 -0
 - data/test/sample_for_test/dir_a1/duplicate_filename_2.png +0 -0
 - data/test/sample_for_test/dir_b1/dir_b2/{duplicate_filename.sample → duplicate_filename_1.sample} +0 -0
 - data/test/sample_for_test/dir_b1/dir_b2/duplicate_filename_2.png +0 -0
 - data/test/test_check.rb +58 -17
 - data/test/test_file_profile.rb +1 -1
 - data/test/test_formatter.rb +54 -0
 - metadata +13 -6
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: f0bee9d09d0dc3b70e60cfc8e6b383f08e6070b8
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: f2dfc12500b29bfd22c9752dbf1dab479123be30
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 6cc1ee617589e8e23bce4a5c4f9e2f6b9110b302658cc60fa3acf28b8d7187469fdac4739e6254d6f70c7d2ace7082eb1c23598d35d5629f8fc97382cef4ebea
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: da5031d498c68fd85b3da4c06da79b2d65c769815462e3c9f19146e4d776847c679e173057ca3f26718309462e7d3d4f00918274c6fab1c1ed4924ab171288ca
         
     | 
    
        data/.travis.yml
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | 
         @@ -15,6 +15,8 @@ install: 
     | 
|
| 
       15 
15 
     | 
    
         
             
                $ gem install duplicated_filename_checker
         
     | 
| 
       16 
16 
     | 
    
         | 
| 
       17 
17 
     | 
    
         
             
            ## Usage
         
     | 
| 
      
 18 
     | 
    
         
            +
            ### survey duplicate filename
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
       18 
20 
     | 
    
         
             
            ```
         
     | 
| 
       19 
21 
     | 
    
         
             
            $ dup-filename ./survey_dir1_root ./survey_dir2_root
         
     | 
| 
       20 
22 
     | 
    
         | 
| 
         @@ -38,6 +40,14 @@ $ dup-filename ./survey_dir1_root ./survey_dir2_root 
     | 
|
| 
       38 
40 
     | 
    
         | 
| 
       39 
41 
     | 
    
         
             
            ```
         
     | 
| 
       40 
42 
     | 
    
         | 
| 
      
 43 
     | 
    
         
            +
            ### only filename option: `-l`
         
     | 
| 
      
 44 
     | 
    
         
            +
            ```
         
     | 
| 
      
 45 
     | 
    
         
            +
            $ dup-filename -l ./survey_dir1_root ./survey_dir2_root
         
     | 
| 
      
 46 
     | 
    
         
            +
            dupfilename1.png
         
     | 
| 
      
 47 
     | 
    
         
            +
            dupfilename2.png
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
            ```
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
       41 
51 
     | 
    
         
             
            ## Usage `duplicated_filename_checker` as library
         
     | 
| 
       42 
52 
     | 
    
         | 
| 
       43 
53 
     | 
    
         
             
            You can use `duplicated_filename_checker` in ruby program.
         
     | 
| 
         @@ -87,4 +97,4 @@ p duplicate_file_profiles[0].path 
     | 
|
| 
       87 
97 
     | 
    
         | 
| 
       88 
98 
     | 
    
         
             
            p duplicate_file_profiles[1].path
         
     | 
| 
       89 
99 
     | 
    
         
             
            #=> /Users/shinya131/survey_dir2_root/subdirectory/dupfilename1.png
         
     | 
| 
       90 
     | 
    
         
            -
            ```
         
     | 
| 
      
 100 
     | 
    
         
            +
            ```
         
     | 
    
        data/bin/dup-filename
    CHANGED
    
    | 
         @@ -1,34 +1,27 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            #!/usr/bin/env ruby
         
     | 
| 
      
 2 
     | 
    
         
            +
            $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
         
     | 
| 
       2 
3 
     | 
    
         
             
            require 'duplicated_filename_checker'
         
     | 
| 
       3 
4 
     | 
    
         
             
            require 'optparse'
         
     | 
| 
       4 
5 
     | 
    
         | 
| 
       5 
     | 
    
         
            -
            #  
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
              raise ArgumentError.new('Specify the argument. Argument is survey target root paths.')
         
     | 
| 
       8 
     | 
    
         
            -
            end
         
     | 
| 
      
 6 
     | 
    
         
            +
            # read args
         
     | 
| 
      
 7 
     | 
    
         
            +
            options = ARGV.getopts("li:")
         
     | 
| 
       9 
8 
     | 
    
         | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
      
 9 
     | 
    
         
            +
            exclude_basename = options["i"]
         
     | 
| 
      
 10 
     | 
    
         
            +
            only_basename = options["l"]
         
     | 
| 
       11 
11 
     | 
    
         
             
            servey_root_paths = ARGV
         
     | 
| 
       12 
     | 
    
         
            -
            duplicated_file_profiles = DuplicatedFilenameChecker::Check.new(*servey_root_paths).execute
         
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
            # options
         
     | 
| 
       15 
     | 
    
         
            -
            options = ARGV.getopts("i:")
         
     | 
| 
       16 
     | 
    
         
            -
            ignore_keyword = options["i"]
         
     | 
| 
       17 
12 
     | 
    
         | 
| 
       18 
     | 
    
         
            -
            #  
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
              end
         
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
              puts "## #{basename}"
         
     | 
| 
      
 13 
     | 
    
         
            +
            # survey
         
     | 
| 
      
 14 
     | 
    
         
            +
            include DuplicatedFilenameChecker
         
     | 
| 
      
 15 
     | 
    
         
            +
            duplicated_file_profiles = Check.new(*servey_root_paths).execute
         
     | 
| 
      
 16 
     | 
    
         
            +
            result = Formatter.new(duplicated_file_profiles)
         
     | 
| 
       25 
17 
     | 
    
         | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
                puts " * md5: #{file_profile.md5_digest}"
         
     | 
| 
       29 
     | 
    
         
            -
                puts " * mtime: #{file_profile.stat.mtime}"
         
     | 
| 
       30 
     | 
    
         
            -
                puts "\n"
         
     | 
| 
       31 
     | 
    
         
            -
              end
         
     | 
| 
      
 18 
     | 
    
         
            +
            # filter
         
     | 
| 
      
 19 
     | 
    
         
            +
            result.exclude_basename(exclude_basename)
         
     | 
| 
       32 
20 
     | 
    
         | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
      
 21 
     | 
    
         
            +
            # show
         
     | 
| 
      
 22 
     | 
    
         
            +
            if only_basename
         
     | 
| 
      
 23 
     | 
    
         
            +
              puts result.only_basename
         
     | 
| 
      
 24 
     | 
    
         
            +
            else
         
     | 
| 
      
 25 
     | 
    
         
            +
              puts result.markdown
         
     | 
| 
       34 
26 
     | 
    
         
             
            end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
         @@ -1,6 +1,9 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            class DuplicatedFilenameChecker::Check
         
     | 
| 
       2 
     | 
    
         
            -
              def initialize(* 
     | 
| 
       3 
     | 
    
         
            -
                 
     | 
| 
      
 2 
     | 
    
         
            +
              def initialize(*check_direcotry_roots)
         
     | 
| 
      
 3 
     | 
    
         
            +
                argument_size_validation!(check_direcotry_roots)
         
     | 
| 
      
 4 
     | 
    
         
            +
                check_directory_exists_validation!(check_direcotry_roots)
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
                @check_target_paths = check_target_paths_by(check_direcotry_roots)
         
     | 
| 
       4 
7 
     | 
    
         
             
              end
         
     | 
| 
       5 
8 
     | 
    
         | 
| 
       6 
9 
     | 
    
         
             
              def execute
         
     | 
| 
         @@ -9,28 +12,52 @@ class DuplicatedFilenameChecker::Check 
     | 
|
| 
       9 
12 
     | 
    
         | 
| 
       10 
13 
     | 
    
         
             
              private
         
     | 
| 
       11 
14 
     | 
    
         | 
| 
       12 
     | 
    
         
            -
              # select duplicate paths from  
     | 
| 
      
 15 
     | 
    
         
            +
              # select duplicate paths from check target paths
         
     | 
| 
       13 
16 
     | 
    
         
             
              def duplicate_paths
         
     | 
| 
       14 
     | 
    
         
            -
                @ 
     | 
| 
       15 
     | 
    
         
            -
                  is_duplicate?( 
     | 
| 
      
 17 
     | 
    
         
            +
                @check_target_paths.select do |file|
         
     | 
| 
      
 18 
     | 
    
         
            +
                  is_duplicate?(file.basename)
         
     | 
| 
       16 
19 
     | 
    
         
             
                end
         
     | 
| 
       17 
20 
     | 
    
         
             
              end
         
     | 
| 
       18 
21 
     | 
    
         | 
| 
       19 
22 
     | 
    
         
             
              def is_duplicate?(basename)
         
     | 
| 
       20 
     | 
    
         
            -
                 
     | 
| 
      
 23 
     | 
    
         
            +
                basename_with_count[basename] > 1
         
     | 
| 
       21 
24 
     | 
    
         
             
              end
         
     | 
| 
       22 
25 
     | 
    
         | 
| 
       23 
     | 
    
         
            -
              #  
     | 
| 
       24 
     | 
    
         
            -
              # @example  
     | 
| 
       25 
     | 
    
         
            -
              def  
     | 
| 
       26 
     | 
    
         
            -
                 
     | 
| 
      
 26 
     | 
    
         
            +
              # @return [Hash] basename with same basename count.
         
     | 
| 
      
 27 
     | 
    
         
            +
              # @example { "basename_a.png" => 1, "basename_b.png" => 3, "basename_c.png" => 1 }
         
     | 
| 
      
 28 
     | 
    
         
            +
              def basename_with_count
         
     | 
| 
      
 29 
     | 
    
         
            +
                unless @basename_count.nil? # memorize
         
     | 
| 
      
 30 
     | 
    
         
            +
                  return @basename_count
         
     | 
| 
      
 31 
     | 
    
         
            +
                end
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                @basename_count = Hash.new(0)
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                @check_target_paths.each do |file|
         
     | 
| 
      
 36 
     | 
    
         
            +
                  @basename_count[file.basename] += 1
         
     | 
| 
      
 37 
     | 
    
         
            +
                end
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
                @basename_count
         
     | 
| 
       27 
40 
     | 
    
         
             
              end
         
     | 
| 
       28 
41 
     | 
    
         | 
| 
       29 
     | 
    
         
            -
              def  
     | 
| 
      
 42 
     | 
    
         
            +
              def check_target_paths_by(root_paths)
         
     | 
| 
       30 
43 
     | 
    
         
             
                # get paths in subdirectory
         
     | 
| 
       31 
44 
     | 
    
         
             
                paths = root_paths.map{|root| Dir.glob("#{root}/**/*.*") }.flatten
         
     | 
| 
       32 
45 
     | 
    
         | 
| 
       33 
46 
     | 
    
         
             
                # exchange to FileProfile
         
     | 
| 
       34 
47 
     | 
    
         
             
                paths.map{|path| DuplicatedFilenameChecker::FileProfile.new(path) }
         
     | 
| 
       35 
48 
     | 
    
         
             
              end
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
              def argument_size_validation!(check_direcotry_roots)
         
     | 
| 
      
 51 
     | 
    
         
            +
                unless check_direcotry_roots.size > 0
         
     | 
| 
      
 52 
     | 
    
         
            +
                  raise ArgumentError.new('Specify the argument. Argument is survey target root paths.')
         
     | 
| 
      
 53 
     | 
    
         
            +
                end
         
     | 
| 
      
 54 
     | 
    
         
            +
              end
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
              def check_directory_exists_validation!(check_direcotry_roots)
         
     | 
| 
      
 57 
     | 
    
         
            +
                check_direcotry_roots.each do |dir|
         
     | 
| 
      
 58 
     | 
    
         
            +
                  unless File.exists?(dir)
         
     | 
| 
      
 59 
     | 
    
         
            +
                    raise ArgumentError.new("No such directory: #{dir}")
         
     | 
| 
      
 60 
     | 
    
         
            +
                  end
         
     | 
| 
      
 61 
     | 
    
         
            +
                end
         
     | 
| 
      
 62 
     | 
    
         
            +
              end
         
     | 
| 
       36 
63 
     | 
    
         
             
            end
         
     | 
| 
         @@ -0,0 +1,58 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            class DuplicatedFilenameChecker::Formatter
         
     | 
| 
      
 2 
     | 
    
         
            +
              def initialize(result_of_duplicate_filename_checker_check_execute)
         
     | 
| 
      
 3 
     | 
    
         
            +
                @duplicate_file_profiles = result_of_duplicate_filename_checker_check_execute
         
     | 
| 
      
 4 
     | 
    
         
            +
              end
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
              def exclude_basename(exclude_basename_regexp)
         
     | 
| 
      
 7 
     | 
    
         
            +
                @exclude_basename_regexp = exclude_basename_regexp
         
     | 
| 
      
 8 
     | 
    
         
            +
              end
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
              def hash
         
     | 
| 
      
 11 
     | 
    
         
            +
                duplicate_file_profiles_with_filter
         
     | 
| 
      
 12 
     | 
    
         
            +
              end
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
              def only_basename
         
     | 
| 
      
 15 
     | 
    
         
            +
                duplicate_file_profiles_with_filter.keys
         
     | 
| 
      
 16 
     | 
    
         
            +
              end
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
              # @example
         
     | 
| 
      
 19 
     | 
    
         
            +
              # ### duplicate_filename.sample
         
     | 
| 
      
 20 
     | 
    
         
            +
              # 1. /Users/nagai_shinya/gem/duplicated_filename_checker/test/sample_for_test/dir_a1/duplicate_filename.sample
         
     | 
| 
      
 21 
     | 
    
         
            +
              #  * md5: 5258bf47639b8f906c1a17aee86c54dd
         
     | 
| 
      
 22 
     | 
    
         
            +
              #  * mtime: 2015-03-07 13:44:05 +0900
         
     | 
| 
      
 23 
     | 
    
         
            +
              #
         
     | 
| 
      
 24 
     | 
    
         
            +
              # 2. /Users/nagai_shinya/gem/duplicated_filename_checker/test/sample_for_test/dir_b1/dir_b2/duplicate_filename.sample
         
     | 
| 
      
 25 
     | 
    
         
            +
              #  * md5: 5258bf47639b8f906c1a17aee86c54dd
         
     | 
| 
      
 26 
     | 
    
         
            +
              #  * mtime: 2015-03-07 13:44:05 +0900
         
     | 
| 
      
 27 
     | 
    
         
            +
              def markdown
         
     | 
| 
      
 28 
     | 
    
         
            +
                duplicate_file_profiles_with_filter.map do |basename, duplicate_file_profiles|
         
     | 
| 
      
 29 
     | 
    
         
            +
                  [
         
     | 
| 
      
 30 
     | 
    
         
            +
                    "## #{basename}\n",
         
     | 
| 
      
 31 
     | 
    
         
            +
                    "#{file_profile_to_markdown(duplicate_file_profiles)}",
         
     | 
| 
      
 32 
     | 
    
         
            +
                  ]
         
     | 
| 
      
 33 
     | 
    
         
            +
                end.flatten.join
         
     | 
| 
      
 34 
     | 
    
         
            +
              end
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
              private
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
              def duplicate_file_profiles_with_filter
         
     | 
| 
      
 39 
     | 
    
         
            +
                unless @exclude_basename_regexp
         
     | 
| 
      
 40 
     | 
    
         
            +
                  return @duplicate_file_profiles
         
     | 
| 
      
 41 
     | 
    
         
            +
                end
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
                @duplicate_file_profiles.select do |basename, _|
         
     | 
| 
      
 44 
     | 
    
         
            +
                  !(basename =~ Regexp.new(@exclude_basename_regexp))
         
     | 
| 
      
 45 
     | 
    
         
            +
                end
         
     | 
| 
      
 46 
     | 
    
         
            +
              end
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
              def file_profile_to_markdown(duplicate_file_profiles)
         
     | 
| 
      
 49 
     | 
    
         
            +
                duplicate_file_profiles.map.with_index(1) do |file_profile, index|
         
     | 
| 
      
 50 
     | 
    
         
            +
                  [
         
     | 
| 
      
 51 
     | 
    
         
            +
                    "#{index}. #{file_profile.path}\n",
         
     | 
| 
      
 52 
     | 
    
         
            +
                    " * md5: #{file_profile.md5_digest}\n",
         
     | 
| 
      
 53 
     | 
    
         
            +
                    " * mtime: #{file_profile.stat.mtime}\n",
         
     | 
| 
      
 54 
     | 
    
         
            +
                    "\n"
         
     | 
| 
      
 55 
     | 
    
         
            +
                  ]
         
     | 
| 
      
 56 
     | 
    
         
            +
                end.join
         
     | 
| 
      
 57 
     | 
    
         
            +
              end
         
     | 
| 
      
 58 
     | 
    
         
            +
            end
         
     | 
| 
         
            File without changes
         
     | 
| 
         
            File without changes
         
     | 
    
        data/test/sample_for_test/dir_b1/dir_b2/{duplicate_filename.sample → duplicate_filename_1.sample}
    RENAMED
    
    | 
         
            File without changes
         
     | 
| 
         
            File without changes
         
     | 
    
        data/test/test_check.rb
    CHANGED
    
    | 
         @@ -1,28 +1,69 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'minitest_helper'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
               
     | 
| 
       5 
     | 
    
         
            -
                survey_dir_path_1 = './test/sample_for_test/dir_a1'
         
     | 
| 
       6 
     | 
    
         
            -
                survey_dir_path_2 = './test/sample_for_test/dir_b1'
         
     | 
| 
       7 
     | 
    
         
            -
                @sample_filename  = 'duplicate_filename.sample'
         
     | 
| 
      
 3 
     | 
    
         
            +
            describe DuplicatedFilenameChecker::Check do
         
     | 
| 
      
 4 
     | 
    
         
            +
              describe '#initialize' do
         
     | 
| 
       8 
5 
     | 
    
         | 
| 
       9 
     | 
    
         
            -
                 
     | 
| 
      
 6 
     | 
    
         
            +
                describe 'arguments no given.' do
         
     | 
| 
      
 7 
     | 
    
         
            +
                  it 'raise' do
         
     | 
| 
      
 8 
     | 
    
         
            +
                    assert_raises(ArgumentError){ DuplicatedFilenameChecker::Check.new }
         
     | 
| 
      
 9 
     | 
    
         
            +
                  end
         
     | 
| 
      
 10 
     | 
    
         
            +
                end
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                describe 'survey target  directory is no exists.' do
         
     | 
| 
      
 13 
     | 
    
         
            +
                  it 'raise' do
         
     | 
| 
      
 14 
     | 
    
         
            +
                    assert_raises(ArgumentError){ DuplicatedFilenameChecker::Check.new('/not_exists_dir') }
         
     | 
| 
      
 15 
     | 
    
         
            +
                  end
         
     | 
| 
      
 16 
     | 
    
         
            +
                end
         
     | 
| 
       10 
17 
     | 
    
         
             
              end
         
     | 
| 
       11 
18 
     | 
    
         | 
| 
       12 
     | 
    
         
            -
               
     | 
| 
       13 
     | 
    
         
            -
                 
     | 
| 
      
 19 
     | 
    
         
            +
              describe '#execute' do
         
     | 
| 
      
 20 
     | 
    
         
            +
                describe 'survey target has duplicate basename files' do
         
     | 
| 
      
 21 
     | 
    
         
            +
                  before do
         
     | 
| 
      
 22 
     | 
    
         
            +
                    survey_dir_path_1 = './test/sample_for_test/dir_a1'
         
     | 
| 
      
 23 
     | 
    
         
            +
                    survey_dir_path_2 = './test/sample_for_test/dir_b1'
         
     | 
| 
      
 24 
     | 
    
         
            +
                    @sample_filenames = ['duplicate_filename_1.sample', 'duplicate_filename_2.png']
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                    @check = DuplicatedFilenameChecker::Check.new(survey_dir_path_1, survey_dir_path_2)
         
     | 
| 
      
 27 
     | 
    
         
            +
                    @check_result = @check.execute
         
     | 
| 
      
 28 
     | 
    
         
            +
                  end
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                  it 'key is duplicate filename' do
         
     | 
| 
      
 31 
     | 
    
         
            +
                    assert @check_result.keys.any?{|basename| @sample_filenames.include? basename }
         
     | 
| 
      
 32 
     | 
    
         
            +
                  end
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                  describe 'value is duplicate file profiles' do
         
     | 
| 
      
 35 
     | 
    
         
            +
                    before do
         
     | 
| 
      
 36 
     | 
    
         
            +
                      @profiles = @check_result.values
         
     | 
| 
      
 37 
     | 
    
         
            +
                    end
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
                    it 'prfiles is DuplicatedFilenameChecker::FileProfile' do
         
     | 
| 
      
 40 
     | 
    
         
            +
                      @profiles.flatten.each do |path|
         
     | 
| 
      
 41 
     | 
    
         
            +
                        assert path.class == DuplicatedFilenameChecker::FileProfile
         
     | 
| 
      
 42 
     | 
    
         
            +
                      end
         
     | 
| 
      
 43 
     | 
    
         
            +
                    end
         
     | 
| 
       14 
44 
     | 
    
         | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
      
 45 
     | 
    
         
            +
                    it 'proflies.first all basename is same' do
         
     | 
| 
      
 46 
     | 
    
         
            +
                      @profiles.flatten.each do |path|
         
     | 
| 
      
 47 
     | 
    
         
            +
                        assert @sample_filenames.include? path.basename
         
     | 
| 
      
 48 
     | 
    
         
            +
                      end
         
     | 
| 
      
 49 
     | 
    
         
            +
                    end
         
     | 
| 
       16 
50 
     | 
    
         | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
      
 51 
     | 
    
         
            +
                    it 'proflies.first path is different' do
         
     | 
| 
      
 52 
     | 
    
         
            +
                      paths = @profiles.flatten.map(&:path)
         
     | 
| 
      
 53 
     | 
    
         
            +
                      assert paths == paths.uniq
         
     | 
| 
      
 54 
     | 
    
         
            +
                    end
         
     | 
| 
      
 55 
     | 
    
         
            +
                  end
         
     | 
| 
      
 56 
     | 
    
         
            +
                end
         
     | 
| 
       20 
57 
     | 
    
         | 
| 
       21 
     | 
    
         
            -
                 
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
      
 58 
     | 
    
         
            +
                describe 'survey target has not duplicate basename file' do
         
     | 
| 
      
 59 
     | 
    
         
            +
                  before do
         
     | 
| 
      
 60 
     | 
    
         
            +
                    @check = DuplicatedFilenameChecker::Check.new('./test/sample_for_test/dir_a1')
         
     | 
| 
      
 61 
     | 
    
         
            +
                    @check_result = @check.execute
         
     | 
| 
      
 62 
     | 
    
         
            +
                  end
         
     | 
| 
       23 
63 
     | 
    
         | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
      
 64 
     | 
    
         
            +
                  it 'result is empty hash' do
         
     | 
| 
      
 65 
     | 
    
         
            +
                    assert @check_result == {}
         
     | 
| 
      
 66 
     | 
    
         
            +
                  end
         
     | 
| 
      
 67 
     | 
    
         
            +
                end
         
     | 
| 
       27 
68 
     | 
    
         
             
              end
         
     | 
| 
       28 
69 
     | 
    
         
             
            end
         
     | 
    
        data/test/test_file_profile.rb
    CHANGED
    
    | 
         @@ -2,7 +2,7 @@ require 'minitest_helper' 
     | 
|
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            class TestFileProfile < MiniTest::Unit::TestCase
         
     | 
| 
       4 
4 
     | 
    
         
             
              def setup
         
     | 
| 
       5 
     | 
    
         
            -
                @sample_filename      = ' 
     | 
| 
      
 5 
     | 
    
         
            +
                @sample_filename      = 'duplicate_filename_1.sample'
         
     | 
| 
       6 
6 
     | 
    
         
             
                @sample_relative_path = File.join('./test/sample_for_test/dir_a1/', @sample_filename)
         
     | 
| 
       7 
7 
     | 
    
         
             
                @sample_fullpath      = File.join(test_fullpath, 'sample_for_test/dir_a1/', @sample_filename)
         
     | 
| 
       8 
8 
     | 
    
         
             
                @sample_md5_digest    = '5258bf47639b8f906c1a17aee86c54dd'
         
     | 
| 
         @@ -0,0 +1,54 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'minitest_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            describe DuplicatedFilenameChecker::Formatter do
         
     | 
| 
      
 4 
     | 
    
         
            +
              before do
         
     | 
| 
      
 5 
     | 
    
         
            +
                survey_dir_path_1 = './test/sample_for_test/dir_a1'
         
     | 
| 
      
 6 
     | 
    
         
            +
                survey_dir_path_2 = './test/sample_for_test/dir_b1'
         
     | 
| 
      
 7 
     | 
    
         
            +
                @sample_filename  = 'duplicate_filename_1.sample'
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                @check_result = DuplicatedFilenameChecker::Check.new(survey_dir_path_1, survey_dir_path_2).execute
         
     | 
| 
      
 10 
     | 
    
         
            +
                @formatter = DuplicatedFilenameChecker::Formatter.new(@check_result)
         
     | 
| 
      
 11 
     | 
    
         
            +
              end
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
              describe '#hash' do
         
     | 
| 
      
 14 
     | 
    
         
            +
                it 'like plain result' do
         
     | 
| 
      
 15 
     | 
    
         
            +
                  assert @formatter.hash == @check_result
         
     | 
| 
      
 16 
     | 
    
         
            +
                end
         
     | 
| 
      
 17 
     | 
    
         
            +
              end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
              describe '#only_basename' do
         
     | 
| 
      
 20 
     | 
    
         
            +
                it 'show only basenames' do
         
     | 
| 
      
 21 
     | 
    
         
            +
                  assert @formatter.only_basename.sort == ['duplicate_filename_1.sample', 'duplicate_filename_2.png'].sort
         
     | 
| 
      
 22 
     | 
    
         
            +
                end
         
     | 
| 
      
 23 
     | 
    
         
            +
              end
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
              describe '#markdown' do
         
     | 
| 
      
 26 
     | 
    
         
            +
                it 'first line has ##' do
         
     | 
| 
      
 27 
     | 
    
         
            +
                  first_line = @formatter.markdown.split("\n")[0]
         
     | 
| 
      
 28 
     | 
    
         
            +
                  assert first_line =~ /##/
         
     | 
| 
      
 29 
     | 
    
         
            +
                end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                it 'first line has basname' do
         
     | 
| 
      
 32 
     | 
    
         
            +
                  first_line = @formatter.markdown.split("\n")[0]
         
     | 
| 
      
 33 
     | 
    
         
            +
                  puts @formatter.markdown
         
     | 
| 
      
 34 
     | 
    
         
            +
                  assert first_line =~ /#{@sample_filename}/
         
     | 
| 
      
 35 
     | 
    
         
            +
                end
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
                it 'second line has path' do
         
     | 
| 
      
 38 
     | 
    
         
            +
                  second_line = @formatter.markdown.split("\n")[1]
         
     | 
| 
      
 39 
     | 
    
         
            +
                  duplicate_file_list = @check_result.values.first
         
     | 
| 
      
 40 
     | 
    
         
            +
                  assert duplicate_file_list.any?{|file| second_line =~ /#{file.path}/ }
         
     | 
| 
      
 41 
     | 
    
         
            +
                end
         
     | 
| 
      
 42 
     | 
    
         
            +
              end
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
              describe '#exclude_basename' do
         
     | 
| 
      
 45 
     | 
    
         
            +
                before do
         
     | 
| 
      
 46 
     | 
    
         
            +
                  @formatter.exclude_basename('.sample')
         
     | 
| 
      
 47 
     | 
    
         
            +
                end
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
                it 'ignored specified basename' do
         
     | 
| 
      
 50 
     | 
    
         
            +
                  assert @formatter.only_basename == ['duplicate_filename_2.png']
         
     | 
| 
      
 51 
     | 
    
         
            +
                  assert @formatter.hash.keys == ['duplicate_filename_2.png']
         
     | 
| 
      
 52 
     | 
    
         
            +
                end
         
     | 
| 
      
 53 
     | 
    
         
            +
              end
         
     | 
| 
      
 54 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: duplicated_filename_checker
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.3.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Shinya131
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2015-03- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2015-03-07 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: bundler
         
     | 
| 
         @@ -73,12 +73,16 @@ files: 
     | 
|
| 
       73 
73 
     | 
    
         
             
            - lib/duplicated_filename_checker.rb
         
     | 
| 
       74 
74 
     | 
    
         
             
            - lib/duplicated_filename_checker/check.rb
         
     | 
| 
       75 
75 
     | 
    
         
             
            - lib/duplicated_filename_checker/file_profile.rb
         
     | 
| 
      
 76 
     | 
    
         
            +
            - lib/duplicated_filename_checker/formatter.rb
         
     | 
| 
       76 
77 
     | 
    
         
             
            - lib/duplicated_filename_checker/version.rb
         
     | 
| 
       77 
78 
     | 
    
         
             
            - test/minitest_helper.rb
         
     | 
| 
       78 
     | 
    
         
            -
            - test/sample_for_test/dir_a1/ 
     | 
| 
       79 
     | 
    
         
            -
            - test/sample_for_test/ 
     | 
| 
      
 79 
     | 
    
         
            +
            - test/sample_for_test/dir_a1/duplicate_filename_1.sample
         
     | 
| 
      
 80 
     | 
    
         
            +
            - test/sample_for_test/dir_a1/duplicate_filename_2.png
         
     | 
| 
      
 81 
     | 
    
         
            +
            - test/sample_for_test/dir_b1/dir_b2/duplicate_filename_1.sample
         
     | 
| 
      
 82 
     | 
    
         
            +
            - test/sample_for_test/dir_b1/dir_b2/duplicate_filename_2.png
         
     | 
| 
       80 
83 
     | 
    
         
             
            - test/test_check.rb
         
     | 
| 
       81 
84 
     | 
    
         
             
            - test/test_file_profile.rb
         
     | 
| 
      
 85 
     | 
    
         
            +
            - test/test_formatter.rb
         
     | 
| 
       82 
86 
     | 
    
         
             
            homepage: https://github.com/Shinya131/duplicated_filename_checker
         
     | 
| 
       83 
87 
     | 
    
         
             
            licenses:
         
     | 
| 
       84 
88 
     | 
    
         
             
            - MIT
         
     | 
| 
         @@ -105,7 +109,10 @@ specification_version: 4 
     | 
|
| 
       105 
109 
     | 
    
         
             
            summary: This gem is check duplicated filename in multiple directory.
         
     | 
| 
       106 
110 
     | 
    
         
             
            test_files:
         
     | 
| 
       107 
111 
     | 
    
         
             
            - test/minitest_helper.rb
         
     | 
| 
       108 
     | 
    
         
            -
            - test/sample_for_test/dir_a1/ 
     | 
| 
       109 
     | 
    
         
            -
            - test/sample_for_test/ 
     | 
| 
      
 112 
     | 
    
         
            +
            - test/sample_for_test/dir_a1/duplicate_filename_1.sample
         
     | 
| 
      
 113 
     | 
    
         
            +
            - test/sample_for_test/dir_a1/duplicate_filename_2.png
         
     | 
| 
      
 114 
     | 
    
         
            +
            - test/sample_for_test/dir_b1/dir_b2/duplicate_filename_1.sample
         
     | 
| 
      
 115 
     | 
    
         
            +
            - test/sample_for_test/dir_b1/dir_b2/duplicate_filename_2.png
         
     | 
| 
       110 
116 
     | 
    
         
             
            - test/test_check.rb
         
     | 
| 
       111 
117 
     | 
    
         
             
            - test/test_file_profile.rb
         
     | 
| 
      
 118 
     | 
    
         
            +
            - test/test_formatter.rb
         
     |