kamaze-project 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +9 -9
  3. data/lib/kamaze-project.rb +1 -31
  4. data/lib/kamaze/project.rb +37 -31
  5. data/lib/kamaze/project/autoload.rb +38 -0
  6. data/lib/kamaze/project/boot/core_ext.rb +8 -8
  7. data/lib/kamaze/project/boot/listen.rb +11 -13
  8. data/lib/kamaze/project/bundled.rb +79 -0
  9. data/lib/kamaze/project/concern.rb +17 -2
  10. data/lib/kamaze/project/concern/cli.rb +3 -1
  11. data/lib/kamaze/project/concern/cli/with_exit_on_failure.rb +2 -6
  12. data/lib/kamaze/project/concern/env.rb +14 -12
  13. data/lib/kamaze/project/concern/helper.rb +1 -2
  14. data/lib/kamaze/project/concern/mode.rb +1 -1
  15. data/lib/kamaze/project/concern/observable.rb +12 -11
  16. data/lib/kamaze/project/concern/sh.rb +7 -7
  17. data/lib/kamaze/project/concern/tasks.rb +36 -10
  18. data/lib/kamaze/project/concern/tools.rb +2 -3
  19. data/lib/kamaze/project/config.rb +1 -1
  20. data/lib/kamaze/project/core_ext/object.rb +17 -8
  21. data/lib/kamaze/project/core_ext/pp.rb +14 -16
  22. data/lib/kamaze/project/debug.rb +47 -48
  23. data/lib/kamaze/project/dsl.rb +9 -5
  24. data/lib/kamaze/project/dsl/definition.rb +6 -12
  25. data/lib/kamaze/project/dsl/setup.rb +1 -3
  26. data/lib/kamaze/project/helper.rb +1 -1
  27. data/lib/kamaze/project/helper/inflector.rb +9 -27
  28. data/lib/kamaze/project/helper/project.rb +1 -1
  29. data/lib/kamaze/project/helper/project/config.rb +1 -1
  30. data/lib/kamaze/project/inflector.rb +15 -0
  31. data/lib/kamaze/project/observable.rb +1 -4
  32. data/lib/kamaze/project/observer.rb +1 -1
  33. data/lib/kamaze/project/resources/Vagrantfile +1 -1
  34. data/lib/kamaze/project/struct.rb +1 -1
  35. data/lib/kamaze/project/tasks/cs.rb +1 -1
  36. data/lib/kamaze/project/tasks/cs/control.rb +1 -1
  37. data/lib/kamaze/project/tasks/cs/correct.rb +1 -1
  38. data/lib/kamaze/project/tasks/cs/pre_commit.rb +4 -6
  39. data/lib/kamaze/project/tasks/doc.rb +2 -4
  40. data/lib/kamaze/project/tasks/doc/watch.rb +4 -6
  41. data/lib/kamaze/project/tasks/gem.rb +15 -6
  42. data/lib/kamaze/project/tasks/gem/build.rb +33 -17
  43. data/lib/kamaze/project/tasks/gem/compile.rb +1 -1
  44. data/lib/kamaze/project/tasks/gem/gemspec.rb +12 -11
  45. data/lib/kamaze/project/tasks/gem/install.rb +1 -1
  46. data/lib/kamaze/project/tasks/gem/push.rb +16 -17
  47. data/lib/kamaze/project/tasks/misc/gitignore.rb +1 -1
  48. data/lib/kamaze/project/tasks/shell.rb +1 -1
  49. data/lib/kamaze/project/tasks/sources.rb +1 -1
  50. data/lib/kamaze/project/tasks/sources/license.rb +1 -1
  51. data/lib/kamaze/project/tasks/test.rb +3 -5
  52. data/lib/kamaze/project/tasks/vagrant.rb +1 -1
  53. data/lib/kamaze/project/tasks/version/edit.rb +1 -1
  54. data/lib/kamaze/project/tools.rb +18 -6
  55. data/lib/kamaze/project/tools/base_tool.rb +6 -2
  56. data/lib/kamaze/project/tools/console.rb +4 -13
  57. data/lib/kamaze/project/tools/console/output.rb +14 -6
  58. data/lib/kamaze/project/tools/console/output/buffer.rb +8 -3
  59. data/lib/kamaze/project/tools/gemspec.rb +11 -21
  60. data/lib/kamaze/project/tools/gemspec/builder.rb +43 -31
  61. data/lib/kamaze/project/tools/gemspec/concern.rb +6 -1
  62. data/lib/kamaze/project/tools/gemspec/concern/reading.rb +2 -5
  63. data/lib/kamaze/project/tools/gemspec/packager.rb +10 -10
  64. data/lib/kamaze/project/tools/gemspec/packer.rb +11 -15
  65. data/lib/kamaze/project/tools/gemspec/packer/command.rb +1 -1
  66. data/lib/kamaze/project/tools/gemspec/reader.rb +22 -14
  67. data/lib/kamaze/project/tools/gemspec/reader/decorator.rb +3 -6
  68. data/lib/kamaze/project/tools/gemspec/writer.rb +43 -19
  69. data/lib/kamaze/project/tools/gemspec/writer/dep_gen.rb +9 -6
  70. data/lib/kamaze/project/tools/gemspec/writer/dependency.rb +1 -1
  71. data/lib/kamaze/project/tools/git.rb +13 -31
  72. data/lib/kamaze/project/tools/git/hooks.rb +12 -6
  73. data/lib/kamaze/project/tools/git/hooks/base_hook.rb +3 -11
  74. data/lib/kamaze/project/tools/git/hooks/pre_commit.rb +3 -7
  75. data/lib/kamaze/project/tools/git/status.rb +13 -9
  76. data/lib/kamaze/project/tools/git/status/decorator.rb +1 -1
  77. data/lib/kamaze/project/tools/git/status/file.rb +2 -1
  78. data/lib/kamaze/project/tools/git/status/files_array.rb +1 -1
  79. data/lib/kamaze/project/tools/git/status/index.rb +1 -1
  80. data/lib/kamaze/project/tools/git/status/worktree.rb +1 -1
  81. data/lib/kamaze/project/tools/git/util.rb +1 -1
  82. data/lib/kamaze/project/tools/licenser.rb +2 -2
  83. data/lib/kamaze/project/tools/packager.rb +12 -22
  84. data/lib/kamaze/project/tools/packager/filesystem.rb +11 -3
  85. data/lib/kamaze/project/tools/packager/filesystem/operator.rb +19 -11
  86. data/lib/kamaze/project/tools/packager/filesystem/operator/utils.rb +22 -16
  87. data/lib/kamaze/project/tools/process_locker.rb +67 -36
  88. data/lib/kamaze/project/tools/rspec.rb +5 -3
  89. data/lib/kamaze/project/tools/rubocop.rb +30 -40
  90. data/lib/kamaze/project/tools/rubocop/arguments.rb +1 -1
  91. data/lib/kamaze/project/tools/rubocop/config.rb +2 -4
  92. data/lib/kamaze/project/tools/shell.rb +7 -8
  93. data/lib/kamaze/project/tools/vagrant.rb +6 -16
  94. data/lib/kamaze/project/tools/vagrant/composer.rb +1 -1
  95. data/lib/kamaze/project/tools/vagrant/composer/file.rb +1 -1
  96. data/lib/kamaze/project/tools/vagrant/remote.rb +1 -1
  97. data/lib/kamaze/project/tools/vagrant/shell.rb +1 -1
  98. data/lib/kamaze/project/tools/vagrant/writer.rb +1 -1
  99. data/lib/kamaze/project/tools/yardoc.rb +14 -17
  100. data/lib/kamaze/project/tools/yardoc/file.rb +7 -7
  101. data/lib/kamaze/project/tools/yardoc/watchable.rb +9 -15
  102. data/lib/kamaze/project/tools/yardoc/watcher.rb +28 -35
  103. data/lib/kamaze/project/tools_provider.rb +28 -40
  104. data/lib/kamaze/project/tools_provider/resolver.rb +1 -1
  105. data/lib/kamaze/project/version.rb +5 -94
  106. data/lib/kamaze/project/version.yml +5 -5
  107. metadata +23 -64
  108. data/bin/plop +0 -5
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (C) 2017-2018 Dimitri Arrigoni <dimitri@arrigoni.me>
3
+ # Copyright (C) 2017-2021 Dimitri Arrigoni <dimitri@arrigoni.me>
4
4
  # License GPLv3+: GNU GPL version 3 or later
