copy_tuner_incompatible_search 0.1.4 → 0.1.5

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
2
  SHA256:
3
- metadata.gz: 8e0d80ab1633aaac8dce000b96a11d5d7c7a133f5b07c241ba1426178b4f9d63
4
- data.tar.gz: ac0e9f7149cb519a9a4ad23b45db1c17cbe0b008c278c5a09821e74190f01876
3
+ metadata.gz: 6bf1eb19d25dd77c7a6bfd5f190f2ae6d2528290a4e4aa738694a8472177420d
4
+ data.tar.gz: 1b8e382f5cf7b855b3676981ca01fda08e141b4b217679eb6580b9b3797f534b
5
5
  SHA512:
6
- metadata.gz: 115e471c21e4d4832209b9cfbae972dd0c648fb8cfc46ed2d385bc8a2f0a17fb6475827491bcf24b7b633e2f95523e6153a1dc56b4e371dae86d2024bdf452d1
7
- data.tar.gz: e52b3f4e1c912665375985e09ed6def6055d6625567c478977c244408dffeade150bccea1c17e57199f5efde70e8fcd786382d98b0a75aab719a19ff220decac
6
+ metadata.gz: 4f6a71993756a555c2d1fb1419c2a7fd08ce9deba72f99f604e68eae718afbcfe4388dc1f63f4aec77db29a27cfe866b8a5e92602740467b0c1c8fcb6781d10e
7
+ data.tar.gz: f86654919bc9399476f88bbe63d753f1d400a7c6ff4c2692c50014e9c574d35b25825f74d96b0d2a73d47ef0b47fdbd3fda7264e302cf4c3903d563e919eb7de
data/.rubocop.yml CHANGED
@@ -1,11 +1,11 @@
1
- AllCops:
2
- NewCops: enable
3
- inherit_gem:
4
- sgcop: ruby/rubocop.yml
5
1
  require:
6
2
  - rubocop-rake
7
3
  - rubocop-rspec
4
+ inherit_gem:
5
+ sgcop: ruby/rubocop.yml
8
6
 
7
+ AllCops:
8
+ NewCops: enable
9
9
  Bundler/GemComment:
10
10
  Enabled: false
11
11
  RSpec/DescribedClass:
data/CHANGELOG.md CHANGED
@@ -1,4 +1,7 @@
1
1
  ## [Unreleased]
2
+ ## [0.1.5] - 2024-04-28
3
+
4
+ - Refactor the code
2
5
 
3
6
  ## [0.1.0] - 2024-04-27
4
7
 
