jp_strings_finder 0.1.0 → 0.1.1
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/README.md +16 -0
- data/config/config.yml.example +3 -0
- data/exe/jp_strings_finder +11 -5
- data/lib/jp_strings_finder/config.rb +29 -0
- data/lib/jp_strings_finder/version.rb +1 -1
- data/lib/jp_strings_finder.rb +1 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b956f7edeab7561fe7a471c181cf623ce6a618fe
|
4
|
+
data.tar.gz: ec1df441726e59ee9096eefd3d0858181fb3c8ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 214abc2ea4ac3530d60181652618a537bdb1b19da5ad8d93b5e4f6dc0d47f1829664b535a1e59d1d4f1b0f7819e6410bcfe5f0fc4b031d2fe0f131d2ff10e2ec
|
7
|
+
data.tar.gz: 5ed4503006a4efe19e96baffad5e47cb38b8f8991b553911f80e73056f9e7a302d407392f8619999b17ffc4267549aa2f17e8ce86904a4879812e31b854e98f5
|
data/README.md
CHANGED
@@ -50,6 +50,22 @@ In both cases, files with not supported filetype are ignore with the below messa
|
|
50
50
|
Unsupported filetype [app/views/books/books.csv]
|
51
51
|
```
|
52
52
|
|
53
|
+
## Configuration
|
54
|
+
|
55
|
+
You can set a few configuration options by passing YAML file with `-f` option (only excluding files for the moment though):
|
56
|
+
|
57
|
+
```
|
58
|
+
$ jp_strings_finder -f config.yml app/views/
|
59
|
+
```
|
60
|
+
|
61
|
+
A config file should be like the below, see `config/config.yml.example` for details:
|
62
|
+
|
63
|
+
```yaml
|
64
|
+
exclude:
|
65
|
+
- "**/*.ja.html.slim"
|
66
|
+
- "**/version.rb"
|
67
|
+
```
|
68
|
+
|
53
69
|
## Installation
|
54
70
|
|
55
71
|
Add this line to your application's Gemfile:
|
data/exe/jp_strings_finder
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
+
require "optparse"
|
3
4
|
require "colorize"
|
4
5
|
require "jp_strings_finder"
|
5
6
|
|
6
|
-
def find_in_file(file_path)
|
7
|
+
def find_in_file(file_path, config)
|
7
8
|
file_path = File.expand_path(file_path)
|
9
|
+
return if config.exclude?(file_path)
|
8
10
|
begin
|
9
11
|
strings = JpStringsFinder.find_in(file_path)
|
10
12
|
rescue => e
|
@@ -21,23 +23,27 @@ def find_in_file(file_path)
|
|
21
23
|
end
|
22
24
|
end
|
23
25
|
|
24
|
-
def find_in_directory(dir_path)
|
26
|
+
def find_in_directory(dir_path, config)
|
25
27
|
dir_path = File.expand_path(dir_path)
|
26
28
|
results = []
|
27
29
|
Dir.glob(File.join(dir_path, "/**/*")) do |file_path|
|
28
30
|
next if File.directory?(file_path)
|
29
|
-
results << find_in_file(file_path)
|
31
|
+
results << find_in_file(file_path, config)
|
30
32
|
end
|
31
33
|
results
|
32
34
|
end
|
33
35
|
|
36
|
+
args = ARGV.getopts('f:')
|
37
|
+
config_file = args["f"]
|
34
38
|
path = ARGV[0]
|
35
39
|
|
40
|
+
config = JpStringsFinder::Config.new(config_file: config_file)
|
41
|
+
|
36
42
|
results =
|
37
43
|
if File.directory?(path)
|
38
|
-
find_in_directory(path).compact
|
44
|
+
find_in_directory(path, config).compact
|
39
45
|
elsif File.file?(path)
|
40
|
-
[find_in_file(path)].compact
|
46
|
+
[find_in_file(path, config)].compact
|
41
47
|
else
|
42
48
|
raise "[#{path}] is not found"
|
43
49
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "yaml"
|
2
|
+
|
3
|
+
module JpStringsFinder
|
4
|
+
class Config
|
5
|
+
DEFAULT = {
|
6
|
+
"exclude" => []
|
7
|
+
}
|
8
|
+
|
9
|
+
attr_reader :config, :exclude_files
|
10
|
+
|
11
|
+
def initialize(config_file: nil)
|
12
|
+
if config_file
|
13
|
+
loaded_config = YAML.load_file(config_file)
|
14
|
+
@config = DEFAULT.merge(loaded_config)
|
15
|
+
else
|
16
|
+
@config = DEFAULT
|
17
|
+
end
|
18
|
+
|
19
|
+
@exclude_files = @config["exclude"].inject([]) do |acc, elem|
|
20
|
+
acc << Dir.glob(elem).map { |e| File.expand_path(e) }
|
21
|
+
acc.flatten.uniq
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def exclude?(file_path)
|
26
|
+
@exclude_files.include?(file_path)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/jp_strings_finder.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jp_strings_finder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hirofumi Wakasugi
|
@@ -152,9 +152,11 @@ files:
|
|
152
152
|
- Rakefile
|
153
153
|
- bin/console
|
154
154
|
- bin/setup
|
155
|
+
- config/config.yml.example
|
155
156
|
- exe/jp_strings_finder
|
156
157
|
- jp_strings_finder.gemspec
|
157
158
|
- lib/jp_strings_finder.rb
|
159
|
+
- lib/jp_strings_finder/config.rb
|
158
160
|
- lib/jp_strings_finder/erb_finder.rb
|
159
161
|
- lib/jp_strings_finder/filetype_detector.rb
|
160
162
|
- lib/jp_strings_finder/finder.rb
|