5
5
  # <http://www.gnu.org/licenses/gpl.html>.
6
6
  # This is free software: you are free to change and redistribute it.
@@ -1,27 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (C) 2017-2018 Dimitri Arrigoni <dimitri@arrigoni.me>
3
+ # Copyright (C) 2017-2021 Dimitri Arrigoni <dimitri@arrigoni.me>
4
4
  # License GPLv3+: GNU GPL version 3 or later
5
5
  # <http://www.gnu.org/licenses/gpl.html>.
6
6
  # This is free software: you are free to change and redistribute it.
7
7
  # There is NO WARRANTY, to the extent permitted by law.
8
8
 
9
- [nil, :gem_runner, :exceptions].each do |req|
10
- require "rubygems/#{req}".rstrip('/')
11
- end
12
-
13
- # Code mostly based on gem executable
14
- #
15
- # @see http://guides.rubygems.org/publishing/
16
- # @see rubygems-tasks
17
- builder = tools.fetch(:gemspec_builder)
18
- desc 'Push gem up to the gem server'
19
- task 'gem:push': [builder.buildable] do
20
- args = [:push, builder.buildable].map(&:to_s)
9
+ [nil, :gem_runner, :exceptions].each { |req| require ['rubygems', req].compact.join('/') }
21
10
 
22
- begin
23
- Gem::GemRunner.new.run(args.map(&:to_s))
24
- rescue Gem::SystemExitException => e
25
- exit(e.exit_code)
11
+ tools.fetch(:gemspec_builder).tap do |builder|
12
+ # Code mostly based on gem executable
13
+ #
14
+ # @see http://guides.rubygems.org/publishing/
15
+ # @see rubygems-tasks
16
+ runner = lambda do
17
+ [:push, builder.buildable].map(&:to_s).yield_self do |args|
18
+ Gem::GemRunner.new.run(args.map(&:to_s))
19
+ rescue Gem::SystemExitException => e
20
+ exit(e.exit_code)
21
+ end
26
22
  end
23
+
24
+ desc 'Push gem up to the gem server'
25
+ task('gem:push': [builder.buildable]) { runner.call }
27
26
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (C) 2017-2018 Dimitri Arrigoni <dimitri@arrigoni.me>
3
+ # Copyright (C) 2017-2021 Dimitri Arrigoni <dimitri@arrigoni.me>
4
4
  # License GPLv3+: GNU GPL version 3 or later
5
5
  # <http://www.gnu.org/licenses/gpl.html>.
6
6
  # This is free software: you are free to change and redistribute it.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (C) 2017-2018 Dimitri Arrigoni <dimitri@arrigoni.me>
3
+ # Copyright (C) 2017-2021 Dimitri Arrigoni <dimitri@arrigoni.me>
4
4
  # License GPLv3+: GNU GPL version 3 or later
5
5
  # <http://www.gnu.org/licenses/gpl.html>.
6
6
  # This is free software: you are free to change and redistribute it.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- # Copyright (C) 2017-2018 Dimitri Arrigoni <dimitri@arrigoni.me>
2
+ # Copyright (C) 2017-2021 Dimitri Arrigoni <dimitri@arrigoni.me>
3
3
  # License GPLv3+: GNU GPL version 3 or later
4
4
  # <http://www.gnu.org/licenses/gpl.html>.
5
5
  # This is free software: you are free to change and redistribute it.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (C) 2017-2018 Dimitri Arrigoni <dimitri@arrigoni.me>
3
+ # Copyright (C) 2017-2021 Dimitri Arrigoni <dimitri@arrigoni.me>
4
4
  # License GPLv3+: GNU GPL version 3 or later
5
5
  # <http://www.gnu.org/licenses/gpl.html>.
6
6
  # This is free software: you are free to change and redistribute it.
@@ -1,16 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (C) 2017-2018 Dimitri Arrigoni <dimitri@arrigoni.me>
3
+ # Copyright (C) 2017-2021 Dimitri Arrigoni <dimitri@arrigoni.me>
4
4
  # License GPLv3+: GNU GPL version 3 or later
5
5
  # <http://www.gnu.org/licenses/gpl.html>.
6
6
  # This is free software: you are free to change and redistribute it.
7
7
  # There is NO WARRANTY, to the extent permitted by law.
8
8
 
9
9
  desc 'Run test suites'
10
- task :test do |task, args|
11
- tags = args.extras
12
-
10
+ task :test do |_task, args|
13
11
  tools.fetch(:rspec).tap do |rspec|
14
- rspec.tags = tags
12
+ rspec.tags = args.extras
15
13
  end.run
16
14
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (C) 2017-2018 Dimitri Arrigoni <dimitri@arrigoni.me>
3
+ # Copyright (C) 2017-2021 Dimitri Arrigoni <dimitri@arrigoni.me>
4
4
  # License GPLv3+: GNU GPL version 3 or later
5
5
  # <http://www.gnu.org/licenses/gpl.html>.
6
6
  # This is free software: you are free to change and redistribute it.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (C) 2017-2018 Dimitri Arrigoni <dimitri@arrigoni.me>
3
+ # Copyright (C) 2017-2021 Dimitri Arrigoni <dimitri@arrigoni.me>
4
4
  # License GPLv3+: GNU GPL version 3 or later
5
5
  # <http://www.gnu.org/licenses/gpl.html>.
6
6
  # This is free software: you are free to change and redistribute it.
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (C) 2017-2018 Dimitri Arrigoni <dimitri@arrigoni.me>
3
+ # Copyright (C) 2017-2021 Dimitri Arrigoni <dimitri@arrigoni.me>
4
4
  # License GPLv3+: GNU GPL version 3 or later
5
5
  # <http://www.gnu.org/licenses/gpl.html>.
6
6
  # This is free software: you are free to change and redistribute it.
@@ -9,10 +9,22 @@
9
9
  require_relative '../project'
10
10
  require_relative 'tools_provider'
11
11
 
12
- # rubocop:disable Style/Documentation
13
-
12
+ # Namespace for tools
14
13
  module Kamaze::Project::Tools
15
- require_relative 'tools/base_tool'
14
+ # @formatter:off
15
+ {
16
+ BaseTool: 'base_tool',
17
+ Console: 'console',
18
+ Gemspec: 'gemspec',
19
+ Git: 'git',
20
+ Licenser: 'licenser',
21
+ Packager: 'packager',
22
+ ProcessLocker: 'process_locker',
23
+ Rspec: 'rspec',
24
+ Rubocop: 'rubocop',
25
+ Shell: 'shell',
26
+ Vagrant: 'vagrant',
27
+ Yardoc: 'yardoc',
28
+ }.each { |k, v| autoload(k, "#{__dir__}/tools/#{v}") }
29
+ # @formatter:on
16
30
  end
17
-
18
- # rubocop:enable Style/Documentation
@@ -1,13 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (C) 2017-2018 Dimitri Arrigoni <dimitri@arrigoni.me>
3
+ # Copyright (C) 2017-2021 Dimitri Arrigoni <dimitri@arrigoni.me>
4
4
  # License GPLv3+: GNU GPL version 3 or later
5
5
  # <http://www.gnu.org/licenses/gpl.html>.
6
6
  # This is free software: you are free to change and redistribute it.
7
7
  # There is NO WARRANTY, to the extent permitted by law.
8
8
 
9
9
  require_relative '../tools'
10
- require_relative '../observable'
11
10
 
12
11
  # Provides base for tools
13
12
  #
@@ -28,6 +27,7 @@ class Kamaze::Project::Tools::BaseTool < Kamaze::Project::Observable
28
27
  # Mutable attributes become ``ro`` after initialization
29
28
  #
30
29
  # @return [Array]
30
+ # @abstract
31
31
  def mutable_attributes
32
32
  []
33
33
  end
@@ -35,6 +35,8 @@ class Kamaze::Project::Tools::BaseTool < Kamaze::Project::Observable
35
35
  protected
36
36
 
37
37
  # Execute additionnal setup
38
+ #
39
+ # @abstract
38
40
  def setup
39
41
  nil
40
42
  end
@@ -47,7 +49,9 @@ class Kamaze::Project::Tools::BaseTool < Kamaze::Project::Observable
47
49
  # @return [self]
48
50
  def attrs_mute!
49
51
  mutable_attributes.each do |m|
52
+ # rubocop:disable Style/AccessModifierDeclarations
50
53
  self.singleton_class.class_eval { protected "#{m}=" }
54
+ # rubocop:enable Style/AccessModifierDeclarations
51
55
  end
52
56
 
53
57
  self
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (C) 2017-2018 Dimitri Arrigoni <dimitri@arrigoni.me>
3
+ # Copyright (C) 2017-2021 Dimitri Arrigoni <dimitri@arrigoni.me>
4
4
  # License GPLv3+: GNU GPL version 3 or later
5
5
  # <http://www.gnu.org/licenses/gpl.html>.
6
6
  # This is free software: you are free to change and redistribute it.
@@ -8,22 +8,13 @@
8
8
 
9
9
  require_relative '../tools'
10
10
 
11
- # rubocop:disable Style/Documentation
12
-
13
- module Kamaze::Project::Tools
14
- class Console < BaseTool
15
- end
16
-
17
- require_relative 'console/output'
18
- end
19
-
20
- # rubocop:enable Style/Documentation
21
-
22
11
  # Provide access to a [console](https://en.wikipedia.org/wiki/System_console)
23
12
  # having two outputs: ``stdout`` and ``stderr``
24
13
  #
25
14
  # @see Kamaze::Project::Tools::Console::Output
26
- class Kamaze::Project::Tools::Console
15
+ class Kamaze::Project::Tools::Console < Kamaze::Project::Tools::BaseTool
16
+ autoload(:Output, "#{__dir__}/console/output")
17
+
27
18
  attr_writer :stdout
28
19
  attr_writer :stderr
29
20
 
@@ -1,13 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (C) 2017-2018 Dimitri Arrigoni <dimitri@arrigoni.me>
3
+ # Copyright (C) 2017-2021 Dimitri Arrigoni <dimitri@arrigoni.me>
4
4
  # License GPLv3+: GNU GPL version 3 or later
5
5
  # <http://www.gnu.org/licenses/gpl.html>.
6
6
  # This is free software: you are free to change and redistribute it.
7
7
  # There is NO WARRANTY, to the extent permitted by law.
8
8
 
9
9
  require_relative '../console'
10
- require_relative 'output/buffer'
11
10
 
12
11
  # Provide a console output
13
12
  #
@@ -23,6 +22,14 @@ require_relative 'output/buffer'
23
22
  # @see https://github.com/Shopify/cli-ui
24
23
  # @see http://ruby-doc.org/core-2.1.3/IO.html
25
24
  class Kamaze::Project::Tools::Console::Output
25
+ # @formatter:off
26
+ {
27
+ Buffer: 'buffer'
28
+ }.each do |s, fp|
29
+ autoload(s, "#{__dir__}/output/#{fp}")
30
+ end
31
+ # @formatter:on
32
+
26
33
  # @param [IO] to
27
34
  def initialize(to = $stdout)
28
35
  @output = to
@@ -42,9 +49,9 @@ class Kamaze::Project::Tools::Console::Output
42
49
  #
43
50
  # @return [self]
44
51
  def flush
45
- output.flush if output.respond_to?(:flush)
46
-
47
- self
52
+ self.tap do
53
+ output.flush if output.respond_to?(:flush)
54
+ end
48
55
  end
49
56
 
50
57
  def method_missing(method, *args, &block)
@@ -113,7 +120,8 @@ class Kamaze::Project::Tools::Console::Output
113
120
  # Bufferize given arguments
114
121
  #
115
122
  # @param [Array<String>] strings
116
- # @return [Array<String>]
123
+ #
124
+ # @return [Array<Buffer>|Array<String>]
117
125
  def bufferize(*strings)
118
126
  strings.to_a.map { |s| Buffer.new(self, s) }
119
127
  end
@@ -1,13 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (C) 2017-2018 Dimitri Arrigoni <dimitri@arrigoni.me>
3
+ # Copyright (C) 2017-2021 Dimitri Arrigoni <dimitri@arrigoni.me>
4
4
  # License GPLv3+: GNU GPL version 3 or later
5
5
  # <http://www.gnu.org/licenses/gpl.html>.
6
6
  # This is free software: you are free to change and redistribute it.
7
7
  # There is NO WARRANTY, to the extent permitted by law.
8
8
 
9
9
  require_relative '../output'
10
- require 'cli/ui'
11
10
 
12
11
  class Kamaze::Project::Tools::Console::Output
13
12
  class Buffer
@@ -43,6 +42,12 @@ class Kamaze::Project::Tools::Console::Output::Buffer
43
42
  # @param [String] str
44
43
  # @return [String]
45
44
  def decorate(str)
46
- CLI::UI.fmt(str.to_s, enable_color: output.tty?)
45
+ ui.fmt(str.to_s, enable_color: output.tty?)
46
+ end
47
+
48
+ def ui
49
+ require 'cli/ui'
50
+
51
+ CLI::UI
47
52
  end
48
53
  end
@@ -1,33 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (C) 2017-2018 Dimitri Arrigoni <dimitri@arrigoni.me>
3
+ # Copyright (C) 2017-2021 Dimitri Arrigoni <dimitri@arrigoni.me>
4
4
  # License GPLv3+: GNU GPL version 3 or later
5
5
  # <http://www.gnu.org/licenses/gpl.html>.
6
6
  # This is free software: you are free to change and redistribute it.
7
7
  # There is NO WARRANTY, to the extent permitted by law.
8
8
 
9
9
  require_relative '../tools'
10
- require_relative 'packager'
11
10
 
12
11
  # Module providng several tools based on gemspec reader/writer
13
12
  module Kamaze::Project::Tools::Gemspec
14
- class Reader < Kamaze::Project::Tools::BaseTool
15
- end
16
-
17
- class Writer < Kamaze::Project::Tools::BaseTool
18
- end
19
-
20
- # @abstract
21
- class Packager < Kamaze::Project::Tools::Packager
22
- end
23
-
24
- class Builder < Packager
25
- end
26
-
27
- class Packer < Packager
28
- end
29
-
30
- [:packager,
31
- :reader, :writer,
32
- :builder, :packer].each { |req| require_relative "gemspec/#{req}" }
13
+ # @formatter:off
14
+ {
15
+ Reader: 'reader',
16
+ Writer: 'writer',
17
+ Packager: 'packager',
18
+ Builder: 'builder',
19
+ Concern: 'concern',
20
+ Packer: 'packer',
21
+ }.each { |s, fp| autoload(s, "#{__dir__}/gemspec/#{fp}") }
22
+ # @formatter:on
33
23
  end
@@ -1,16 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (C) 2017-2018 Dimitri Arrigoni <dimitri@arrigoni.me>
3
+ # Copyright (C) 2017-2021 Dimitri Arrigoni <dimitri@arrigoni.me>
4
4
  # License GPLv3+: GNU GPL version 3 or later
5
5
  # <http://www.gnu.org/licenses/gpl.html>.
6
6
  # This is free software: you are free to change and redistribute it.
7
7
  # There is NO WARRANTY, to the extent permitted by law.
8
8
 
9
- require 'fileutils'
10
- require 'rubygems'
11
- require 'rubygems/gem_runner'
12
-
13
- require_relative 'packager'
9
+ require_relative '../gemspec'
14
10
 
15
11
  # Package a ``gem`` from its own ``gemspec`` file
16
12
  #
@@ -25,39 +21,46 @@ require_relative 'packager'
25
21
  # builder = Kamaze.project.tools.fetch(:gemspec_builder)
26
22
  # builder.build if builder.ready?
27
23
  # ```
28
- class Kamaze::Project::Tools::Gemspec::Builder
24
+ class Kamaze::Project::Tools::Gemspec::Builder < Kamaze::Project::Tools::Gemspec::Packager
25
+ autoload(:FileUtils, 'fileutils')
26
+ autoload(:Pathname, 'pathname')
27
+
29
28
  # Build ``.gem`` file
30
29
  #
31
30
  # @return [self]
32
31
  def build
33
- prepare
32
+ self.tap do
33
+ prepare
34
34
 
35
- buildable_dir = self.buildable.dirname.realpath
35
+ buildable_dir = self.buildable.dirname.realpath
36
36
 
37
- # dive into ``src`` file
38
- Dir.chdir(gemspec_srcfile.dirname) do
39
- Gem::GemRunner.new.run(build_args).yield_self do |file|
40
- FileUtils.mv(file, buildable_dir)
37
+ # dive into ``src`` file
38
+ Dir.chdir(gemspec_srcfile.dirname) do
39
+ self.gem_runner.run(build_args).yield_self do |file|
40
+ FileUtils.mv(file, buildable_dir)
41
41
 
42
- buildable_dir.join(file)
42
+ buildable_dir.join(file)
43
+ end
43
44
  end
44
45
  end
45
-
46
- self
47
46
  end
48
47
 
49
48
  # Get buildable (relative path)
50
49
  #
51
50
  # @return [Pathname]
52
51
  def buildable
53
- full_name = gemspec_reader.read(Hash).fetch(:full_name)
54
- file_path = fs.package_dirs
55
- .fetch(:gem)
56
- .join("#{full_name}.gem")
57
- .to_s
58
- .gsub(%r{^\./}, '')
59
-
60
- ::Pathname.new(file_path)
52
+ return nil unless ready? # @todo raise an explicit exception
53
+
54
+ gemspec_reader.read(Hash).fetch(:full_name).tap do |full_name|
55
+ # @formatter:off
56
+ return fs.package_dirs
57
+ .fetch(:gem)
58
+ .join("#{full_name}.gem")
59
+ .to_s
60
+ .gsub(%r{^\./}, '')
61
+ .yield_self { |file_path| Pathname.new(file_path) }
62
+ # @formatter:on
63
+ end
61
64
  end
62
65
 
63
66
  def ready?
@@ -70,12 +73,13 @@ class Kamaze::Project::Tools::Gemspec::Builder
70
73
  #
71
74
  # @return [Pathname]
72
75
  def gemspec_srcfile
76
+ # @formatter:off
73
77
  (package_dirs.fetch(:src)
74
- .realpath
75
- .join(buildable.basename('.*')).to_s
76
- .gsub(/-([0-9 \.])+$/, '') + '.gemspec').yield_self do |s|
77
- Pathname.new(s)
78
- end
78
+ .realpath
79
+ .join(buildable.basename('.*')).to_s
80
+ .gsub(/-([0-9 \.])+$/, '') + '.gemspec')
81
+ .yield_self { |s| Pathname.new(s) }
82
+ # @formatter:on
79
83
  end
80
84
 
81
85
  protected
@@ -84,8 +88,16 @@ class Kamaze::Project::Tools::Gemspec::Builder
84
88
  super
85
89
 
86
90
  self.package_labels = [:src, :gem]
87
- self.purgeables = [:gem]
88
- self.package_name = "ruby/gem-#{Gem::VERSION}"
91
+ self.purgeables = [:gem]
92
+ self.package_name = "ruby/gem-#{Gem::VERSION}"
93
+ end
94
+
95
+ # @return [Gem::GemRunner]
96
+ def gem_runner
97
+ require 'rubygems'
98
+ require 'rubygems/gem_runner'
99
+
100
+ Gem::GemRunner.new
89
101
  end
90
102
 
91
103
  # Get args used by ``gem`` command