ggem 1.9.0 → 1.9.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.
@@ -1,58 +1,60 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "fileutils"
2
4
  require "ggem/template"
3
5
 
4
- module GGem
6
+ module GGem; end
7
+ class GGem::Gem
8
+ NoNameError = Class.new(ArgumentError)
5
9
 
6
- class Gem
10
+ attr_reader :root_path, :name
7
11
 
8
- attr_reader :root_path, :name
12
+ def initialize(path, name)
13
+ raise NoNameError if name.to_s.empty?
14
+ @root_path, self.name = path, name
15
+ end
9
16
 
10
- def initialize(path, name)
11
- raise NoNameError if name.to_s.empty?
12
- @root_path, self.name = path, name
13
- end
17
+ def save!
18
+ GGem::Template.new(self).save
19
+ self
20
+ end
14
21
 
15
- def save!
16
- Template.new(self).save
17
- self
18
- end
22
+ def path
23
+ File.join(@root_path, @name)
24
+ end
19
25
 
20
- def path; File.join(@root_path, @name); end
21
- def name=(name); @name = normalize_name(name); end
26
+ def name=(name)
27
+ @name = normalize_name(name)
28
+ end
22
29
 
23
- def module_name
24
- transforms = {
25
- "_" => "",
26
- "-" => ""
27
- }
28
- @module_name ||= transform_name(transforms){ |part| part.capitalize }
29
- end
30
+ def module_name
31
+ transforms = {
32
+ "_" => "",
33
+ "-" => ""
34
+ }
35
+ @module_name ||= transform_name(transforms){ |part| part.capitalize }
36
+ end
30
37
 
31
- def ruby_name
32
- @ruby_name ||= transform_name{ |part| part.downcase }
33
- end
38
+ def ruby_name
39
+ @ruby_name ||= transform_name{ |part| part.downcase }
40
+ end
34
41
 
35
- private
42
+ private
36
43
 
37
- def normalize_name(name)
38
- und_camelcs = [ /([A-Z])([a-z])/, '_\1\2' ]
39
- rm_dup_und = [ /_+/, "_" ]
40
- rm_lead_und = [ /^_/, "" ]
41
- name.gsub(*und_camelcs).gsub(*rm_dup_und).sub(*rm_lead_und).downcase
42
- end
44
+ def normalize_name(name)
45
+ und_camelcs = [/([A-Z])([a-z])/, '_\1\2']
46
+ rm_dup_und = [/_+/, "_"]
47
+ rm_lead_und = [/^_/, "" ]
48
+ name.gsub(*und_camelcs).gsub(*rm_dup_und).sub(*rm_lead_und).downcase
49
+ end
43
50
 
44
- def transform_name(conditions = {}, &block)
45
- n = (block ? block.call(self.name) : self.name)
46
- conditions.each do |on, glue|
47
- if (a = n.split(on)).size > 1
48
- n = a.map{ |part| block.call(part) if block }.join(glue)
49
- end
51
+ def transform_name(conditions = {}, &block)
52
+ n = (block ? block.call(self.name) : self.name)
53
+ conditions.each do |on, glue|
54
+ if (a = n.split(on)).size > 1
55
+ n = a.map{ |part| block.call(part) if block }.join(glue)
50
56
  end
51
- n
52
57
  end
53
-
54
- NoNameError = Class.new(ArgumentError)
55
-
58
+ n
56
59
  end
57
-
58
60
  end
@@ -1,85 +1,82 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "pathname"
2
4
  require "scmd"
3
5
 
4
- module GGem
5
-
6
- class Gemspec
6
+ module GGem; end
7
+ class GGem::Gemspec
8
+ PUSH_HOST_META_KEY = "allowed_push_host"
9
+ DEFAULT_PUSH_HOST = "https://rubygems.org".freeze
10
+ BUILD_TO_DIRNAME = "pkg".freeze
7
11
 
8
- PUSH_HOST_META_KEY = "allowed_push_host"
9
- DEFAULT_PUSH_HOST = "https://rubygems.org".freeze
10
- BUILD_TO_DIRNAME = "pkg".freeze
12
+ NotFoundError = Class.new(ArgumentError)
13
+ LoadError = Class.new(ArgumentError)
14
+ CmdError = Class.new(RuntimeError)
11
15
 
12
- attr_reader :path, :name, :version, :version_tag
13
- attr_reader :gem_file_name, :gem_file, :push_host
16
+ attr_reader :path, :name, :version, :version_tag
17
+ attr_reader :gem_file_name, :gem_file, :push_host
14
18
 
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?
19
+ def initialize(root_path)
20
+ @root = Pathname.new(File.expand_path(root_path))
21
+ raise NotFoundError unless @root.exist?
22
+ @path = Pathname.new(Dir[File.join(@root, "{,*}.gemspec")].first.to_s)
23
+ raise NotFoundError unless @path.exist?
20
24
 
21
- @spec = load_gemspec(@path)
22
- @name = @spec.name
23
- @version = @spec.version
24
- @version_tag = "v#{@version}"
25
+ @spec = load_gemspec(@path)
26
+ @name = @spec.name
27
+ @version = @spec.version
28
+ @version_tag = "v#{@version}"
25
29
 
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)
30
+ @gem_file_name = "#{@name}-#{@version}.gem"
31
+ @gem_file = File.join(BUILD_TO_DIRNAME, @gem_file_name)
32
+ @built_gem_path = @root.join(@gem_file)
29
33
 
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
34
+ @push_host = get_push_host(@spec)
35
+ end
44
36
 
45
- def run_push_cmd
46
- run_cmd("gem push #{@built_gem_path} --host #{@push_host}")
37
+ def run_build_cmd
38
+ run_cmd("gem build --verbose #{@path}").tap do
39
+ gem_path = @root.join(@gem_file_name)
40
+ run_cmd("mkdir -p #{@built_gem_path.dirname}")
41
+ run_cmd("mv #{gem_path} #{@built_gem_path}")
47
42
  end
43
+ end
48
44
 
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
45
+ def run_install_cmd
46
+ run_cmd("gem install #{@built_gem_path}")
47
+ end
60
48
 
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
49
+ def run_push_cmd
50
+ run_cmd("gem push #{@built_gem_path} --host #{@push_host}")
51
+ end
70
52
 
71
- def get_push_host(spec)
72
- ENV["GGEM_PUSH_HOST"] || get_meta(spec)[PUSH_HOST_META_KEY] || DEFAULT_PUSH_HOST
73
- end
53
+ private
74
54
 
75
- def get_meta(spec)
76
- (spec.respond_to?(:metadata) ? spec.metadata : {}) || {}
55
+ def run_cmd(cmd_string)
56
+ cmd = Scmd.new(cmd_string)
57
+ cmd.run
58
+ if !cmd.success?
59
+ raise CmdError, "#{cmd_string}\n" \
60
+ "#{cmd.stderr.empty? ? cmd.stdout : cmd.stderr}"
77
61
  end
62
+ [cmd_string, cmd.exitstatus, cmd.stdout]
63
+ end
78
64
 
79
- NotFoundError = Class.new(ArgumentError)
80
- LoadError = Class.new(ArgumentError)
81
- CmdError = Class.new(RuntimeError)
65
+ def load_gemspec(path)
66
+ eval(path.read, TOPLEVEL_BINDING, path.expand_path.to_s)
67
+ rescue ScriptError, StandardError => e
68
+ original_line = e.backtrace.find{ |line| line.include?(path.to_s) }
69
+ msg = "There was a #{e.class} while loading #{path.basename}: \n#{e.message}"
70
+ msg << " from\n #{original_line}" if original_line
71
+ msg << "\n"
72
+ raise LoadError, msg
73
+ end
82
74
 
75
+ def get_push_host(spec)
76
+ ENV["GGEM_PUSH_HOST"] || get_meta(spec)[PUSH_HOST_META_KEY] || DEFAULT_PUSH_HOST
83
77
  end
84
78
 
79
+ def get_meta(spec)
80
+ (spec.respond_to?(:metadata) ? spec.metadata : {}) || {}
81
+ end
85
82
  end
@@ -1,60 +1,57 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "pathname"
2
4
  require "scmd"
3
5
 
4
- module GGem
6
+ module GGem; end
7
+ class GGem::GitRepo
8
+ NotFoundError = Class.new(ArgumentError)
9
+ CmdError = Class.new(RuntimeError)
5
10
 
6
- class GitRepo
11
+ attr_reader :path
7
12
 
8
- attr_reader :path
13
+ def initialize(repo_path)
14
+ @path = Pathname.new(File.expand_path(repo_path))
15
+ end
9
16
 
10
- def initialize(repo_path)
11
- @path = Pathname.new(File.expand_path(repo_path))
17
+ def run_init_cmd
18
+ run_cmd("git init").tap do
19
+ run_cmd("git add --all && git add -f *.keep")
12
20
  end
21
+ end
13
22
 
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
23
+ def run_validate_clean_cmd
24
+ run_cmd("git diff --exit-code")
25
+ end
19
26
 
20
- def run_validate_clean_cmd
21
- run_cmd("git diff --exit-code")
22
- end
27
+ def run_validate_committed_cmd
28
+ run_cmd("git diff-index --quiet --cached HEAD")
29
+ end
23
30
 
24
- def run_validate_committed_cmd
25
- run_cmd("git diff-index --quiet --cached HEAD")
31
+ def run_push_cmd
32
+ run_cmd("git push").tap do
33
+ run_cmd("git push --tags")
26
34
  end
35
+ end
27
36
 
28
- def run_push_cmd
29
- run_cmd("git push").tap do
30
- run_cmd("git push --tags")
31
- end
32
- end
37
+ def run_add_version_tag_cmd(version, tag)
38
+ run_cmd("git tag -a -m \"Version #{version}\" #{tag}")
39
+ end
33
40
 
34
- def run_add_version_tag_cmd(version, tag)
35
- run_cmd("git tag -a -m \"Version #{version}\" #{tag}")
36
- end
41
+ def run_rm_tag_cmd(tag)
42
+ run_cmd("git tag -d #{tag}")
43
+ end
37
44
 
38
- def run_rm_tag_cmd(tag)
39
- run_cmd("git tag -d #{tag}")
40
- end
45
+ private
41
46
 
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]
47
+ def run_cmd(cmd_string)
48
+ cmd_string = "cd #{@path} && #{cmd_string}"
49
+ cmd = Scmd.new(cmd_string)
50
+ cmd.run
51
+ if !cmd.success?
52
+ raise CmdError, "#{cmd_string}\n" \
53
+ "#{cmd.stderr.empty? ? cmd.stdout : cmd.stderr}"
53
54
  end
54
-
55
- NotFoundError = Class.new(ArgumentError)
56
- CmdError = Class.new(RuntimeError)
57
-
55
+ [cmd_string, cmd.exitstatus, cmd.stdout]
58
56
  end
59
-
60
57
  end
@@ -1,69 +1,64 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "erb"
2
4
  require "fileutils"
3
5
 
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("gitignore.erb", ".gitignore")
25
- save_file("Gemfile.erb", "Gemfile")
26
- save_file("gemspec.erb", "#{@gem.name}.gemspec")
27
- save_file("README.md.erb", "README.md")
28
- save_file("LICENSE.erb", "LICENSE")
29
-
30
- save_file("lib.rb.erb", "lib/#{@gem.ruby_name}.rb")
31
- save_file("lib_version.rb.erb", "lib/#{@gem.ruby_name}/version.rb")
32
-
33
- save_file("test_helper.rb.erb", "test/helper.rb")
34
- save_file("test_support_factory.rb.erb", "test/support/factory.rb")
6
+ module GGem; end
7
+ class GGem::Template
8
+ def initialize(ggem)
9
+ @ggem = ggem
10
+ end
35
11
 
36
- save_empty_file("log/.gitkeep")
37
- save_empty_file("test/system/.gitkeep")
38
- save_empty_file("test/unit/.gitkeep")
39
- save_empty_file("tmp/.gitkeep")
40
- end
12
+ def save
13
+ save_folder # (gem root path)
14
+ save_folder "lib/#{@ggem.ruby_name}"
15
+ save_folder "test/support"
16
+ save_folder "test/system"
17
+ save_folder "test/unit"
18
+ save_folder "log"
19
+ save_folder "tmp"
20
+
21
+ save_file("ruby-version.erb", ".ruby-version")
22
+ save_file("gitignore.erb", ".gitignore")
23
+ save_file("Gemfile.erb", "Gemfile")
24
+ save_file("gemspec.erb", "#{@ggem.name}.gemspec")
25
+ save_file("README.md.erb", "README.md")
26
+ save_file("LICENSE.erb", "LICENSE")
27
+
28
+ save_file("lib.rb.erb", "lib/#{@ggem.ruby_name}.rb")
29
+ save_file("lib_version.rb.erb", "lib/#{@ggem.ruby_name}/version.rb")
30
+
31
+ save_file("test_helper.rb.erb", "test/helper.rb")
32
+ save_file("test_support_factory.rb.erb", "test/support/factory.rb")
33
+
34
+ save_empty_file("log/.keep")
35
+ save_empty_file("test/system/.keep")
36
+ save_empty_file("test/unit/.keep")
37
+ save_empty_file("tmp/.keep")
38
+ end
41
39
 
42
- private
40
+ private
43
41
 
44
- def save_folder(relative_path=nil)
45
- path = File.join([@gem.path, relative_path].compact)
46
- FileUtils.mkdir_p(path)
47
- end
42
+ def save_folder(relative_path=nil)
43
+ path = File.join([@ggem.path, relative_path].compact)
44
+ FileUtils.mkdir_p(path)
45
+ end
48
46
 
49
- def save_empty_file(relative_path)
50
- path = File.join(@gem.path, relative_path)
51
- FileUtils.touch(path)
52
- end
47
+ def save_empty_file(relative_path)
48
+ path = File.join(@ggem.path, relative_path)
49
+ FileUtils.touch(path)
50
+ end
53
51
 
54
- def save_file(source, output)
55
- source_file = File.join(File.dirname(__FILE__), "template_file", source)
56
- output_file = File.join(@gem.root_path, @gem.name, output)
52
+ def save_file(source, output)
53
+ source_file = File.join(File.dirname(__FILE__), "template_file", source)
54
+ output_file = File.join(@ggem.root_path, @ggem.name, output)
57
55
 
58
- if File.exists?(source_file)
59
- FileUtils.mkdir_p(File.dirname(output_file))
60
- erb = ERB.new(File.read(source_file))
61
- File.open(output_file, "w") {|f| f << erb.result(binding) }
62
- else
63
- raise ArgumentError, "the source file `#{source_file}` does not exist"
64
- end
56
+ if File.exists?(source_file)
57
+ FileUtils.mkdir_p(File.dirname(output_file))
58
+ erb = ERB.new(File.read(source_file))
59
+ File.open(output_file, "w") {|f| f << erb.result(binding) }
60
+ else
61
+ raise ArgumentError, "the source file `#{source_file}` does not exist"
65
62
  end
66
-
67
63
  end
68
-
69
64
  end