ggem 1.9.1 → 1.9.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,85 +1,80 @@
1
1
  require "pathname"
2
2
  require "scmd"
3
3
 
4
- module GGem
5
-
6
- class Gemspec
7
-
8
- PUSH_HOST_META_KEY = "allowed_push_host"
9
- DEFAULT_PUSH_HOST = "https://rubygems.org".freeze
10
- BUILD_TO_DIRNAME = "pkg".freeze
11
-
12
- attr_reader :path, :name, :version, :version_tag
13
- attr_reader :gem_file_name, :gem_file, :push_host
14
-
15
- def initialize(root_path)
16
- @root = Pathname.new(File.expand_path(root_path))
17
- raise NotFoundError unless @root.exist?
18
- @path = Pathname.new(Dir[File.join(@root, "{,*}.gemspec")].first.to_s)
19
- raise NotFoundError unless @path.exist?
20
-
21
- @spec = load_gemspec(@path)
22
- @name = @spec.name
23
- @version = @spec.version
24
- @version_tag = "v#{@version}"
25
-
26
- @gem_file_name = "#{@name}-#{@version}.gem"
27
- @gem_file = File.join(BUILD_TO_DIRNAME, @gem_file_name)
28
- @built_gem_path = @root.join(@gem_file)
29
-
30
- @push_host = get_push_host(@spec)
31
- end
32
-
33
- def run_build_cmd
34
- run_cmd("gem build --verbose #{@path}").tap do
35
- gem_path = @root.join(@gem_file_name)
36
- run_cmd("mkdir -p #{@built_gem_path.dirname}")
37
- run_cmd("mv #{gem_path} #{@built_gem_path}")
38
- end
39
- end
40
-
41
- def run_install_cmd
42
- run_cmd("gem install #{@built_gem_path}")
43
- end
4
+ module GGem; end
5
+ class GGem::Gemspec
6
+ PUSH_HOST_META_KEY = "allowed_push_host"
7
+ DEFAULT_PUSH_HOST = "https://rubygems.org".freeze
8
+ BUILD_TO_DIRNAME = "pkg".freeze
9
+
10
+ NotFoundError = Class.new(ArgumentError)
11
+ LoadError = Class.new(ArgumentError)
12
+ CmdError = Class.new(RuntimeError)
13
+
14
+ attr_reader :path, :name, :version, :version_tag
15
+ attr_reader :gem_file_name, :gem_file, :push_host
16
+
17
+ def initialize(root_path)
18
+ @root = Pathname.new(File.expand_path(root_path))
19
+ raise NotFoundError unless @root.exist?
20
+ @path = Pathname.new(Dir[File.join(@root, "{,*}.gemspec")].first.to_s)
21
+ raise NotFoundError unless @path.exist?
22
+
23
+ @spec = load_gemspec(@path)
24
+ @name = @spec.name
25
+ @version = @spec.version
26
+ @version_tag = "v#{@version}"
27
+
28
+ @gem_file_name = "#{@name}-#{@version}.gem"
29
+ @gem_file = File.join(BUILD_TO_DIRNAME, @gem_file_name)
30
+ @built_gem_path = @root.join(@gem_file)
31
+
32
+ @push_host = get_push_host(@spec)
33
+ end
44
34
 
45
- def run_push_cmd
46
- run_cmd("gem push #{@built_gem_path} --host #{@push_host}")
35
+ def run_build_cmd
36
+ run_cmd("gem build --verbose #{@path}").tap do
37
+ gem_path = @root.join(@gem_file_name)
38
+ run_cmd("mkdir -p #{@built_gem_path.dirname}")
39
+ run_cmd("mv #{gem_path} #{@built_gem_path}")
47
40
  end
41
+ end
48
42
 
49
- private
50
-
51
- def run_cmd(cmd_string)
52
- cmd = Scmd.new(cmd_string)
53
- cmd.run
54
- if !cmd.success?
55
- raise CmdError, "#{cmd_string}\n" \
56
- "#{cmd.stderr.empty? ? cmd.stdout : cmd.stderr}"
57
- end
58
- [cmd_string, cmd.exitstatus, cmd.stdout]
59
- end
43
+ def run_install_cmd
44
+ run_cmd("gem install #{@built_gem_path}")
45
+ end
60
46
 
