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 +4 -4
- data/README.md +4 -3
- data/lib/platina_world/generators/base.rb +23 -13
- data/lib/platina_world/generators/file.rb +4 -4
- data/lib/platina_world/generators/mock.rb +2 -2
- data/lib/platina_world/loggers/file_status.rb +16 -6
- data/lib/platina_world/path.rb +20 -15
- data/lib/platina_world/version.rb +1 -1
- data/sample/ruby_world_sample.yml +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9557d38b820b7e213ef3c6084f403dac05e80ece
|
4
|
+
data.tar.gz: 13bfd726e4e2158d597c06487014565e1bf5c9a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
- [
|
69
|
-
- [
|
70
|
-
- [
|
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
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
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
|
42
|
+
def generate_file_with_dir(path)
|
33
43
|
raise NotImplementedError
|
34
44
|
end
|
35
45
|
|
36
|
-
def
|
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
|
@@ -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(
|
23
|
+
file_format(message[:action]) % message
|
16
24
|
end
|
17
25
|
|
18
|
-
def file_format(
|
19
|
-
case
|
20
|
-
when
|
26
|
+
def file_format(action)
|
27
|
+
case action
|
28
|
+
when :create
|
21
29
|
" \e[32m%{action}\e[0m %{path}\n"
|
22
|
-
when
|
23
|
-
" \e[
|
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
|
data/lib/platina_world/path.rb
CHANGED
@@ -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
|
-
# @
|
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
|
-
#
|
33
|
-
#
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|