compath 0.1.3 → 0.1.4

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: 1c86314adbf42083643e131c063cd7419584345c
4
- data.tar.gz: 2aab33aef2eafbbb8dd217280c869b2f05a075b2
3
+ metadata.gz: db1088c56006f4e8bcbfc910a58e7f1b42a1db1f
4
+ data.tar.gz: 00a2e3283fdfb1e8da6ecb3fb05330df34abfa58
5
5
  SHA512:
6
- metadata.gz: 549891f66676b7baa8cdf1920e7453df1f18667331ac564181ae7b4a24a23e3343b4f8e45ff256a57f901a1c20be02cf9bc73169f7d4adeeb613f3d4a750bd9b
7
- data.tar.gz: d16d0b63491daffd8e57275754f3b78e2aa24f4eaa72351169947544da0cce5c50e5fbbe258bcd9750048282a92627e753f0f01404f3a7e01aab59173317f1b0
6
+ metadata.gz: 2b62dace41df7c5911709aa5dccd65a7b73258becac6287f990fe93a2bba8511ebb381911c768b1e3d45371075bec39bf66f70c01d546090e70c72168f5b4da2
7
+ data.tar.gz: 5947e8bd948198cb120acdf10a5e0cb0cce5a6260ddbcba436d0531c2dd1b7b697742f8f21738b87ce7682ce8f67d128f0400a3ccfd283a5c8d067c855a64039
@@ -1,42 +1,8 @@
1
1
  ---
2
- - ".compath.yml":
3
- desc:
4
- - ".gitignore":
5
- desc:
6
- - ".rspec":
7
- desc: Configuration file for RSpec
8
- - ".travis.yml":
9
- desc: Configuration file for travis
10
- - bin/:
11
- desc:
12
- - bin/console:
13
- desc:
14
- - bin/setup:
15
- desc:
16
- - compath.gemspec:
17
- desc:
18
- - exe/:
19
- desc:
20
- - exe/compath:
21
- desc:
22
- - Gemfile:
23
- desc:
24
- - lib/:
25
- desc:
26
- - lib/compath/:
27
- desc:
28
- scan: false
29
- - lib/compath.rb:
30
- desc:
31
- - LICENSE.txt:
32
- desc:
33
- - Rakefile:
34
- desc:
35
- - README.md:
36
- desc:
37
- - spec/:
38
- desc:
39
- - spec/compath_spec.rb:
40
- desc:
41
- - spec/spec_helper.rb:
42
- desc:
2
+ bin/:
3
+ exe/:
4
+ lib/:
5
+ lib/compath/:
6
+ desc:
7
+ scan: false
8
+ spec/:
@@ -5,7 +5,6 @@ require "pathname"
5
5
  require "compath/guide"
6
6
  require "compath/guide_book"
7
7
  require "compath/finder"
8
- require "compath/dumper"
9
8
  require "compath/path_sorter"
10
9
  require "compath/config_loader"
11
10
  require "compath/version"
@@ -5,6 +5,7 @@ module Compath
5
5
  paths = Compath::PathSorter.sort(finder.paths.keys)
6
6
 
7
7
  guides = paths.map {|path| Compath::Guide.new(path) }
8
+ guides.select!(&:directory?)
8
9
  guide_book = Compath::GuideBook.new(guides)
9
10
  if FileTest.exist?('.compath.yml')
10
11
  config = Compath::ConfigLoader.load(File.read('.compath.yml'))
@@ -4,12 +4,21 @@ module Compath
4
4
  def load(config)
5
5
  conf = YAML.load(config)
6
6
 
7
- guides = conf.map do |guide_hash|
8
- path = guide_hash.keys.first
9
- options = guide_hash.values.first
10
- options = options.each_with_object({}) do |(key, value), hash|
11
- hash[key.to_sym] = value
7
+ guides = conf.map do |path, guide|
8
+ if guide.is_a?(Hash)
9
+ # symbolize keys
10
+ options = guide.each_with_object({}) do |(key, value), hash|
11
+ hash[key.to_sym] = value
12
+ end
13
+ else
14
+ # nil or String
15
+ options = {
16
+ scan: true,
17
+ desc: guide,
18
+ }
12
19
  end
20
+
21
+ # TODO: Bad interface...
13
22
  Guide.new(path, **options)
14
23
  end
15
24
  end
@@ -28,23 +28,11 @@ module Compath
28
28
  end
29
29
 
30
30
  def to_object
31
- scan_or_not = if !directory? || @scan_children
32
- {}
33
- else
34
- {
35
- 'scan' => false
36
- }
37
- end
38
-
39
- object = {
40
- object_key => {
41
- 'desc' => @description
42
- }.merge(scan_or_not)
43
- }
44
-
45
- object
31
+ { object_key => object_value }
46
32
  end
47
33
 
34
+ private
35
+
48
36
  def object_key
49
37
  if directory?
50
38
  pathname.to_s + '/'
@@ -52,5 +40,16 @@ module Compath
52
40
  pathname.to_s
53
41
  end
54
42
  end
43
+
44
+ def object_value
45
+ if !directory? || @scan_children
46
+ @description
47
+ else
48
+ {
49
+ 'desc' => @description,
50
+ 'scan' => @scan_children,
51
+ }
52
+ end
53
+ end
55
54
  end
56
55
  end
@@ -20,14 +20,15 @@ module Compath
20
20
  end
21
21
 
22
22
  def publish
23
- guides.map do |guide|
23
+ @index.each_with_object({}) do |(path, guide), hash|
24
24
  scan_children = true
25
25
  scan_children = guide.ancestors.all? do |ancestor|
26
26
  @index[ancestor.to_path].scan_children
27
27
  end
28
28
  next unless scan_children
29
- guide.to_object
30
- end.compact
29
+
30
+ hash.update(guide.to_object)
31
+ end
31
32
  end
32
33
 
33
34
  def publish_yaml
@@ -1,5 +1,8 @@
1
1
  module Compath
2
2
  # TODO: Remove Pathname
3
+ # Sorted files and directories are ordered as below
4
+ # 1. directory
5
+ # 2. file
3
6
  module PathSorter
4
7
  module_function
5
8
 
@@ -1,3 +1,3 @@
1
1
  module Compath
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  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.3
4
+ version: 0.1.4
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-10 00:00:00.000000000 Z
11
+ date: 2017-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -89,7 +89,6 @@ files:
89
89
  - lib/compath.rb
90
90
  - lib/compath/cli.rb
91
91
  - lib/compath/config_loader.rb
92
- - lib/compath/dumper.rb
93
92
  - lib/compath/finder.rb
94
93
  - lib/compath/guide.rb
95
94
  - lib/compath/guide_book.rb
@@ -1,23 +0,0 @@
1
- module Compath
2
- class Dumper
3
- def initialize(paths)
4
- @paths = paths.each_with_object({}) do |path, hash|
5
- hash[path] = Guide.new(path)
6
- end
7
- end
8
-
9
- def dump
10
- @paths.values.map do |path|
11
- scan_target = true
12
- scan_target = path.ancestors.all?(&:scan_children)
13
- next unless scan_target
14
- path.to_object
15
- end.compact
16
- end
17
- alias_method :dump_hash, :dump
18
-
19
- def dump_yaml
20
- YAML.dump(dump_hash)
21
- end
22
- end
23
- end