ggem 1.8.3 → 1.9.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,58 +1,58 @@
1
- require 'fileutils'
2
- require 'ggem/template'
1
+ require "fileutils"
2
+ require "ggem/template"
3
3
 
4
- module GGem
4
+ module GGem; end
5
+ class GGem::Gem
6
+ NoNameError = Class.new(ArgumentError)
5
7
 
6
- class Gem
8
+ attr_reader :root_path, :name
7
9
 
8
- attr_reader :root_path, :name
10
+ def initialize(path, name)
11
+ raise NoNameError if name.to_s.empty?
12
+ @root_path, self.name = path, name
13
+ end
9
14
 
10
- def initialize(path, name)
11
- raise NoNameError if name.to_s.empty?
12
- @root_path, self.name = path, name
13
- end
15
+ def save!
16
+ GGem::Template.new(self).save
17
+ self
18
+ end
14
19
 
15
- def save!
16
- Template.new(self).save
17
- self
18
- end
20
+ def path
21
+ File.join(@root_path, @name)
22
+ end
19
23
 
20
- def path; File.join(@root_path, @name); end
21
- def name=(name); @name = normalize_name(name); end
24
+ def name=(name)
25
+ @name = normalize_name(name)
26
+ end
22
27
 
23
- def module_name
24
- transforms = {
25
- '_' => '',
26
- '-' => ''
27
- }
28
- @module_name ||= transform_name(transforms){ |part| part.capitalize }
29
- end
28
+ def module_name
29
+ transforms = {
30
+ "_" => "",
31
+ "-" => ""
32
+ }
33
+ @module_name ||= transform_name(transforms){ |part| part.capitalize }
34
+ end
30
35
 
31
- def ruby_name
32
- @ruby_name ||= transform_name{ |part| part.downcase }
33
- end
36
+ def ruby_name
37
+ @ruby_name ||= transform_name{ |part| part.downcase }
38
+ end
34
39
 
35
- private
40
+ private
36
41
 
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
42
+ def normalize_name(name)
43
+ und_camelcs = [/([A-Z])([a-z])/, '_\1\2']
44
+ rm_dup_und = [/_+/, "_"]
45
+ rm_lead_und = [/^_/, "" ]
46
+ name.gsub(*und_camelcs).gsub(*rm_dup_und).sub(*rm_lead_und).downcase
47
+ end
43
48
 
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
49
+ def transform_name(conditions = {}, &block)
50
+ n = (block ? block.call(self.name) : self.name)
51
+ conditions.each do |on, glue|
52
+ if (a = n.split(on)).size > 1
53
+ n = a.map{ |part| block.call(part) if block }.join(glue)
50
54
  end
51
- n
52
55
  end
53
-
54
- NoNameError = Class.new(ArgumentError)
55
-
56
+ n
56
57
  end
57
-
58
58
  end
@@ -1,85 +1,80 @@
1
- require 'pathname'
2
- require 'scmd'
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
1
+ require "pathname"
2
+ require "scmd"
3
+
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
- require 'pathname'
2
- require 'scmd'
1
+ require "pathname"
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,64 +1,62 @@
1
- require 'erb'
2
- require 'fileutils'
1
+ require "erb"
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 "lib/#{@gem.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('gitignore.erb', '.gitignore')
22
- save_file('Gemfile.erb', 'Gemfile')
23
- save_file('gemspec.erb', "#{@gem.name}.gemspec")
24
- save_file('README.md.erb', 'README.md')
25
- save_file('LICENSE.erb', 'LICENSE')
26
-
27
- save_file('lib.rb.erb', "lib/#{@gem.ruby_name}.rb")
28
- save_file('lib_version.rb.erb', "lib/#{@gem.ruby_name}/version.rb")
29
-
30
- save_file('test_helper.rb.erb', 'test/helper.rb')
31
- 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
32
9
 
33
- save_empty_file('log/.gitkeep')
34
- save_empty_file('tmp/.gitkeep')
35
- 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
36
37
 
37
- private
38
+ private
38
39
 
39
- def save_folder(relative_path=nil)
40
- path = File.join([@gem.path, relative_path].compact)
41
- FileUtils.mkdir_p(path)
42
- end
40
+ def save_folder(relative_path=nil)
41
+ path = File.join([@ggem.path, relative_path].compact)
42
+ FileUtils.mkdir_p(path)
43
+ end
43
44
 
44
- def save_empty_file(relative_path)
45
- path = File.join(@gem.path, relative_path)
46
- FileUtils.touch(path)
47
- end
45
+ def save_empty_file(relative_path)
46
+ path = File.join(@ggem.path, relative_path)
47
+ FileUtils.touch(path)
48
+ end
48
49
 
49
- def save_file(source, output)
50
- source_file = File.join(File.dirname(__FILE__), 'template_file', source)
51
- 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)
52
53
 
53
- if File.exists?(source_file)
54
- FileUtils.mkdir_p(File.dirname(output_file))
55
- erb = ERB.new(File.read(source_file))
56
- File.open(output_file, 'w') {|f| f << erb.result(binding) }
57
- else
58
- raise ArgumentError, "the source file '#{source_file}' does not exist"
59
- 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"
60
60
  end
61
-
62
61
  end
63
-
64
62
  end