data/README.md CHANGED
@@ -1,24 +1,24 @@
1
- # CopyTunerIncompatibleSearch
1
+ ![](https://github.com/JunichiIto/copy_tuner_incompatible_search/actions/workflows/rspec.yml/badge.svg)
2
+ ![](https://github.com/JunichiIto/copy_tuner_incompatible_search/actions/workflows/rubocop.yml/badge.svg)
3
+ ![](https://github.com/JunichiIto/copy_tuner_incompatible_search/actions/workflows/steep.yml/badge.svg)
2
4
 
3
- TODO: Delete this and the text below, and describe your gem
5
+ # CopyTunerIncompatibleSearch
4
6
 
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/copy_tuner_incompatible_search`. To experiment with that code, run `bin/console` for an interactive prompt.
7
+ Search usage of incompatible keys in CopyTuner.
6
8
 
7
9
  ## Installation
8
10
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
-
11
11
  Install the gem and add to the application's Gemfile by executing:
12
12
 
13
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
13
+ $ bundle add copy_tuner_incompatible_search
14
14
 
15
15
  If bundler is not being used to manage dependencies, install the gem by executing:
16
16
 
17
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
17
+ $ gem install copy_tuner_incompatible_search
18
18
 
19
19
  ## Usage
20
20
 
21
- TODO: Write usage instructions here
21
+ copy_tuner_incompatible_search
22
22
 
23
23
  ## Development
24
24
 
@@ -28,7 +28,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
28
28
 
29
29
  ## Contributing
30
30
 
31
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/copy_tuner_incompatible_search. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/copy_tuner_incompatible_search/blob/main/CODE_OF_CONDUCT.md).
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/JunichiIto/copy_tuner_incompatible_search. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/copy_tuner_incompatible_search/blob/main/CODE_OF_CONDUCT.md).
32
32
 
33
33
  ## License
34
34
 
data/Steepfile ADDED
@@ -0,0 +1,33 @@
1
+ # D = Steep::Diagnostic
2
+ #
3
+ # target :lib do
4
+ # signature "sig"
5
+ #
6
+ # check "lib" # Directory name
7
+ # check "Gemfile" # File name
8
+ # check "app/models/**/*.rb" # Glob
9
+ # # ignore "lib/templates/*.rb"
10
+ #
11
+ # # library "pathname" # Standard libraries
12
+ # # library "strong_json" # Gems
13
+ #
14
+ # # configure_code_diagnostics(D::Ruby.default) # `default` diagnostics setting (applies by default)
15
+ # # configure_code_diagnostics(D::Ruby.strict) # `strict` diagnostics setting
16
+ # # configure_code_diagnostics(D::Ruby.lenient) # `lenient` diagnostics setting
17
+ # # configure_code_diagnostics(D::Ruby.silent) # `silent` diagnostics setting
18
+ # # configure_code_diagnostics do |hash| # You can setup everything yourself
19
+ # # hash[D::Ruby::NoMethod] = :information
20
+ # # end
21
+ # end
22
+
23
+ # target :test do
24
+ # signature "sig", "sig-private"
25
+ #
26
+ # check "test"
27
+ #
28
+ # # library "pathname" # Standard libraries
29
+ # end
30
+ target :lib do
31
+ check 'lib'
32
+ signature 'sig'
33
+ end
@@ -15,8 +15,8 @@ module CopyTunerIncompatibleSearch
15
15
  results = search_static_usages(incompatible_keys)
16
16
  results << search_lazy_usages
17
17
  results << search_dynamic_usages
18
- ignored_keys = Set[*eval(ignored_keys_text)] # rubocop:disable Security/Eval
19
- XlsxWriter.dump_to_xlsx(results, incompatible_keys, ignored_keys, output_path)
18
+ ignored_keys = search_ignored_keys
19
+ XlsxWriter.new(results, incompatible_keys, ignored_keys).save_to(output_path)
20
20
  puts 'Finish'
21
21
  end
22
22
 
@@ -46,14 +46,33 @@ module CopyTunerIncompatibleSearch
46
46
  def add_usage(grep_result)
47
47
  grep_result.each_line do |line|
48
48
  if lazy?
49
- line.scan(/['"](\.[^'"]+)/).flatten.each do |lazy_key|
50
- @usages << Usage.new(line, lazy_key)
49
+ line.scan(/(?<=['"])\.[^'"]+/) do |lazy_key|
50
+ @usages << Usage.new(line, lazy_key.to_s)
51
51
  end
52
52
  else
53
53
  @usages << Usage.new(line)
54
54
  end
55
55
  end
56
56
  end
57
+
58
+ def full_key_for(usage)
59
+ if lazy?
60
+ path = usage
61
+ .file
62
+ .sub(%r{^app/views/}, '')
63
+ .sub(/\..+$/, '')
64
+ .sub('/_', '/')
65
+ .gsub('/', '.')
66
+ path + usage.lazy_key.to_s
67
+ else
68
+ key
69
+ end
70
+ end
71
+
72
+ def already_migrated?(usage)
73
+ used_key = lazy? ? usage.lazy_key : key
74
+ usage.initializers? || usage.code.include?("#{used_key}_html")
75
+ end
57
76
  end
58
77
 
59
78
  class Usage
@@ -63,31 +82,31 @@ module CopyTunerIncompatibleSearch
63
82
  file, line, code = grep_result.split(':', 3)
64
83
  @file = file
65
84
  @line = line
66
- @code = code.strip
85
+ @code = code.to_s.strip
67
86
  @lazy_key = lazy_key
68
87
  end
88
+
89
+ def initializers?
90
+ file == 'config/initializers/copy_tuner.rb'
91
+ end
69
92
  end
70
93
 
71
94
  def search_incompatible_keys
72
95
  stdout = detect_html_incompatible_keys
73
96
  keys = stdout.lines(chomp: true).map do |line|
74
- line.split('.', 2).last
97
+ line.split('.', 2).last.to_s
75
98
  end.uniq.sort
76
99
  Set[*keys]
77
100
  end
78
101
 
79
102
  def search_static_usages(incompatible_keys)
80
103
  puts "Searching #{incompatible_keys.count} keys"
81
- count = 0
82
- incompatible_keys.map do |key|
83
- count += 1
104
+ incompatible_keys.map.with_index(1) do |key, count|
84
105
  puts "#{count} / #{incompatible_keys.count}" if (count % 100).zero?
85
106
 
86
107
  result = Result.new(:static, key)
87
108
  usage = grep_usage(key).strip
88
- unless usage.empty?
89
- result.add_usage(usage)
90
- end
109
+ result.add_usage(usage)
91
110
  result
92
111
  end
93
112
  end
@@ -106,6 +125,10 @@ module CopyTunerIncompatibleSearch
106
125
  result
107
126
  end
108
127
 
128
+ def search_ignored_keys
129
+ Set[*eval(ignored_keys_text)] # rubocop:disable Security/Eval
130
+ end
131
+
109
132
  def detect_html_incompatible_keys
110
133
  `rails copy_tuner:detect_html_incompatible_keys`
111
134
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CopyTunerIncompatibleSearch
4
- VERSION = '0.1.4'
4
+ VERSION = '0.1.5'
5
5
  end
@@ -2,17 +2,13 @@
2
2
 
3
3
  module CopyTunerIncompatibleSearch
4
4
  class XlsxWriter
5
- def self.dump_to_xlsx(results, incompatible_keys, ignored_keys, output_path)
6
- self.new(results, incompatible_keys, ignored_keys).dump_to_xlsx(output_path)
7
- end
8
-
9
5
  def initialize(results, incompatible_keys, ignored_keys)
10
6
  @results = results
11
7
  @incompatible_keys = incompatible_keys
12
8
  @ignored_keys = ignored_keys
13
9
  end
14
10
 
15
- def dump_to_xlsx(output_path)
11
+ def save_to(output_path)
16
12
  Axlsx::Package.new do |p|
17
13
  p.workbook.add_worksheet(name: 'Data') do |sheet|
18
14
  style = sheet.styles.add_style(font_name: 'Courier New', sz: 14)
@@ -45,30 +41,22 @@ module CopyTunerIncompatibleSearch
45
41
  def add_result_rows(sheet, result, style)
46
42
  added = false
47
43
  result.usages.each do |usage|
48
- key = build_key(result, usage)
49
- next unless should_output?(usage, result, key)
44
+ unless result.dynamic?
45
+ full_key = result.full_key_for(usage)
46
+ next unless should_output?(usage, result, full_key)
50
47
 
51
- ignored = ignored_flag(key) unless result.dynamic?
52
- sheet.add_row [result.type, key, ignored.to_s, usage.file, usage.line, usage.code], style: style
48
+ ignored = ignored_flag(full_key)
49
+ end
50
+ sheet.add_row [result.type, full_key, ignored.to_s, usage.file, usage.line, usage.code], style: style
53
51
  added = true
54
52
  end
55
- if !added && result.static?
53
+ if result.static? && !added
56
54
  sheet.add_row [result.type, result.key, ignored_flag(result.key), '', '', ''], style: style
57
55
  end
58
56
  end
59
57
 
60
- def build_key(result, usage)
61
- if result.lazy?
62
- path = usage.file.sub(%r{^app/views/}, '').sub(/\..+$/, '').sub('/_', '/').gsub('/', '.')
63
- path + usage.lazy_key
64
- else
65
- result.key
66
- end
67
- end
68
-
69
- def should_output?(usage, result, key)
70
- already_migrated = usage.file == 'config/initializers/copy_tuner.rb' || usage.code.include?("#{usage.lazy_key || result.key}_html")
71
- (!result.lazy? || incompatible_keys.include?(key)) && !already_migrated
58
+ def should_output?(usage, result, full_key)
59
+ incompatible_keys.include?(full_key) && !result.already_migrated?(usage)
72
60
  end
73
61
 
74
62
  def ignored_flag(key)
@@ -0,0 +1,67 @@
1
+ module CopyTunerIncompatibleSearch
2
+ class Command
3
+ def self.run: (String output_path) -> void
4
+
5
+ def run: (String output_path) -> void
6
+
7
+ private
8
+
9
+ class Result
10
+ type result_type = :dynamic | :static | :lazy
11
+
12
+ attr_reader type: result_type
13
+
14
+ attr_reader key: String
15
+
16
+ attr_reader usages: Array[Usage]
17
+
18
+ def initialize: (result_type type, String key) -> void
19
+
20
+ def static?: () -> bool
21
+
22
+ def lazy?: () -> bool
23
+
24
+ def dynamic?: () -> bool
25
+
26
+ def add_usage: (String grep_result) -> void
27
+
28
+ def full_key_for: (Usage usage) -> String
29
+
30
+ def already_migrated?: (Usage usage) -> bool
31
+ end
32
+
33
+ class Usage
34
+ attr_reader file: String
35
+
36
+ attr_reader line: String
37
+
38
+ attr_reader code: String
39
+
40
+ attr_reader lazy_key: String?
41
+
42
+ def initialize: (String grep_result, ?String? lazy_key) -> void
43
+
44
+ def initializers?: () -> bool
45
+ end
46
+
47
+ def search_incompatible_keys: () -> Set[String]
48
+
49
+ def search_static_usages: (Set[String] incompatible_keys) -> Array[Result]
50
+
51
+ def search_lazy_usages: () -> Result
52
+
53
+ def search_dynamic_usages: () -> Result
54
+
55
+ def search_ignored_keys: () -> Set[String]
56
+
57
+ def detect_html_incompatible_keys: () -> String
58
+
59
+ def grep_lazy_keys: () -> String
60
+
61
+ def grep_dynamic_keys: () -> String
62
+
63
+ def grep_usage: (String key) -> String
64
+
65
+ def ignored_keys_text: () -> ::String
66
+ end
67
+ end
@@ -0,0 +1,29 @@
1
+ module CopyTunerIncompatibleSearch
2
+ class XlsxWriter
3
+ def initialize: (Array[Command::Result] results, Set[String] incompatible_keys, Set[String] ignored_keys) -> void
4
+
5
+ def save_to: (String output_path) -> void
6
+
7
+ private
8
+
9
+ attr_reader results: Array[Command::Result]
10
+
11
+ attr_reader incompatible_keys: Set[String]
12
+
13
+ attr_reader ignored_keys: Set[String]
14
+
15
+ def freeze_pane: (untyped sheet) -> void
16
+
17
+ def add_result_rows: (untyped sheet, Command::Result result, untyped style) -> void
18
+
19
+ def should_output?: (Command::Usage usage, Command::Result result, String full_key) -> bool
20
+
21
+ def ignored_flag: (String key) -> ("Y" | "N")
22
+ end
23
+ end
24
+
25
+ module Axlsx
26
+ class Package
27
+ def initialize: () { (untyped) -> void } -> void
28
+ end
29
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: copy_tuner_incompatible_search
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Junichi Ito
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-04-27 00:00:00.000000000 Z
11
+ date: 2024-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: caxlsx
@@ -39,12 +39,15 @@ files:
39
39
  - LICENSE.txt
40
40
  - README.md
41
41
  - Rakefile
42
+ - Steepfile
42
43
  - exe/copy_tuner_incompatible_search
43
44
  - lib/copy_tuner_incompatible_search.rb
44
45
  - lib/copy_tuner_incompatible_search/command.rb
45
46
  - lib/copy_tuner_incompatible_search/version.rb
46
47
  - lib/copy_tuner_incompatible_search/xlsx_writer.rb
47
48
  - sig/copy_tuner_incompatible_search.rbs
49
+ - sig/lib/copy_tuner_incompatible_search/command.rbs
50
+ - sig/lib/copy_tuner_incompatible_search/xlsx_writer.rbs
48
51
  homepage: https://github.com/JunichiIto/copy_tuner_incompatible_search
49
52
  licenses:
50
53
  - MIT