compath 0.1.7 → 0.1.8

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: 1f2e0e66e3839bf65292f80ba6d74ea111552b18
4
- data.tar.gz: d6a0c453760bd6dc2a863b89bee3bbee825d6d4e
3
+ metadata.gz: 2547bb4109ddc4b27334c1d7dddf4b9e2485ec8c
4
+ data.tar.gz: 00a4c8b479e7600f543d1b5009eb0ff789e9b3bd
5
5
  SHA512:
6
- metadata.gz: 044a25838f0f30322e55ea522f7adcbca0e2fe22fb22dfdc63d48237d46eac248f490024d7f80c0ead9c6ae886a837ca5a8618c21ec46fa710055ad4ce6d3839
7
- data.tar.gz: 6b6678b4980161c8fc44812b45fb99085b66ecfec38db67f863ca5b26ca0c84629750544658e0d8387be9f06622f9462ce7a7f8358a5b7706f938527b044b85d
6
+ metadata.gz: 00204f9c2e9fb60983573d2e44ae5e9e1a5a687a6d00cd999c833a93b5dc1131154cd1270b90fd5878c4e7ad6806f2ae2f0842001b93bca182a27e9d4ce501e6
7
+ data.tar.gz: 988799224d0eaad2080e5abed8b7d3281c7a1cc665dae1f357b98fd58e6e0357f598a01b312d3e36e340d960540adb85895da8c47d899e4f67f6ef22369bb6b3
@@ -1,6 +1,7 @@
1
1
  ---
2
- bin/:
3
- exe/:
4
- lib/:
5
- lib/compath/**/*:
6
- spec/:
2
+ .github/:
3
+ bin/:
4
+ exe/:
5
+ lib/:
6
+ lib/compath/:
7
+ spec/:
File without changes
data/README.md CHANGED
@@ -38,7 +38,7 @@ spec/:
38
38
  ...
39
39
  ```
40
40
 
41
- It will be updated to the following content by compath.
41
+ It will be updated to the following content by running `compath`.
42
42
 
43
43
  ```yaml
44
44
  ---
@@ -2,6 +2,7 @@ require "forwardable"
2
2
  require "yaml"
3
3
  require "pathname"
4
4
 
5
+ require "compath/yaml_formatter"
5
6
  require "compath/guide"
6
7
  require "compath/guide_book"
7
8
  require "compath/finder"
@@ -19,8 +19,9 @@ module Compath
19
19
  end
20
20
 
21
21
  yaml = guide_book.publish_yaml
22
+ formatted_yaml = YamlFormatter.new(yaml).format
22
23
 
23
- File.write('.compath.yml', yaml)
24
+ File.write('.compath.yml', formatted_yaml)
24
25
  puts 'Write .compath.yml'
25
26
  end
26
27
  end
@@ -1,3 +1,3 @@
1
1
  module Compath
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
@@ -0,0 +1,44 @@
1
+ module Compath
2
+ class YamlFormatter
3
+ attr_accessor :yaml
4
+
5
+ def initialize(yaml)
6
+ @yaml = yaml
7
+ end
8
+
9
+ def format
10
+ formatters.each do |formatter|
11
+ self.yaml = formatter.call(yaml)
12
+ end
13
+ yaml
14
+ end
15
+
16
+ def formatters
17
+ @formatters ||= [
18
+ remove_trailing_space_formatter,
19
+ remove_quotes_from_keys_formatter,
20
+ ]
21
+ end
22
+
23
+ def remove_trailing_space_formatter
24
+ lambda do |yaml|
25
+ yaml.lines.map(&:rstrip).map {|x| "#{x}\n" }.join
26
+ end
27
+ end
28
+
29
+ QUOTED_KEY_REGEXP = /^"(?<key>[^"]+)":(?<value>.*)/
30
+ def remove_quotes_from_keys_formatter
31
+ lambda do |yaml|
32
+ lines = yaml.lines.map do |line|
33
+ if m = QUOTED_KEY_REGEXP.match(line)
34
+ "#{m[:key]}: #{m[:value]}"
35
+ else
36
+ line.chomp
37
+ end
38
+ end
39
+
40
+ lines.map {|x| "#{x}\n" }.join
41
+ end
42
+ end
43
+ end
44
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: compath
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - meganemura
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-06-11 00:00:00.000000000 Z
11
+ date: 2017-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -75,6 +75,7 @@ extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
77
77
  - ".compath.yml"
78
+ - ".github/.gitkeep"
78
79
  - ".gitignore"
79
80
  - ".rspec"
80
81
  - ".travis.yml"
@@ -94,6 +95,7 @@ files:
94
95
  - lib/compath/guide_book.rb
95
96
  - lib/compath/path_sorter.rb
96
97
  - lib/compath/version.rb
98
+ - lib/compath/yaml_formatter.rb
97
99
  homepage: https://github.com/meganemura/compath
98
100
  licenses:
99
101
  - MIT