platina_world 0.1.2.1 → 0.1.3

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: 824378c15e08401f1c8fecef4315e7a041b24683
4
- data.tar.gz: 8c85e179ab46ea674135d0e4eccc3a0c94f18a3c
3
+ metadata.gz: 9557d38b820b7e213ef3c6084f403dac05e80ece
4
+ data.tar.gz: 13bfd726e4e2158d597c06487014565e1bf5c9a8
5
5
  SHA512:
6
- metadata.gz: 85b8c2790fc1e3747d16b3f9d53b0e336926e230cbe292b444782ee7b8786ffe4feaf70b52d977ade48c233d504b983f70d26f103b23de72f9d5a1774834b189
7
- data.tar.gz: 77c6716adfe5fb82793c2fe774a2de7a7e6da525ce2be53aed1af90080380443098955d0be9bb5e754fb76629018df7cbc28dd709943092498d101d2a4926e25
6
+ metadata.gz: e8967810b3c57eb43c32826f07320ee6a4c57480baf114aedc45ec82d1074c8d4fcd95a4f8ca3530fac379e9ac18928aad8b5501e7f6909343a6622a4faf4763
7
+ data.tar.gz: abb3b3b03c4566ec86fbc914c0ebab688540605311eafbbad080723f3f9ede0158c30e8bc3883b9206fef9110e4f96f71a072f5a84b931a43e894770f0c171a8
data/README.md CHANGED
@@ -65,9 +65,10 @@ $ platinaworld -p pw.yml
65
65
 
66
66
  ## TODO
67
67
 
68
- - [ x ] dry-run
69
- - [ x ] logger
70
- - [ x ] error class
68
+ - [x] dry-run
69
+ - [x] logger
70
+ - [x] error class
71
+ - [x] check file exist or not
71
72
  - [ ] has contents
72
73
  - [ ] json parse
73
74
  - [ ] tree command json parse
@@ -7,33 +7,43 @@ module PlatinaWorld
7
7
 
8
8
  def call
9
9
  @paths.each do |path|
10
- case
11
- when path.directory?
12
- generate_directory(path)
13
- when path.has_directory?
14
- generate_file_with_dir(path)
10
+ file_path = path.file_path
11
+
12
+ if file_exist?(file_path)
13
+ PlatinaWorld::FileStatus.skip(file_path)
15
14
  else
16
- generate_file(path)
15
+ generate(path)
16
+ PlatinaWorld::FileStatus.create(file_path)
17
17
  end
18
-
19
- PlatinaWorld::FileStatus.info(
20
- action: "create",
21
- path: path.file_path
22
- )
23
18
  end
24
19
  end
25
20
 
26
21
  private
27
22
 
23
+ def generate(path)
24
+ case
25
+ when path.directory?
26
+ generate_directory(path)
27
+ when path.has_directory?
28
+ generate_file_with_dir(path)
29
+ else
30
+ generate_file(path)
31
+ end
32
+ end
33
+
34
+ def file_exist?(file_path)
35
+ ::File.exist?(file_path)
36
+ end
37
+
28
38
  def generate_directory(path)
29
39
  raise NotImplementedError
30
40
  end
31
41
 
32
- def generate_file(path)
42
+ def generate_file_with_dir(path)
33
43
  raise NotImplementedError
34
44
  end
35
45
 
36
- def generate_file_with_dir(path)
46
+ def generate_file(path)
37
47
  raise NotImplementedError
38
48
  end
39
49
  end
@@ -10,14 +10,14 @@ module PlatinaWorld
10
10
  FileUtils.mkdir_p(path.directory_name)
11
11
  end
12
12
 
13
- def generate_file(path)
14
- FileUtils.touch(path.file_name)
15
- end
16
-
17
13
  def generate_file_with_dir(path)
18
14
  FileUtils.mkdir_p(path.directory_name)
19
15
  FileUtils.touch("#{path.directory_name}/#{path.file_name}")
20
16
  end
17
+
18
+ def generate_file(path)
19
+ FileUtils.touch(path.file_name)
20
+ end
21
21
  end
22
22
  end
