jp_strings_finder 0.1.0 → 0.1.1

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
  SHA1:
3
- metadata.gz: f2e5360d873e7e539abffef78140079257ffea65
4
- data.tar.gz: 4ba1d251bdbfe1a5e8e86cdbcab382c8e5a98d17
3
+ metadata.gz: b956f7edeab7561fe7a471c181cf623ce6a618fe
4
+ data.tar.gz: ec1df441726e59ee9096eefd3d0858181fb3c8ce
5
5
  SHA512:
6
- metadata.gz: 5bc8c4b53fac9f884f5f6f2e97c1a46f457ee9e17d675abfb25700e1419b40543a9e55a40d16e41aa6acfa28d0ec64ab2231947bf9f2e7e0f90a9747db7d1443
7
- data.tar.gz: d6aa0d57c77b6439f2168af5be016c6339d2a8a81e49d4ec9b7c24b93ac032378f1f9bd004a814962926fcf9d2b827c43aa94c6d6185cbb169b9d89d3d2a3801
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:
@@ -0,0 +1,3 @@
1
+ exclude:
2
+ - "**/*.ja.html.slim"
3
+ - "**/version.rb"
@@ -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
@@ -1,3 +1,3 @@
1
1
  module JpStringsFinder
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require "jp_strings_finder/version"
2
+ require "jp_strings_finder/config"
2
3
  require "jp_strings_finder/finder"
3
4
  require "jp_strings_finder/printer"
4
5
 
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.0
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