regren 0.0.4 → 0.0.5
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.
- data/bin/regren +3 -2
- data/lib/filename_history.rb +15 -3
- data/lib/folder_contents_history.rb +5 -5
- metadata +18 -12
- checksums.yaml +0 -7
data/bin/regren
CHANGED
@@ -5,10 +5,11 @@ $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
|
|
5
5
|
require 'optparse'
|
6
6
|
require 'folder_contents_history'
|
7
7
|
require 'filename_history'
|
8
|
+
require 'colorize'
|
8
9
|
|
9
10
|
def string_prompt(prompt = '>')
|
10
11
|
begin
|
11
|
-
print("#{prompt} ")
|
12
|
+
print("#{prompt} ".colorize(:color => :green))
|
12
13
|
gets.chomp
|
13
14
|
rescue Interrupt
|
14
15
|
exit 130
|
@@ -90,7 +91,7 @@ when :rename
|
|
90
91
|
when :reapply
|
91
92
|
history.plan_reapplication('.')
|
92
93
|
end
|
93
|
-
history.log unless options[:quiet]
|
94
|
+
history.log(options[:regexp], options[:replacement]) unless options[:quiet]
|
94
95
|
unless options[:dry_run] || options[:mode] == :history
|
95
96
|
if !history.changed.empty? && prompt?('Execute the rename?', options)
|
96
97
|
history.log_backup(options[:history_file]) if options[:backup]
|
data/lib/filename_history.rb
CHANGED
@@ -31,7 +31,11 @@ class FileNameHistory
|
|
31
31
|
|
32
32
|
def plan_rename(regexp, replacement)
|
33
33
|
new_name = @current.gsub(regexp, replacement)
|
34
|
-
|
34
|
+
if new_name != current
|
35
|
+
@current_color = @current.gsub(regexp, '\0'.colorize(:color => :green))
|
36
|
+
@last_color = @current.gsub(regexp, replacement.colorize(:color => :cyan))
|
37
|
+
@history << new_name
|
38
|
+
end
|
35
39
|
end
|
36
40
|
|
37
41
|
def plan_rollback
|
@@ -60,9 +64,17 @@ class FileNameHistory
|
|
60
64
|
where.print "-> #{@history.join("\n-> ")}\n\n"
|
61
65
|
end
|
62
66
|
|
67
|
+
def last_color
|
68
|
+
@last_color || last_name
|
69
|
+
end
|
70
|
+
|
71
|
+
def current_color
|
72
|
+
@current_color || @current
|
73
|
+
end
|
74
|
+
|
63
75
|
def log(where = $stdout)
|
64
76
|
return unless changed?
|
65
|
-
where.puts(
|
66
|
-
where.puts("-> #{
|
77
|
+
where.puts(current_color)
|
78
|
+
where.puts("-> #{last_color}")
|
67
79
|
end
|
68
80
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
class FolderContentsHistory
|
2
|
-
require '
|
2
|
+
require 'multi_json'
|
3
3
|
|
4
4
|
def initialize(entries = {})
|
5
5
|
@entries = entries
|
@@ -51,9 +51,9 @@ class FolderContentsHistory
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
def log
|
54
|
+
def log(regexp = '', replacement = '')
|
55
55
|
if conflicts?
|
56
|
-
puts <<-NOTE.gsub(/^.*\|/, '')
|
56
|
+
puts <<-NOTE.gsub(/^.*\|/, '').colorize(:color => :red)
|
57
57
|
|==================================================
|
58
58
|
|!!! Some files would be lost by this operation !!!
|
59
59
|
|==================================================
|
@@ -70,7 +70,7 @@ class FolderContentsHistory
|
|
70
70
|
backup = with_history.reduce({}) do |hash, item|
|
71
71
|
hash.update(item.last.to_hash)
|
72
72
|
end
|
73
|
-
File.write(where,
|
73
|
+
File.write(where, MultiJson.dump(backup, :pretty => true))
|
74
74
|
end
|
75
75
|
|
76
76
|
def to_hash(input_hash = @entries)
|
@@ -98,7 +98,7 @@ class FolderContentsHistory
|
|
98
98
|
end
|
99
99
|
|
100
100
|
def self.new_from_history(history_file)
|
101
|
-
entries =
|
101
|
+
entries = MultiJson.load(File.read(history_file)).reduce({}) do |hash, item|
|
102
102
|
hash.update(item.first => FileNameHistory.new_from_history(item.last))
|
103
103
|
end
|
104
104
|
FolderContentsHistory.new(entries)
|
metadata
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: regren
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Adam Ruzicka
|
@@ -11,37 +12,41 @@ cert_chain: []
|
|
11
12
|
date: 2014-06-28 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
15
|
+
name: multi_json
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
16
18
|
requirements:
|
17
19
|
- - ~>
|
18
20
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
21
|
+
version: 1.10.1
|
20
22
|
type: :runtime
|
21
23
|
prerelease: false
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
23
26
|
requirements:
|
24
27
|
- - ~>
|
25
28
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
29
|
+
version: 1.10.1
|
27
30
|
- !ruby/object:Gem::Dependency
|
28
31
|
name: minitest
|
29
32
|
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
30
34
|
requirements:
|
31
35
|
- - ~>
|
32
36
|
- !ruby/object:Gem::Version
|
33
37
|
version: '1.3'
|
34
|
-
- - '>='
|
38
|
+
- - ! '>='
|
35
39
|
- !ruby/object:Gem::Version
|
36
40
|
version: 4.7.3
|
37
41
|
type: :development
|
38
42
|
prerelease: false
|
39
43
|
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
40
45
|
requirements:
|
41
46
|
- - ~>
|
42
47
|
- !ruby/object:Gem::Version
|
43
48
|
version: '1.3'
|
44
|
-
- - '>='
|
49
|
+
- - ! '>='
|
45
50
|
- !ruby/object:Gem::Version
|
46
51
|
version: 4.7.3
|
47
52
|
description: A simple gem for batch renaming files
|
@@ -52,32 +57,33 @@ extensions: []
|
|
52
57
|
extra_rdoc_files: []
|
53
58
|
files:
|
54
59
|
- bin/regren
|
55
|
-
- lib/folder_contents_history.rb
|
56
60
|
- lib/filename_history.rb
|
61
|
+
- lib/folder_contents_history.rb
|
57
62
|
- test/filename_history_test.rb
|
58
63
|
- test/folder_contents_history_test.rb
|
59
64
|
homepage: https://github.com/adamruzicka/regren
|
60
65
|
licenses:
|
61
66
|
- MIT
|
62
|
-
metadata: {}
|
63
67
|
post_install_message:
|
64
68
|
rdoc_options: []
|
65
69
|
require_paths:
|
66
70
|
- lib
|
67
71
|
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
68
73
|
requirements:
|
69
|
-
- - '>='
|
74
|
+
- - ! '>='
|
70
75
|
- !ruby/object:Gem::Version
|
71
76
|
version: 1.9.2
|
72
77
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
73
79
|
requirements:
|
74
|
-
- - '>='
|
80
|
+
- - ! '>='
|
75
81
|
- !ruby/object:Gem::Version
|
76
82
|
version: '0'
|
77
83
|
requirements: []
|
78
84
|
rubyforge_project:
|
79
|
-
rubygems_version:
|
85
|
+
rubygems_version: 1.8.25
|
80
86
|
signing_key:
|
81
|
-
specification_version:
|
87
|
+
specification_version: 3
|
82
88
|
summary: regren
|
83
89
|
test_files: []
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: b37b7b976a4778f6d1bd4c6a4e400f596c7ddb0b
|
4
|
-
data.tar.gz: d3574cf7d20b64e468f0db47acf5033f228ec1cf
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: f6553b71b3311525b6699cc5b31f94cd231a43939346b386489962d6036fcc77f47deba2b4c118514f4cc76222454182af289b9186bfd8eadb566a0c7a18d82b
|
7
|
-
data.tar.gz: f723d1200a3be1e993aef3c7c8e75f8d0ade430352a987a1e72bd615d95c7d653221c905963abe9fc4abb275af9afbef86459b62decd1bf9967587612fbfecf4
|