23
23
  end
@@ -9,11 +9,11 @@ module PlatinaWorld
9
9
  # noop
10
10
  end
11
11
 
12
- def generate_file(path)
12
+ def generate_file_with_dir(path)
13
13
  # noop
14
14
  end
15
15
 
16
- def generate_file_with_dir(path)
16
+ def generate_file(path)
17
17
  # noop
18
18
  end
19
19
  end
@@ -3,6 +3,14 @@ require "platina_world/loggers/base"
3
3
  module PlatinaWorld
4
4
  module Loggers
5
5
  class FileStatus < Base
6
+ def create(path)
7
+ info(action: :create, path: path)
8
+ end
9
+
10
+ def skip(path)
11
+ info(action: :skip, path: path)
12
+ end
13
+
6
14
  private
7
15
 
8
16
  def formatter_class
@@ -12,15 +20,17 @@ module PlatinaWorld
12
20
 
13
21
  class FileFormatter
14
22
  def call(severity, time, program_name, message)
15
- file_format(severity) % message
23
+ file_format(message[:action]) % message
16
24
  end
17
25
 
18
- def file_format(severity)
19
- case severity
20
- when "INFO"
26
+ def file_format(action)
27
+ case action
28
+ when :create
21
29
  " \e[32m%{action}\e[0m %{path}\n"
22
- when "ERROR"
23
- " \e[31m%{action}\e[0m %{path}\n"
30
+ when :skip
31
+ " \e[34m%{action} \e[0m %{path}\n"
32
+ when :failed
33
+ " \e[31m%{action} \e[0m %{path}\n"
24
34
  end
25
35
  end
26
36
  end
@@ -6,42 +6,47 @@ module PlatinaWorld
6
6
  @file_path = file_path
7
7
  end
8
8
 
9
+ # @return [String] file name
9
10
  def file_name
10
11
  path[:file]
11
12
  end
12
13
 
14
+ # @return [String] directory path
13
15
  def directory_name
14
16
  path[:directory]
15
17
  end
16
18
 
19
+ # @return [True, False] path is directory or not
17
20
  def directory?
18
21
  file_name == ""
19
22
  end
20
23
 
24
+ # @return [True, False] path has directory path or not
21
25
  def has_directory?
22
26
  directory_name != ""
23
27
  end
24
28
 
25
29
  private
26
30
 
31
+ def path
32
+ @path ||= file_and_directory_name
33
+ end
34
+
27
35
  # Return file name and dirctory name as Array
28
- # @params [String] file path (e.g "a/b/c")
29
- # @return [[String, String]] first is file path name and second is directory path name
36
+ # @return [{String => String}] file name and directory name as Hash
30
37
  #
31
38
  # Examples.
32
- # file_and_dir_name("a/b/c") => ["a/b", "c"]
33
- # file_and_dir_name("a/b/c/") => ["a/b/c", ""]
34
- def path
35
- @path ||= begin
36
- path = file_path.split("/", -1)
37
- file_name = path.pop
38
- directory_name = path.join("/")
39
-
40
- {
41
- file: file_name,
42
- directory: directory_name
43
- }
44
- end
39
+ # file_path = "a/b/c"
40
+ # file_and_directory_name => { directory: "a/b", file: "c"}
41
+ #
42
+ # file_path = "a/b/c/"
43
+ # file_and_directory_name("a/b/c/") => ["a/b/c", ""]
44
+ def file_and_directory_name
45
+ path = file_path.split("/", -1)
46
+ file_name = path.pop
47
+ directory_name = path.join("/")
48
+
49
+ { file: file_name, directory: directory_name }
45
50
  end
46
51
  end
47
52
  end
@@ -1,3 +1,3 @@
1
1
  module PlatinaWorld
2
- VERSION = "0.1.2.1"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -6,6 +6,6 @@
6
6
  - platina_world_spec.rb
7
7
  - spec_helper.rb
8
8
  - Gemfile
9
- - .rpsec
9
+ - .rspec
10
10
  - .gitignore
11
11
  - .rubocop.yml
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: platina_world
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - ganmacs