61
- def load_gemspec(path)
62
- eval(path.read, TOPLEVEL_BINDING, path.expand_path.to_s)
63
- rescue ScriptError, StandardError => e
64
- original_line = e.backtrace.find{ |line| line.include?(path.to_s) }
65
- msg = "There was a #{e.class} while loading #{path.basename}: \n#{e.message}"
66
- msg << " from\n #{original_line}" if original_line
67
- msg << "\n"
68
- raise LoadError, msg
69
- end
47
+ def run_push_cmd
48
+ run_cmd("gem push #{@built_gem_path} --host #{@push_host}")
49
+ end
70
50
 
71
- def get_push_host(spec)
72
- ENV["GGEM_PUSH_HOST"] || get_meta(spec)[PUSH_HOST_META_KEY] || DEFAULT_PUSH_HOST
73
- end
51
+ private
74
52
 
75
- def get_meta(spec)
76
- (spec.respond_to?(:metadata) ? spec.metadata : {}) || {}
53
+ def run_cmd(cmd_string)
54
+ cmd = Scmd.new(cmd_string)
55
+ cmd.run
56
+ if !cmd.success?
57
+ raise CmdError, "#{cmd_string}\n" \
58
+ "#{cmd.stderr.empty? ? cmd.stdout : cmd.stderr}"
77
59
  end
60
+ [cmd_string, cmd.exitstatus, cmd.stdout]
61
+ end
78
62
 
79
- NotFoundError = Class.new(ArgumentError)
80
- LoadError = Class.new(ArgumentError)
81
- CmdError = Class.new(RuntimeError)
63
+ def load_gemspec(path)
64
+ eval(path.read, TOPLEVEL_BINDING, path.expand_path.to_s)
65
+ rescue ScriptError, StandardError => e
66
+ original_line = e.backtrace.find{ |line| line.include?(path.to_s) }
67
+ msg = "There was a #{e.class} while loading #{path.basename}: \n#{e.message}"
68
+ msg << " from\n #{original_line}" if original_line
69
+ msg << "\n"
70
+ raise LoadError, msg
71
+ end
82
72
 
73
+ def get_push_host(spec)
74
+ ENV["GGEM_PUSH_HOST"] || get_meta(spec)[PUSH_HOST_META_KEY] || DEFAULT_PUSH_HOST
83
75
  end
84
76
 
77
+ def get_meta(spec)
78
+ (spec.respond_to?(:metadata) ? spec.metadata : {}) || {}
79
+ end
85
80
  end
@@ -1,60 +1,55 @@
1
1
  require "pathname"
2
2
  require "scmd"
3
3
 
4
- module GGem
4
+ module GGem; end
5
+ class GGem::GitRepo
6
+ NotFoundError = Class.new(ArgumentError)
7
+ CmdError = Class.new(RuntimeError)
5
8
 
6
- class GitRepo
9
+ attr_reader :path
7
10
 
8
- attr_reader :path
11
+ def initialize(repo_path)
12
+ @path = Pathname.new(File.expand_path(repo_path))
13
+ end
9
14
 
10
- def initialize(repo_path)
11
- @path = Pathname.new(File.expand_path(repo_path))
15
+ def run_init_cmd
16
+ run_cmd("git init").tap do
17
+ run_cmd("git add --all && git add -f *.keep")
12
18
  end
19
+ end
13
20
 
14
- def run_init_cmd
15
- run_cmd("git init").tap do
16
- run_cmd("git add --all && git add -f *.gitkeep")
17
- end
18
- end
21
+ def run_validate_clean_cmd
22
+ run_cmd("git diff --exit-code")
23
+ end
19
24
 
20
- def run_validate_clean_cmd
21
- run_cmd("git diff --exit-code")
22
- end
25
+ def run_validate_committed_cmd
26
+ run_cmd("git diff-index --quiet --cached HEAD")
27
+ end
23
28
 
24
- def run_validate_committed_cmd
25
- run_cmd("git diff-index --quiet --cached HEAD")
29
+ def run_push_cmd
30
+ run_cmd("git push").tap do
31
+ run_cmd("git push --tags")
26
32
  end
33
+ end
27
34
 
28
- def run_push_cmd
29
- run_cmd("git push").tap do
30
- run_cmd("git push --tags")
31
- end
32
- end
35
+ def run_add_version_tag_cmd(version, tag)
36
+ run_cmd("git tag -a -m \"Version #{version}\" #{tag}")
37
+ end
33
38
 
34
- def run_add_version_tag_cmd(version, tag)
35
- run_cmd("git tag -a -m \"Version #{version}\" #{tag}")
36
- end
39
+ def run_rm_tag_cmd(tag)
40
+ run_cmd("git tag -d #{tag}")
41
+ end
37
42
 
38
- def run_rm_tag_cmd(tag)
39
- run_cmd("git tag -d #{tag}")
40
- end
43
+ private
41
44
 
42
- private
43
-
44
- def run_cmd(cmd_string)
45
- cmd_string = "cd #{@path} && #{cmd_string}"
46
- cmd = Scmd.new(cmd_string)
47
- cmd.run
48
- if !cmd.success?
49
- raise CmdError, "#{cmd_string}\n" \
50
- "#{cmd.stderr.empty? ? cmd.stdout : cmd.stderr}"
51
- end
52
- [cmd_string, cmd.exitstatus, cmd.stdout]
45
+ def run_cmd(cmd_string)
46
+ cmd_string = "cd #{@path} && #{cmd_string}"
47
+ cmd = Scmd.new(cmd_string)
48
+ cmd.run
49
+ if !cmd.success?
50
+ raise CmdError, "#{cmd_string}\n" \
51
+ "#{cmd.stderr.empty? ? cmd.stdout : cmd.stderr}"
53
52
  end
54
-
55
- NotFoundError = Class.new(ArgumentError)
56
- CmdError = Class.new(RuntimeError)
57
-
53
+ [cmd_string, cmd.exitstatus, cmd.stdout]
58
54
  end
59
-
60
55
  end
@@ -1,70 +1,62 @@
1
1
  require "erb"
2
2
  require "fileutils"
3
3
 
4
- module GGem
5
-
6
- class Template
7
-
8
- def initialize(ggem)
9
- @gem = ggem
10
- end
11
-
12
- def save
13
- save_folder # (gem root path)
14
- save_folder ".circleci"
15
- save_folder "lib/#{@gem.ruby_name}"
16
- save_folder "test/support"
17
- save_folder "test/system"
18
- save_folder "test/unit"
19
- save_folder "log"
20
- save_folder "tmp"
21
-
22
- save_file("circleci_config.yml.erb", ".circleci/config.yml")
23
-
24
- save_file("ruby-version.erb", ".ruby-version")
25
- save_file("gitignore.erb", ".gitignore")
26
- save_file("Gemfile.erb", "Gemfile")
27
- save_file("gemspec.erb", "#{@gem.name}.gemspec")
28
- save_file("README.md.erb", "README.md")
29
- save_file("LICENSE.erb", "LICENSE")
30
-
31
- save_file("lib.rb.erb", "lib/#{@gem.ruby_name}.rb")
32
- save_file("lib_version.rb.erb", "lib/#{@gem.ruby_name}/version.rb")
33
-
34
- save_file("test_helper.rb.erb", "test/helper.rb")
35
- save_file("test_support_factory.rb.erb", "test/support/factory.rb")
4
+ module GGem; end
5
+ class GGem::Template
6
+ def initialize(ggem)
7
+ @ggem = ggem
8
+ end
36
9
 
37
- save_empty_file("log/.gitkeep")
38
- save_empty_file("test/system/.gitkeep")
39
- save_empty_file("test/unit/.gitkeep")
40
- save_empty_file("tmp/.gitkeep")
41
- end
10
+ def save
11
+ save_folder # (gem root path)
12
+ save_folder "lib/#{@ggem.ruby_name}"
13
+ save_folder "test/support"
14
+ save_folder "test/system"
15
+ save_folder "test/unit"
16
+ save_folder "log"
17
+ save_folder "tmp"
18
+
19
+ save_file("ruby-version.erb", ".ruby-version")
20
+ save_file("gitignore.erb", ".gitignore")
21
+ save_file("Gemfile.erb", "Gemfile")
22
+ save_file("gemspec.erb", "#{@ggem.name}.gemspec")
23
+ save_file("README.md.erb", "README.md")
24
+ save_file("LICENSE.erb", "LICENSE")
25
+
26
+ save_file("lib.rb.erb", "lib/#{@ggem.ruby_name}.rb")
27
+ save_file("lib_version.rb.erb", "lib/#{@ggem.ruby_name}/version.rb")
28
+
29
+ save_file("test_helper.rb.erb", "test/helper.rb")
30
+ save_file("test_support_factory.rb.erb", "test/support/factory.rb")
31
+
32
+ save_empty_file("log/.keep")
33
+ save_empty_file("test/system/.keep")
34
+ save_empty_file("test/unit/.keep")
35
+ save_empty_file("tmp/.keep")
36
+ end
42
37
 
43
- private
38
+ private
44
39
 
45
- def save_folder(relative_path=nil)
46
- path = File.join([@gem.path, relative_path].compact)
47
- FileUtils.mkdir_p(path)
48
- end
40
+ def save_folder(relative_path=nil)
41
+ path = File.join([@ggem.path, relative_path].compact)
42
+ FileUtils.mkdir_p(path)
43
+ end
49
44
 
50
- def save_empty_file(relative_path)
51
- path = File.join(@gem.path, relative_path)
52
- FileUtils.touch(path)
53
- end
45
+ def save_empty_file(relative_path)
46
+ path = File.join(@ggem.path, relative_path)
47
+ FileUtils.touch(path)
48
+ end
54
49
 
55
- def save_file(source, output)
56
- source_file = File.join(File.dirname(__FILE__), "template_file", source)
57
- output_file = File.join(@gem.root_path, @gem.name, output)
50
+ def save_file(source, output)
51
+ source_file = File.join(File.dirname(__FILE__), "template_file", source)
52
+ output_file = File.join(@ggem.root_path, @ggem.name, output)
58
53
 
59
- if File.exists?(source_file)
60
- FileUtils.mkdir_p(File.dirname(output_file))
61
- erb = ERB.new(File.read(source_file))
62
- File.open(output_file, "w") {|f| f << erb.result(binding) }
63
- else
64
- raise ArgumentError, "the source file `#{source_file}` does not exist"
65
- end
54
+ if File.exists?(source_file)
55
+ FileUtils.mkdir_p(File.dirname(output_file))
56
+ erb = ERB.new(File.read(source_file))
57
+ File.open(output_file, "w") {|f| f << erb.result(binding) }
58
+ else
59
+ raise ArgumentError, "the source file `#{source_file}` does not exist"
66
60
  end
67
-
68
61
  end
69
-
70
62
  end
@@ -1,7 +1,7 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- ruby '> 1.8'
3
+ ruby "~> 2.5"
4
4
 
5
5
  gemspec
6
6
 
7
- gem "pry", "~> 0.11.3"
7
+ gem "pry", "~> 0.12.2"
@@ -1,4 +1,4 @@
1
- # <%= @gem.module_name %>
1
+ # <%= @ggem.module_name %>
2
2
 
3
3
  TODO: Write a gem description
4
4
 
@@ -10,7 +10,7 @@ TODO: Write code samples and usage instructions here
10
10
 
11
11
  Add this line to your application's Gemfile:
12
12
 
13
- gem "<%= @gem.name %>"
13
+ gem "<%= @ggem.name %>"
14
14
 
15
15
  And then execute:
16
16
 
@@ -18,7 +18,7 @@ And then execute:
18
18
 
19
19
  Or install it yourself as:
20
20
 
21
- $ gem install <%= @gem.name %>
21
+ $ gem install <%= @ggem.name %>
22
22
 
23
23
  ## Contributing
24
24
 
@@ -1,11 +1,11 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  lib = File.expand_path("../lib", __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "<%= @gem.ruby_name %>/version"
4
+ require "<%= @ggem.ruby_name %>/version"
5
5
 
6
6
  Gem::Specification.new do |gem|
7
- gem.name = "<%= @gem.name %>"
8
- gem.version = <%= @gem.module_name %>::VERSION
7
+ gem.name = "<%= @ggem.name %>"
8
+ gem.version = <%= @ggem.module_name %>::VERSION
9
9
  gem.authors = ["TODO: authors"]
10
10
  gem.email = ["TODO: emails"]
11
11
  gem.summary = "TODO: Write a gem summary"
@@ -18,10 +18,9 @@ Gem::Specification.new do |gem|
18
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
19
  gem.require_paths = ["lib"]
20
20
 
21
- gem.required_ruby_version = '> 1.8'
21
+ gem.required_ruby_version = "~> 2.5"
22
22
 
23
- gem.add_development_dependency("assert", ["~> 2.17.0"])
23
+ gem.add_development_dependency("assert", ["~> 2.18.2"])
24
24
 
25
25
  # TODO: gem.add_dependency("gem-name", ["~> 0.0.0"])
26
-
27
26
  end
@@ -1,5 +1,5 @@
1
- require "<%= @gem.ruby_name %>/version"
1
+ require "<%= @ggem.ruby_name %>/version"
2
2
 
3
- module <%= @gem.module_name %>
3
+ module <%= @ggem.module_name %>
4
4
  # TODO: your code goes here...
5
5
  end
@@ -1,3 +1,3 @@
1
- module <%= @gem.module_name %>
1
+ module <%= @ggem.module_name %>
2
2
  VERSION = "0.0.1"
3
3
  end
@@ -1 +1 @@
1
- 2.3.7
1
+ 2.5.5