rename_gem 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d5dc142f3588040cd30fc17ace93061f6564834d7c6b00db6d600d4f7d9ab2a6
4
- data.tar.gz: ff6248367664d2fbe2ee4134bc3d980776d1267008defc86cd997a4fcccc2e00
3
+ metadata.gz: d94c4504bc60d9df94db95f491c1c305504b62ccdbe81b855d7e5239423a41a8
4
+ data.tar.gz: 2aaaab3e85bb4fd5be9a83d91dced99f44f2b2deb418ad4bb87944c3ca5f8efe
5
5
  SHA512:
6
- metadata.gz: bdfa2e938d229eaa87365ce1ba9c06fc91ab060f9ef80f058165d3d8da4aae12211a6a7c1118735f41739286dd847b4bc8b19fb67b5e9e4e02033c3b90c6db20
7
- data.tar.gz: 57bce7a0effb78b67452bcb00225903667ec4bc3fa4a52d6a2f4c933a5b949c8f971a858739d4387fac4a3652c9fb621fa2da2f6d09af23d7d3b56225e16bd90
6
+ metadata.gz: 31827b02f7039de9904e09b0414956184e5854a36e194354478fb14eba3701cc1da6a2efd812270b5533e1cc9c1f7171a22e84c435c7a396daf92db52dad26f2
7
+ data.tar.gz: b3066e038a12fcf962418c29b43c4960aac1d37342bfdfd57433f7c2e78910788c625ec60d998eaf998fdc0fc78256cd017265636a9df317f29cca3be70f3419
@@ -3,6 +3,8 @@
3
3
  module RenameGem
4
4
  module Renamer
5
5
  class DirectoryHandler
6
+ EXCLUDED_DIRS = ['.git'].freeze
7
+
6
8
  attr_reader :name, :new_name
7
9
 
8
10
  def initialize(name, new_name)
@@ -16,9 +18,15 @@ module RenameGem
16
18
  directory.directories.each do |sub_directory|
17
19
  sub_directory.change(name).to(new_name)
18
20
 
19
- recurse!(sub_directory)
21
+ recurse!(sub_directory) unless excluded_directory?(sub_directory)
20
22
  end
21
23
  end
24
+
25
+ private
26
+
27
+ def excluded_directory?(dir)
28
+ EXCLUDED_DIRS.include? dir.path.filename
29
+ end
22
30
  end
23
31
  end
24
32
  end
@@ -24,6 +24,7 @@ module RenameGem
24
24
 
25
25
  validate_chaining
26
26
 
27
+ file_handler.change(modifier) if path.file?
27
28
  rename
28
29
  end
29
30
 
@@ -44,16 +45,11 @@ module RenameGem
44
45
  def rename
45
46
  new_path = path.build(modifier.replacement(path.filename)).to_s
46
47
 
47
- unless path.to_s == new_path
48
- file_handler.change(modifier) if path.file?
48
+ path.rename(new_path)
49
49
 
50
- path.rename(new_path)
51
- puts "rename #{path} to #{new_path}"
52
-
53
- modifier = Modifier.new
54
- end
50
+ modifier = Modifier.new
55
51
  rescue Modifier::ReplacementNotFound => e
56
- puts "ignoring #{e.message}"
52
+ # nothing
57
53
  end
58
54
 
59
55
  def validate_chaining
@@ -5,12 +5,13 @@ module RenameGem
5
5
  require 'tempfile'
6
6
 
7
7
  class FileHandler
8
- attr_reader :path, :file, :possession
8
+ attr_reader :path, :file, :possession, :changes
9
9
 
10
10
  def initialize(path)
11
11
  @path = path
12
12
  @file = File.new(path.to_s)
13
13
  @possession = Possession.new(file)
14
+ @changes = false
14
15
  end
15
16
 
16
17
  def change(modifier)
@@ -18,17 +19,20 @@ module RenameGem
18
19
 
19
20
  file.each_line do |line|
20
21
  temp_file.puts modifier.replacement(line)
22
+ @changes = true
21
23
  rescue Modifier::ReplacementNotFound
22
24
  temp_file.puts line
23
25
  end
24
26
 
25
27
  temp_file.close
26
- FileUtils.mv(temp_file.path, path.to_s) if modifier.times_replaced.positive?
27
- temp_file.unlink
28
28
 
29
- possession.update(file)
29
+ if @changes
30
+ FileUtils.mv(temp_file.path, path.to_s)
31
+ possession.update(file)
32
+ puts "Edit #{path}"
33
+ end
30
34
 
31
- puts "#{modifier.times_replaced} lines changed in #{path}"
35
+ temp_file.unlink
32
36
  end
33
37
  end
34
38
  end
@@ -6,12 +6,10 @@ module RenameGem
6
6
  ReplacementNotFound = Class.new(StandardError)
7
7
 
8
8
  attr_accessor :from, :to
9
- attr_reader :times_replaced
10
9
 
11
10
  def initialize(from = nil, to = nil)
12
11
  @from = from
13
12
  @to = to
14
- @times_replaced = 0
15
13
  end
16
14
 
17
15
  def valid?
@@ -22,10 +20,8 @@ module RenameGem
22
20
 
23
21
  def replacement(string)
24
22
  replacer = StringReplacer.new(string)
25
- content = replacer.replace(from).with(to)
26
- @times_replaced += 1
27
23
 
28
- content
24
+ replacer.replace(from).with(to)
29
25
  rescue StringReplacer::NoMatchError => e
30
26
  raise ReplacementNotFound, e.message
31
27
  end
@@ -44,6 +44,7 @@ module RenameGem
44
44
  raise RenameError, "#{self} must be a file or a directory"
45
45
  end
46
46
 
47
+ puts "Rename #{self} -> #{self.class.new(new_path).filename}"
47
48
  @pathname = Pathname.new(new_path)
48
49
  end
49
50
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RenameGem
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rename_gem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rónán Duddy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-12-11 00:00:00.000000000 Z
11
+ date: 2020-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor