platina_world 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 738e240a6d6087bf82cf85d136e1f4fe5a952fae
4
- data.tar.gz: 8ed17ae1a95d3d3b98563e3d25479af09ffa8d2c
3
+ metadata.gz: 3068308554e89e3ec93d81b86855bda168c5fd23
4
+ data.tar.gz: d44ea71922386356b1a58e6b94ea372d2f044e8a
5
5
  SHA512:
6
- metadata.gz: f5b024776558ee93af1385f50286a5bd1e77e2dcc829565d85085c571321653668c07f9562fed6809cefc604d1fa9ca2308ef610953753cd7458576bf2d73144
7
- data.tar.gz: b5d8ce23316fecf4c6765ab05808141dbcc89c02e69442443c5b01bf0ca4b8d24a0f6d581515f13c22b54b6de4e3bef3c48e8f5e8141d51b631b524009b49b96
6
+ metadata.gz: 537f2bf6cf2c990629df77cfe161c2db6c69699e76b8b880a632f77e06c2831fbd58667322fc1dfe892433e4c4d45a6a2e616c54f0f0602aa749ee7adee0b9a2
7
+ data.tar.gz: aea445a02ff7cdc04544b730c7f182dec98b9962ef3406d346554b6fb73808b0b7c57f3c70dc92378ff5c03de0d43b64005ac713f359b2e774c6c98b96e4cd7b
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in platinaworld.gemspec
4
4
  gemspec
