irep 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 3c63f5fea943cedefdde0959f35b308e3779e124
4
- data.tar.gz: ffaa7b26938f4aea6107b1a9b44be17fb62b9b21
2
+ SHA256:
3
+ metadata.gz: 99ca2f7b8ade7f67206c47740c76be56a28f630dff2c85ca256f77742479f099
4
+ data.tar.gz: a7c9a50bc0a1d50ddc15107d9d33bfe819d331bea51777a5f43e5a58a8a87e37
5
5
  SHA512:
6
- metadata.gz: 764d0c1932a8eadceffb5bdeff0d5459784c1a35f3095ce9cffda1546423bf42bfbd3d523620371933f188b93ffa5c3dd4d4bcb14ab53fe39001eee956e208ee
7
- data.tar.gz: 0c0835d41a0624e3bb8bc1f626dc7d6628817121512fd90e7410973c544f80458aea05a852ac60c42b39fc0217b13b2797877d6a25767942d642770037118781
6
+ metadata.gz: 4259d16d22489a3612974158b0d3d25dbd4951db594f701950c125cd0426c9c12a58082cc8bec1c2320acc633c639f0de79465a790f5900216f11c28a4f56153
7
+ data.tar.gz: 9ac2ba1196844636be08bbe1977542ce69457655f10fd43b06822ca0f40024f14ea1f361157897dcd832a51bed749fa370ec2d37eaea59a4aa9888df34c2adad
@@ -0,0 +1 @@
1
+ 2.6.3
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'irep'
5
+
6
+ Irep::CLI.execute(STDOUT, ARGV)
@@ -7,7 +7,6 @@ Gem::Specification.new do |spec|
7
7
  spec.name = "irep"
8
8
  spec.version = Irep::VERSION
9
9
  spec.authors = ["motoki-shun"]
10
- spec.email = ["shuuuuuny@gmail.com"]
11
10
 
12
11
  spec.summary = 'A code searching and interactive replacing tool on CLI.'
13
12
  spec.homepage = 'https://github.com/shuuuuun/irep'
@@ -27,10 +26,10 @@ Gem::Specification.new do |spec|
27
26
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
27
  spec.require_paths = ["lib"]
29
28
 
30
- spec.add_development_dependency "bundler", "~> 1.14"
31
- spec.add_development_dependency "rake", "~> 10.0"
32
- spec.add_development_dependency 'test-unit'
33
- spec.add_development_dependency 'test-unit-rr'
29
+ spec.add_development_dependency 'bundler', '~> 2.0'
30
+ spec.add_development_dependency 'rake', '~> 12.3'
31
+ spec.add_development_dependency 'test-unit', '~> 3.3'
32
+ spec.add_development_dependency 'test-unit-rr', '~> 1.0'
34
33
  spec.add_development_dependency 'pry'
35
34
 
36
35
  spec.add_dependency 'rainbow'
@@ -7,7 +7,9 @@ require 'irep/interface'
7
7
  module Irep
8
8
  class CLI
9
9
  def self.execute(stdout, argv = [])
10
+ # TODO: 引数が3つのときは最後をpathとして処理したい
10
11
  opts, args = parse_options argv
12
+
11
13
  # TODO: implement log level
12
14
  # Interface.debug "argv: #{argv}"
13
15
  # Interface.debug "opts: #{opts}"
@@ -28,7 +30,7 @@ module Irep
28
30
  search.show_results
29
31
  exit
30
32
  end
31
- Replace.replace_by_search_results_interactively search.results, search_text, replace_text
33
+ Replace.replace_interactively search.results, search_text, replace_text
32
34
  end
33
35
 
34
36
  private
@@ -2,10 +2,13 @@ require 'rainbow'
2
2
 
3
3
  module Irep
4
4
  class Interface
5
+ attr_reader :apply_all_flag
6
+
5
7
  def initialize(cases: [], message:)
6
8
  @cases = cases
7
9
  @message = message
8
10
  @quit = false
11
+ @apply_all_flag = false
9
12
  end
10
13
 
11
14
  def listen(opts = {})
@@ -34,6 +37,11 @@ module Irep
34
37
  @quit = true
35
38
  end
36
39
 
40
+ def apply_all
41
+ @apply_all_flag = true
42
+ @quit = true
43
+ end
44
+
37
45
  def self.get_input
38
46
  STDIN.gets.chomp
39
47
  end
@@ -4,33 +4,30 @@ module Irep
4
4
  module Replace
5
5
  extend self
6
6
 
7
- def replace_by_search_results(search_results, search_text, replace_text)
8
- # TODO: replace_by_search_results
9
- end
7
+ # TODO: replace_immediately
8
+ # def replace_immediately(search_results, search_text, replace_text)
9
+ # end
10
10
 
11
- def replace_by_search_results_interactively(search_results, search_text, replace_text)
11
+ def replace_interactively(search_results, search_text, replace_text)
12
12
  search_results.each do |result|
13
13
  next unless result[:preview]
14
14
  result[:result_preview] = result[:preview].gsub(search_text, replace_text)
15
15
  end
16
16
  listened_results = listen_if_replace(search_results)