5
+
6
+ gem "codeclimate-test-reporter", require: false
data/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  <a href="https://codeclimate.com/github/ganmacs/platina_world"><img src="https://codeclimate.com/github/ganmacs/platina_world/badges/gpa.svg" /></a>
4
4
  [![Build Status](https://travis-ci.org/ganmacs/platina_world.svg)](https://travis-ci.org/ganmacs/platina_world)
5
+ [![Test Coverage](https://codeclimate.com/github/ganmacs/platina_world/badges/coverage.svg)](https://codeclimate.com/github/ganmacs/platina_world/coverage)
5
6
 
6
7
  platina_world Creates platina world in a moment
7
8
 
@@ -62,6 +63,17 @@ and run as below
62
63
  $ platinaworld ruby
63
64
  ```
64
65
 
66
+ #### Contents
67
+
68
+ If you want to create file which has contents, then use `@` literal as below.
69
+
70
+ ```yml
71
+ - .rspec@https://filepath.com
72
+ - .gitignore@$HOME/.platina_world/t/ruby/.gitignore
73
+ ```
74
+
75
+ then create `.rspec` file which contents get from `http://filepaht.com`, and `.gitignore` file which contents get from `$HOME/.platina_world/t/ruby/.gitignore.paltinaworld`
76
+
65
77
  ## TODO
66
78
 
67
79
  - [x] dry-run
@@ -70,8 +82,8 @@ $ platinaworld ruby
70
82
  - [x] check file exist or not
71
83
  - [x] dot file
72
84
  - [x] usage
73
- - [ ] manager spec
74
- - [ ] has contents
85
+ - [x] has contents( @postion syntax ?)
86
+ - [x] manager spec
75
87
  - [ ] json parse
76
88
  - [ ] tree command json parse
77
89
  - [ ] easy format
@@ -13,7 +13,7 @@ module PlatinaWorld
13
13
  def call
14
14
  case
15
15
  when list?
16
- template_manager.all
16
+ template_manager.show_items
17
17
  when setup?
18
18
  template_manager.setup
19
19
  else
@@ -29,9 +29,9 @@ module PlatinaWorld
29
29
 
30
30
  def runner_class
31
31
  if dry_run?
32
- PlatinaWorld::Runners::Dry
32
+ PlatinaWorld::Runner::Dry
33
33
  else
34
- PlatinaWorld::Runners::Production
34
+ PlatinaWorld::Runner::Production
35
35
  end
36
36
  end
37
37
 
@@ -40,22 +40,22 @@ module PlatinaWorld
40
40
  end
41
41
 
42
42
  def loaded_file
43
- PlatinaWorld::FileLoader.new(file_path).load
43
+ @loaded_file ||= PlatinaWorld::FileLoader.new(tempalte_path).load
44
44
  end
45
45
 
46
- def file_path
47
- if template_path
48
- template_manager.file(template_path)
46
+ def tempalte_path
47
+ if tempalte_name
48
+ template_manager.expand(tempalte_name)
49
49
  else
50
50
  options["path"]
51
51
  end
52
52
  end
53
53
 
54
- def template_path
55
- @template_path ||= begin
56
- option_parser.permute!(@argv) # call #permute! to clear @argv
57
- @argv.pop
58
- end
54
+ def tempalte_name
55
+ @tempalte_name ||= begin
56
+ option_parser.permute!(@argv) # call #permute! to clear @argv
57
+ @argv.pop
58
+ end
59
59
  end
60
60
 
61
61
  def setup?
@@ -0,0 +1,31 @@
1
+ module PlatinaWorld
2
+ module Fetchable
3
+ def contents
4
+ @contents ||= (contents_fetcher && contents_fetcher.fetch)
5
+ end
6
+
7
+ def has_contents?
8
+ !!contents
9
+ end
10
+
11
+ private
12
+
13
+ def contents_path
14
+ fail NotImplementedError
15
+ end
16
+
17
+ def has_contents_path?
18
+ !!contents_path
19
+ end
20
+
21
+ def contents_fetcher
22
+ return @contents_fetcher if instance_variable_defined?(:@contents_fetcher)
23
+ @contents_fetcher =
24
+ if has_contents_path?
25
+ FetcherBuilder.new(contents_path).build
26
+ else
27
+ nil
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,27 @@
1
+ require "platina_world/fetchers/local"
2
+ require "platina_world/fetchers/net"
3
+
4
+ module PlatinaWorld
5
+ class FetcherBuilder
6
+ def initialize(uri)
7
+ @uri = URI.parse(uri)
8
+ end
9
+
10
+ def build
11
+ fetcher_class.new(@uri)
12
+ end
13
+
14
+ private
15
+
16
+ def fetcher_class
17
+ case @uri
18
+ when URI::HTTP, URI::HTTPS
19
+ ::PlatinaWorld::Fetcher::Net
20
+ when URI::Generic
21
+ ::PlatinaWorld::Fetcher::Local
22
+ else
23
+ raise "Unknow URI type: #{@uri.class}(#{@uri})"
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,28 @@
1
+ module PlatinaWorld
2
+ module Fetcher
3
+ class Base
4
+ # @uri [URI::HTTP, URI::HTTPS, URI:Generic]
5
+ def initialize(uri)
6
+ @uri = uri
7
+ end
8
+
9
+ def fetch
10
+ if valid?
11
+ fetch_contents
12
+ else
13
+ fail "invalid file path: #{@uri}"
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def valid?
20
+ raise NotImplementedError
21
+ end
22
+
23
+ def fetch_contents
24
+ raise NotImplementedError
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,30 @@
1
+ require "platina_world/fetchers/base"
2
+
3
+ module PlatinaWorld
4
+ module Fetcher
5
+ class Local < Base
6
+ CONVERT_TABLE = {
7
+ "$HOME" => ENV["HOME"],
8
+ "$ROOT" => "#{ENV['HOME']}/.platina_world"
9
+ }
10
+
11
+ private
12
+
13
+ def valid?
14
+ exist_resouce?
15
+ end
16
+
17
+ def fetch_contents
18
+ File.read(expanded_uri)
19
+ end
20
+
21
+ def expanded_uri
22
+ @expanded_uri ||= @uri.to_s.gsub(%r(\$[^/]+), CONVERT_TABLE)
23
+ end
24
+
25
+ def exist_resouce?
26
+ ::File.exist?(expanded_uri)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,18 @@
1
+ require "net/http"
2
+ require "platina_world/fetchers/base"
3
+
4
+ module PlatinaWorld
5
+ module Fetcher
6
+ class Net < Base
7
+ private
8
+
9
+ def valid?
10
+ true
11
+ end
12
+
13
+ def fetch_contents
14
+ ::Net::HTTP.get(@uri)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,35 +1,60 @@
1
+ require "platina_world/fetcher_builder"
2
+ require "platina_world/fetchable"
3
+
1
4
  module PlatinaWorld
2
5
  class Path
3
- attr_reader :file_path
6
+ include Fetchable
4
7
 
8
+ # file_path [String]
5
9
  def initialize(file_path)
6
- @file_path = file_path
10
+ @file_path, @contents_path = split_path(file_path)
11
+ end
12
+
13
+ def to_s
14
+ @file_path
7
15
  end
8
16
 
9
17
  # @return [String] file name
10
- def file_name
11
- path[:file]
18
+ def filename
19
+ path_info[:file]
12
20
  end
13
21
 
14
22
  # @return [String] directory path
15
- def directory_name
16
- path[:directory]
23
+ def dirname
24
+ path_info[:directory]
17
25
  end
18
26
 
19
27
  # @return [True, False] path is directory or not
20
28
  def directory?
21
- file_name == ""
29
+ filename == ""
22
30
  end
23
31
 
24
32
  # @return [True, False] path has directory path or not
25
33
  def has_directory?
26
- directory_name != ""
34
+ dirname != ""
35
+ end
36
+
37
+ def exist?
38
+ ::File.exist?(@file_path)
27
39
  end
28
40
 
29
41
  private
30
42
 
31
- def path
32
- @path ||= file_and_directory_name
43
+ # override
44
+ def contents_path
45
+ @contents_path
46
+ end
47
+
48
+ def split_path(path)
49
+ if path.include?("@")
50
+ path.split("@")
51
+ else
52
+ [path, nil]
53
+ end
54
+ end
55
+
56
+ def path_info
57
+ @path_info ||= file_and_directory_name
33
58
  end
34
59
 
35
60
  # Return file name and dirctory name as Array
@@ -37,12 +62,12 @@ module PlatinaWorld
37
62
  #
38
63
  # Examples.
39
64
  # file_path = "a/b/c"
40
- # file_and_directory_name => { directory: "a/b", file: "c"}
65
+ # file_and_directory_name(file_path) # => { directory: "a/b", file: "c"}
41
66
  #
42
67
  # file_path = "a/b/c/"
43
- # file_and_directory_name("a/b/c/") => ["a/b/c", ""]
68
+ # file_and_directory_name(file_path) # => { directory: "a/b/c", file: ""}
44
69
  def file_and_directory_name
45
- path = file_path.split("/", -1)
70
+ path = @file_path.split("/", -1)
46
71
  file_name = path.pop
47
72
  directory_name = path.join("/")
48
73
 
@@ -1,28 +1,52 @@
1
1
  require "platina_world/path_builder"
2
2
 
3
3
  module PlatinaWorld
4
- module Runners
4
+ module Runner
5
5
  class Base
6
6
  def initialize(loaded_file)
7
7
  @loaded_file = loaded_file
8
8
  end
9
9
 
10
10
  def run
11
- file_generator.call
11
+ paths.each do |path|
12
+ file_path = path.to_s
13
+
14
+ if path.exist?
15
+ PlatinaWorld::FileStatus.skip(file_path)
16
+ else
17
+ generate(path)
18
+ PlatinaWorld::FileStatus.create(file_path)
19
+ end
20
+ end
12
21
  end
13
22
 
14
23
  private
15
24
 
16
- def generator_class
25
+ def paths
26
+ @paths ||= PlatinaWorld::PathBuilder.new(@loaded_file).build
27
+ end
28
+
29
+ def generate(path)
30
+ case
31
+ when path.directory?
32
+ generate_directory(path)
33
+ when path.has_directory?
34
+ generate_file_with_dir(path)
35
+ else
36
+ generate_file(path)
37
+ end
38
+ end
39
+
40
+ def generate_directory(path)
17
41
  raise NotImplementedError
18
42
  end
19
43
 
20
- def file_generator
21
- generator_class.new(paths)
44
+ def generate_file_with_dir(path)
45
+ raise NotImplementedError
22
46
  end
23
47
 
24
- def paths
25
- @paths ||= PlatinaWorld::PathBuilder.new(@loaded_file).build
48
+ def generate_file(path)
49
+ raise NotImplementedError
26
50
  end
27
51
  end
28
52
  end
@@ -1,13 +1,20 @@
1
1
  require "platina_world/runners/base"
2
- require "platina_world/generators/mock"
3
2
 
4
3
  module PlatinaWorld
5
- module Runners
4
+ module Runner
6
5
  class Dry < Base
7
6
  private
8
7
 
9
- def generator_class
10
- PlatinaWorld::Generators::Mock
8
+ def generate_directory(path)
9
+ # noop
10
+ end
11
+
12
+ def generate_file_with_dir(path)
13
+ # noop
14
+ end
15
+
16
+ def generate_file(path)
17
+ # noop
11
18
  end
12
19
  end
13
20
  end
@@ -1,13 +1,23 @@
1
1
  require "platina_world/runners/base"
2
- require "platina_world/generators/file"
2
+ require 'fileutils'
3
3
 
4
4
  module PlatinaWorld
5
- module Runners
5
+ module Runner
6
6
  class Production < Base
7
7
  private
8
8
 
9
- def generator_class
10
- PlatinaWorld::Generators::File
9
+ def generate_directory(path)
10
+ FileUtils.mkdir_p(path.to_s)
11
+ end
12
+
13
+ def generate_file_with_dir(path)
14
+ FileUtils.mkdir_p(path.dirname)
15
+ generate_file(path)
16
+ end
17
+
18
+ def generate_file(path)
19
+ FileUtils.touch(path.to_s)
20
+ ::File.write(path.to_s, path.contents) if path.has_contents?
11
21
  end
12
22
  end
13
23
  end
@@ -2,14 +2,13 @@ require "platina_world/path"
2
2
 
3
3
  module PlatinaWorld
4
4
  class TemplateManager
5
- attr_reader :root_path, :template_file_pattern
5
+ attr_reader :template_file_pattern
6
6
 
7
7
  def initialize
8
- @root_path = "#{ENV['HOME']}/.platina_world".freeze
9
8
  @template_file_pattern = "#{root_path}/*.{yml,yaml}".freeze
10
9
  end
11
10
 
12
- def all
11
+ def show_items
13
12
  @all ||= all_files.each do |file|
14
13
  file.match(%r!#{root_path}/(?<attr>.*)\.(yml|yaml)!) do |m|
15
14
  puts m[:attr]
@@ -17,23 +16,24 @@ module PlatinaWorld
17
16
  end
18
17
  end
19
18
 
19
+ def root_path
20
+ @root_path ||= Path.new("#{ENV['HOME']}/.platina_world".freeze)
21
+ end
22
+
20
23
  def setup
21
- if exist?
22
- PlatinaWorld::FileStatus.skip(root_path)
24
+ path = root_path.to_s
25
+ if root_path.exist?
26
+ PlatinaWorld::FileStatus.skip(path)
23
27
  else
24
- Dir.mkdir(root_path)
25
- PlatinaWorld::FileStatus.create(root_path)
28
+ Dir.mkdir(path)
29
+ PlatinaWorld::FileStatus.create(path)
26
30
  end
27
31
  end
28
32
 
29
- def file(template)
33
+ def expand(template)
30
34
  "#{root_path}/#{template}.yml"
31
35
  end
32
36
 
33
- def exist?
34
- ::File.exist?(root_path)
35
- end
36
-
37
37
  private
38
38
 
39
39
  def all_files
@@ -1,3 +1,3 @@
1
1
  module PlatinaWorld
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -0,0 +1,3 @@
1
+ - .rubocop2@https://gist.githubusercontent.com/ganmacs/a498999f33b91a34dd15/raw/63bdf7907f00187c604b5f8c2aff5e010550c944/gistfile1.rb
2
+ - .rubocop3@$HOME/.platina_world/t/ruby/.rspec
3
+ - .rubocop4@$ROOT/t/ruby/.rspec
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: platina_world
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - ganmacs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-01 00:00:00.000000000 Z
11
+ date: 2015-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -73,10 +73,12 @@ files:
73
73
  - lib/platina_world/errors/base.rb
74
74
  - lib/platina_world/errors/file_path_error.rb
75
75
  - lib/platina_world/errors/invalid_extension_error.rb
76
+ - lib/platina_world/fetchable.rb
77
+ - lib/platina_world/fetcher_builder.rb
78
+ - lib/platina_world/fetchers/base.rb
79
+ - lib/platina_world/fetchers/local.rb
80
+ - lib/platina_world/fetchers/net.rb
76
81
  - lib/platina_world/file_loader.rb
77
- - lib/platina_world/generators/base.rb
78
- - lib/platina_world/generators/file.rb
79
- - lib/platina_world/generators/mock.rb
80
82
  - lib/platina_world/logger.rb
81
83
  - lib/platina_world/loggers/base.rb
82
84
  - lib/platina_world/loggers/file_status.rb
@@ -89,6 +91,7 @@ files:
89
91
  - lib/platina_world/template_manager.rb
90
92
  - lib/platina_world/version.rb
91
93
  - platinaworld.gemspec
94
+ - samples/contents_sample.yml
92
95
  - samples/ruby_world_sample.yml
93
96
  - samples/simple_sample.json
94
97
  - samples/simple_sample.yml
@@ -1,51 +0,0 @@
1
- module PlatinaWorld
2
- module Generators
3
- class Base
4
- def initialize(paths)
5
- @paths = paths
6
- end
7
-
8
- def call
9
- @paths.each do |path|
10
- file_path = path.file_path
11
-
12
- if file_exist?(file_path)
13
- PlatinaWorld::FileStatus.skip(file_path)
14
- else
15
- generate(path)
16
- PlatinaWorld::FileStatus.create(file_path)
17
- end
18
- end
19
- end
20
-
21
- private
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
-
38
- def generate_directory(path)
39
- raise NotImplementedError
40
- end
41
-
42
- def generate_file_with_dir(path)
43
- raise NotImplementedError
44
- end
45
-
46
- def generate_file(path)
47
- raise NotImplementedError
48
- end
49
- end
50
- end
51
- end
@@ -1,23 +0,0 @@
1
- require "platina_world/generators/base"
2
- require "fileutils"
3
-
4
- module PlatinaWorld
5
- module Generators
6
- class File < Base
7
- private
8
-
9
- def generate_directory(path)
10
- FileUtils.mkdir_p(path.directory_name)
11
- end
12
-
13
- def generate_file_with_dir(path)
14
- FileUtils.mkdir_p(path.directory_name)
15
- FileUtils.touch("#{path.directory_name}/#{path.file_name}")
16
- end
17
-
18
- def generate_file(path)
19
- FileUtils.touch(path.file_name)
20
- end
21
- end
22
- end
23
- end
@@ -1,21 +0,0 @@
1
- require "platina_world/generators/base"
2
-
3
- module PlatinaWorld
4
- module Generators
5
- class Mock < Base
6
- private
7
-
8
- def generate_directory(path)
9
- # noop
10
- end
11
-
12
- def generate_file_with_dir(path)
13
- # noop
14
- end
15
-
16
- def generate_file(path)
17
- # noop
18
- end
19
- end
20
- end
21
- end