17
- replace_in_file_by_results listened_results.select { |r| r[:type] == 'in_file' }, search_text, replace_text
18
- listened_results.select { |r| r[:type] == 'filename' || r[:type] == 'directory' }.each do |result|
17
+ replace_in_file listened_results.select { |r| r[:type] == Search::MatchType::IN_FILE }, search_text, replace_text
18
+ listened_results.select { |r| r[:type] == Search::MatchType::FILENAME || r[:type] == Search::MatchType::DIRECTORY }.each do |result|
19
19
  next unless result[:should_replace]
20
20
  rename_path result[:path], search_text, replace_text
21
21
  end
22
22
  end
23
23
 
24
- def rename_path(path, before, after)
25
- File.rename path, path.gsub(before, after)
26
- end
27
-
28
- def replace_in_file(file_path, before, after='')
29
- txt = File.read(file_path).gsub(before, after)
30
- File.write(file_path, txt)
31
- end
24
+ # TODO: replace_in_file 消してもいいかも
25
+ # def replace_in_file(file_path, before, after='')
26
+ # txt = File.read(file_path).gsub(before, after)
27
+ # File.write(file_path, txt)
28
+ # end
32
29
 
33
- def replace_in_file_by_results(search_results, search_text, replace_text)
30
+ def replace_in_file(search_results, search_text, replace_text)
34
31
  grouped_results = search_results.group_by { |r| r[:path] }
35
32
  grouped_results.each do |path, results|
36
33
  file_text = File.read(path)
@@ -52,6 +49,10 @@ module Irep
52
49
 
53
50
  private
54
51
 
52
+ def rename_path(path, before, after)
53
+ File.rename path, path.gsub(before, after)
54
+ end
55
+
55
56
  def listen_if_replace(results)
56
57
  interface = Interface.new(message: 'Replace', cases: [{
57
58
  cmd: 'y',
@@ -72,7 +73,7 @@ module Irep
72
73
  cmd: 'a',
73
74
  help: 'all, Apply all replacement after this.',
74
75
  func: proc {
75
- # TODO
76
+ interface.apply_all
76
77
  }
77
78
  # }, {
78
79
  # cmd: 'h',
@@ -94,6 +95,7 @@ module Irep
94
95
  result_preview: result[:result_preview],
95
96
  proc_args: [result]
96
97
  )
98
+ result[:should_replace] = true if interface.apply_all_flag
97
99
  end
98
100
  results
99
101
  end
@@ -2,6 +2,13 @@ require 'irep/interface'
2
2
 
3
3
  module Irep
4
4
  class Search
5
+ module MatchType
6
+ DIRECTORY = 0
7
+ FILENAME = 1
8
+ IN_FILE = 2
9
+ end
10
+
11
+ # TODO: make Result class.
5
12
  attr_reader :results
6
13
 
7
14
  def initialize(opts = {})
@@ -17,7 +24,7 @@ module Irep
17
24
  end
18
25
  current_results = match_dir_list.map do |path|
19
26
  {
20
- type: 'directory',
27
+ type: MatchType::DIRECTORY,
21
28
  path: path,
22
29
  preview: path,
23
30
  }
@@ -31,7 +38,7 @@ module Irep
31
38
  end
32
39
  current_results = match_file_list.map do |path|
33
40
  {
34
- type: 'filename',
41
+ type: MatchType::FILENAME,
35
42
  path: path,
36
43
  preview: path,
37
44
  }
@@ -58,7 +65,7 @@ module Irep
58
65
  line_num = match_line_num(file_text, match_data)
59
66
  {
60
67
  match_data: match_data,
61
- type: 'in_file', # in_file, directory, filename
68
+ type: MatchType::IN_FILE,
62
69
  path: file_path, # 'path/to/file_or_directory'
63
70
  offset: match_data.begin(0), # x 全体の何文字目か
64
71
  line: line_num, # y, row 行数
@@ -1,3 +1,3 @@
1
1
  module Irep
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: irep
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - motoki-shun
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-07-29 00:00:00.000000000 Z
11
+ date: 2019-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,56 +16,56 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.14'
19
+ version: '2.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.14'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '12.3'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '12.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: test-unit
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '3.3'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '3.3'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: test-unit-rr
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '1.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: '1.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: pry
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -95,8 +95,7 @@ dependencies:
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  description:
98
- email:
99
- - shuuuuuny@gmail.com
98
+ email:
100
99
  executables:
101
100
  - irep
102
101
  extensions: []
@@ -104,10 +103,12 @@ extra_rdoc_files: []
104
103
  files:
105
104
  - ".commit_template"
106
105
  - ".gitignore"
106
+ - ".ruby-version"
107
107
  - Gemfile
108
108
  - README.md
109
109
  - Rakefile
110
110
  - bin/console
111
+ - bin/irep
111
112
  - bin/setup
112
113
  - bin/show_rainbow_colors
113
114
  - exe/irep
@@ -138,8 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
139
  - !ruby/object:Gem::Version
139
140
  version: '0'
140
141
  requirements: []
141
- rubyforge_project:
142
- rubygems_version: 2.6.11
142
+ rubygems_version: 3.0.3
143
143
  signing_key:
144
144
  specification_version: 4
145
145
  summary: A code searching and interactive replacing tool on CLI.