rubygems-tasks 0.2.6 → 0.3.0

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,8 +1,10 @@
1
- require 'rubygems/tasks/task'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../task'
2
4
 
3
5
  module Gem
4
6
  class Tasks
5
- module SCM
7
+ class SCM
6
8
  #
7
9
  # The `scm:status` task.
8
10
  #
@@ -11,10 +13,7 @@ module Gem
11
13
  #
12
14
  # Initializes the `status` task.
13
15
  #
14
- # @param [Hash] options
15
- # Additional options.
16
- #
17
- def initialize(options={})
16
+ def initialize
18
17
  super()
19
18
 
20
19
  yield self if block_given?
@@ -1,8 +1,10 @@
1
- require 'rubygems/tasks/task'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../task'
2
4
 
3
5
  module Gem
4
6
  class Tasks
5
- module SCM
7
+ class SCM
6
8
  #
7
9
  # The `scm:tag` task.
8
10
  #
@@ -15,7 +17,6 @@ module Gem
15
17
  #
16
18
  # @return [String, Proc]
17
19
  # The format String or Proc.
18
- #
19
20
  attr_accessor :format
20
21
 
21
22
  # Enables or disables PGP signing of tags.
@@ -24,26 +25,22 @@ module Gem
24
25
  # The new value.
25
26
  #
26
27
  # @since 0.2.0
27
- #
28
28
  attr_writer :sign
29
29
 
30
30
  #
31
31
  # Initializes the `scm:tag` task.
32
32
  #
33
- # @param [Hash] options
34
- # Additional options.
35
- #
36
- # @option options [String, Proc] :format (DEFAULT_FORMAT)
33
+ # @param [String, Proc] format
37
34
  # The format String or Proc for version tags.
38
35
  #
39
- # @option options [Boolean] :sign
36
+ # @param [Boolean] sign
40
37
  # Enables PGP signing of tags.
41
38
  #
42
- def initialize(options={})
39
+ def initialize(format: DEFAULT_FORMAT, sign: nil)
43
40
  super()
44
41
 
45
- @format = options.fetch(:format,DEFAULT_FORMAT)
46
- @sign = options[:sign]
42
+ @format = format
43
+ @sign = sign
47
44
 
48
45
  yield self if block_given?
49
46
  define
@@ -1,3 +1,52 @@
1
- require 'rubygems/tasks/scm/status'
2
- require 'rubygems/tasks/scm/tag'
3
- require 'rubygems/tasks/scm/push'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'scm/status'
4
+ require_relative 'scm/tag'
5
+ require_relative 'scm/push'
6
+
7
+ module Gem
8
+ class Tasks
9
+ class SCM
10
+
11
+ # The {Status scm:status} task.
12
+ #
13
+ # @return [Status, nil]
14
+ #
15
+ # @since 0.3.0
16
+ attr_reader :status
17
+
18
+ # The {Tag scm:tag} task.
19
+ #
20
+ # @return [Tag, nil]
21
+ #
22
+ # @since 0.3.0
23
+ attr_reader :tag
24
+
25
+ # The {Push scm:push} task.
26
+ #
27
+ # @return [Push, nil]
28
+ #
29
+ # @since 0.3.0
30
+ attr_reader :push
31
+
32
+ #
33
+ # Initializes the `scm:*` tasks.
34
+ #
35
+ # @param [Boolean] status
36
+ # Enables or disables the {SCM::Status scm:status} task.
37
+ #
38
+ # @param [Boolean] tag
39
+ # Enables or disables the {SCM::Tag scm:tag} task.
40
+ #
41
+ # @param [Boolean] push
42
+ # Enables or disables the {SCM::Push scm:push} task.
43
+ #
44
+ def initialize(status: true, tag: true, push: true)
45
+ @status = (Status.new if status)
46
+ @tag = (Tag.new if tag)
47
+ @push = (Push.new if push)
48
+ end
49
+
50
+ end
51
+ end
52
+ end
@@ -1,52 +1,59 @@
1
- require 'rubygems/tasks/sign/task'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'task'
2
4
 
3
5
  require 'digest'
4
6
 
5
7
  module Gem
6
8
  class Tasks
7
- module Sign
9
+ class Sign
8
10
  #
9
11
  # The `sign:checksum` task.
10
12
  #
11
13
  class Checksum < Task
12
14
 
13
15
  # Enables or disables MD5 checksums.
16
+ #
17
+ # @return [Boolean]
14
18
  attr_writer :md5
15
19
 
16
20
  # Enables or disables SHA1 checksums.
21
+ #
22
+ # @return [Boolean]
17
23
  attr_writer :sha1
18
24
 
19
25
  # Enables or disables SHA2 checksums.
26
+ #
27
+ # @return [Boolean]
20
28
  attr_writer :sha2
21
29
 
22
30
  # Enables or disables SHA512 checksums.
31
+ #
32
+ # @return [Boolean]
23
33
  attr_writer :sha512
24
34
 
25
35
  #
26
36
  # Initializes the `sign:checksum` task.
27
37
  #
28
- # @param [Hash] options
29
- # Digest options.
30
- #
31
- # @option options [Boolean] :md5 (true)
38
+ # @param [Boolean] md5
32
39
  # Specifies whether MD5 checksums are enabled.
33
40
  #
34
- # @option options [Boolean] :sha1 (true)
41
+ # @param [Boolean] sha1
35
42
  # Specifies whether SHA1 checksums are enabled.
36
43
  #
37
- # @option options [Boolean] :sha2 (false)
44
+ # @param [Boolean] sha2
38
45
  # Specifies whether SHA2 checksums are enabled.
39
46
  #
40
- # @option options [Boolean] :sha512 (false)
47
+ # @param [Boolean] sha512
41
48
  # Specifies whether SHA512 checksums are enabled.
42
49
  #
43
- def initialize(options={})
50
+ def initialize(md5: true, sha1: true, sha2: false, sha512: false)
44
51
  super()
45
52
 
46
- @md5 = options.fetch(:md5, true)
47
- @sha1 = options.fetch(:sha1, true)
48
- @sha2 = options.fetch(:sha2, false)
49
- @sha512 = options.fetch(:sha512,false)
53
+ @md5 = md5
54
+ @sha1 = sha1
55
+ @sha2 = sha2
56
+ @sha512 = sha512
50
57
 
51
58
  yield self if block_given?
52
59
  define
@@ -1,8 +1,10 @@
1
- require 'rubygems/tasks/sign/task'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'task'
2
4
 
3
5
  module Gem
4
6
  class Tasks
5
- module Sign
7
+ class Sign
6
8
  #
7
9
  # The `sign:pgp` task.
8
10
  #
@@ -11,10 +13,7 @@ module Gem
11
13
  #
12
14
  # Initializes the `sign` task.
13
15
  #
14
- # @param [Hash] options
15
- # Digest options.
16
- #
17
- def initialize(options={})
16
+ def initialize
18
17
  super()
19
18
 
20
19
  yield self if block_given?
@@ -1,10 +1,12 @@
1
- require 'rubygems/tasks/task'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../task'
2
4
 
3
5
  require 'digest'
4
6
 
5
7
  module Gem
6
8
  class Tasks
7
- module Sign
9
+ class Sign
8
10
  class Task < Tasks::Task
9
11
 
10
12
  #
@@ -1,2 +1,42 @@
1
- require 'rubygems/tasks/sign/checksum'
2
- require 'rubygems/tasks/sign/pgp'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'sign/checksum'
4
+ require_relative 'sign/pgp'
5
+
6
+ module Gem
7
+ class Tasks
8
+ class Sign
9
+
10
+ # The {Checksum sign:checksum} task.
11
+ #
12
+ # @return [Checksum, nil]
13
+ #
14
+ # @since 0.3.0
15
+ attr_reader :checksum
16
+
17
+ # The {PGP sign:pgp} task.
18
+ #
19
+ # @return [PGP, nil]
20
+ #
21
+ # @since 0.3.0
22
+ attr_reader :pgp
23
+
24
+ #
25
+ # Initializes the `scm:*` tasks.
26
+ #
27
+ # @param [Boolean] checksum
28
+ # Enables or disables the {Checksum sign:checksum} task.
29
+ #
30
+ # @param [Boolean] pgp
31
+ # Enables or disables the {PGP sign:pgp} task.
32
+ #
33
+ # @since 0.3.0
34
+ #
35
+ def initialize(checksum: nil, pgp: nil)
36
+ @checksum = (Checksum.new if checksum)
37
+ @pgp = (PGP.new if pgp)
38
+ end
39
+
40
+ end
41
+ end
42
+ end
@@ -1,5 +1,7 @@
1
- require 'rubygems/tasks/project'
2
- require 'rubygems/tasks/printing'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'project'
4
+ require_relative 'printing'
3
5
 
4
6
  require 'rake/tasklib'
5
7
 
@@ -1,13 +1,14 @@
1
- require 'rubygems/tasks/console'
2
- require 'rubygems/tasks/build'
3
- require 'rubygems/tasks/install'
4
- require 'rubygems/tasks/scm'
5
- require 'rubygems/tasks/push'
6
- require 'rubygems/tasks/release'
7
- require 'rubygems/tasks/sign'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'tasks/console'
4
+ require_relative 'tasks/build'
5
+ require_relative 'tasks/install'
6
+ require_relative 'tasks/scm'
7
+ require_relative 'tasks/push'
8
+ require_relative 'tasks/release'
9
+ require_relative 'tasks/sign'
8
10
 
9
11
  require 'rake/tasklib'
10
- require 'ostruct'
11
12
 
12
13
  module Gem
13
14
  #
@@ -28,28 +29,19 @@ module Gem
28
29
  #
29
30
  class Tasks
30
31
 
32
+ # The {Build build:\*} tasks.
31
33
  #
32
- # The `build` tasks.
33
- #
34
- # @return [OpenStruct]
35
- # The collection of `build` tasks.
36
- #
34
+ # @return [Build]
37
35
  attr_reader :build
38
36
 
37
+ # The {SCM scm:\*} tasks.
39
38
  #
40
- # The `scm` tasks.
41
- #
42
- # @return [OpenStruct]
43
- # The collection of `scm` tasks.
44
- #
39
+ # @return [SCM]
45
40
  attr_reader :scm
46
41
 
42
+ # The {Sign sign:\*} tasks.
47
43
  #
48
- # The `sign` tasks.
49
- #
50
- # @return [OpenStruct]
51
- # The collection of `sign` tasks.
52
- #
44
+ # @return [Sign]
53
45
  attr_reader :sign
54
46
 
55
47
  # The {Console console} task.
@@ -67,30 +59,54 @@ module Gem
67
59
  #
68
60
  # Initializes the project tasks.
69
61
  #
70
- # @param [Hash{Symbol => Hash}] options
71
- # Enables or disables individual tasks.
62
+ # @param [Hash{Symbol => Boolean}] build
63
+ # Enables or disables the `build` tasks. Additional keyword arguments
64
+ # can be passed to the individual build tasks via a Hash.
65
+ #
66
+ # @option build [Boolean] :gem (true)
67
+ # Enables or disables the {Build::Gem build:gem} task.
68
+ #
69
+ # @option build [Boolean] :tar
70
+ # Enables or disables the {Build::Tar build:tar} task.
71
+ #
72
+ # @option build [Boolean] :zip
73
+ # Enables or disables the {Build::Zip build:zip} task.
74
+ #
75
+ # @param [Hash{Symbol => Boolean}] scm
76
+ # Enables or disables the `scm` tasks. Additional keyword arguments
77
+ # can be passed to the individual scm tasks via a Hash.
72
78
  #
73
- # @option options [Hash{Symbol => Boolean}] :build
74
- # Enables or disables the `build` tasks.
79
+ # @option scm [Boolean] :status (true)
80
+ # Enables or disables the {SCM::Status scm:status} task.
75
81
  #
76
- # @option options [Hash{Symbol => Boolean}] :scm
77
- # Enables or disables the `scm` tasks.
82
+ # @option scm [Boolean] :tag (true)
83
+ # Enables or disables the {SCM::Tag scm:tag} task.
78
84
  #
79
- # @option options [Boolean] :console (true)
85
+ # @option scm [Boolean] :push (true)
86
+ # Enables or disables the {SCM::Push scm:push} task.
87
+ #
88
+ # @param [Hash{Symbol => Boolean}] sign
89
+ # Enables or disables the `sign` tasks. Additional keyword arguments
90
+ # can be passed to the individual sign tasks via a Hash.
91
+ #
92
+ # @option sign [Boolean] :checksum
93
+ # Enables or disables the {Sign::Checksum sign:checksum} task.
94
+ #
95
+ # @option sign [Boolean] :pgp
96
+ # Enables or disables the {Sign::PGP sign:pgp} task.
97
+ #
98
+ # @param [Boolean] console
80
99
  # Enables or disables the {Console console} task.
81
100
  #
82
- # @option options [Boolean] :install (true)
101
+ # @param [Boolean] install
83
102
  # Enables or disables the {Install install} task.
84
103
  #
85
- # @option options [Boolean] :push (true)
104
+ # @param [Boolean] push
86
105
  # Enables or disables the {Push push} task.
87
106
  #
88
- # @option options [Boolean] :release (true)
107
+ # @param [Boolean] release
89
108
  # Enables or disables the {Release release} task.
90
109
  #
91
- # @option options [Hash{Symbol => Boolean}] :sign
92
- # Enables or disables the `sign` tasks.
93
- #
94
110
  # @yield [tasks]
95
111
  # If a block is given, it will be passed the newly created tasks,
96
112
  # before they are fully defined.
@@ -109,36 +125,21 @@ module Gem
109
125
  # tasks.scm.tag.format = "release-%s"
110
126
  # end
111
127
  #
112
- def initialize(options={})
113
- build_options = options.fetch(:build,{})
114
- scm_options = options.fetch(:scm,{})
115
- sign_options = options.fetch(:sign,{})
116
-
117
- @scm = OpenStruct.new
118
- @build = OpenStruct.new
119
- @sign = OpenStruct.new
120
-
121
- if build_options
122
- @build.gem = (Build::Gem.new if build_options.fetch(:gem,true))
123
- @build.tar = (Build::Tar.new if build_options[:tar])
124
- @build.zip = (Build::Zip.new if build_options[:zip])
125
- end
126
-
127
- if scm_options
128
- @scm.status = (SCM::Status.new if scm_options.fetch(:status,true))
129
- @scm.tag = (SCM::Tag.new if scm_options.fetch(:tag,true))
130
- @scm.push = (SCM::Push.new if scm_options.fetch(:push,true))
131
- end
132
-
133
- if sign_options
134
- @sign.checksum = (Sign::Checksum.new if sign_options[:checksum])
135
- @sign.pgp = (Sign::PGP.new if sign_options[:pgp])
136
- end
137
-
138
- @console = (Console.new if options.fetch(:console,true))
139
- @install = (Install.new if options.fetch(:install,true))
140
- @push = (Push.new if options.fetch(:push,true))
141
- @release = (Release.new if options.fetch(:release,true))
128
+ def initialize(build: {},
129
+ scm: {},
130
+ sign: {},
131
+ console: true,
132
+ install: true,
133
+ push: true,
134
+ release: true)
135
+ @scm = SCM.new(**scm)
136
+ @build = Build.new(**build)
137
+ @sign = Sign.new(**sign)
138
+
139
+ @console = (Console.new if console)
140
+ @install = (Install.new if install)
141
+ @push = (Push.new if push)
142
+ @release = (Release.new if release)
142
143
 
143
144
  yield self if block_given?
144
145
  end
@@ -0,0 +1,72 @@
1
+ require 'spec_helper'
2
+ require 'rake_context'
3
+
4
+ require 'rubygems/tasks/build'
5
+
6
+ describe Gem::Tasks::Build do
7
+ include_context "rake"
8
+
9
+ describe "#initialize" do
10
+ context "when given no keyword arguments" do
11
+ it "must initialize #gem by default" do
12
+ expect(subject.gem).to be_a(Gem::Tasks::Build::Gem)
13
+ end
14
+
15
+ it "must not initialize #tar by default" do
16
+ expect(subject.tar).to be(nil)
17
+ end
18
+
19
+ it "must not initialize #zip by default" do
20
+ expect(subject.zip).to be(nil)
21
+ end
22
+ end
23
+
24
+ context "when given `gem: true`" do
25
+ subject { described_class.new(gem: true) }
26
+
27
+ it "must initialize #gem" do
28
+ expect(subject.gem).to be_a(Gem::Tasks::Build::Gem)
29
+ end
30
+ end
31
+
32
+ context "when given `gem: false`" do
33
+ subject { described_class.new(gem: false) }
34
+
35
+ it "must not initialize #gem" do
36
+ expect(subject.gem).to be(nil)
37
+ end
38
+ end
39
+
40
+ context "when given `tar: true`" do
41
+ subject { described_class.new(tar: true) }
42
+
43
+ it "must initialize #tar" do
44
+ expect(subject.tar).to be_a(Gem::Tasks::Build::Tar)
45
+ end
46
+ end
47
+
48
+ context "when given `tar: false`" do
49
+ subject { described_class.new(tar: false) }
50
+
51
+ it "must not initialize #tar" do
52
+ expect(subject.tar).to be(nil)
53
+ end
54
+ end
55
+
56
+ context "when given `zip: true`" do
57
+ subject { described_class.new(zip: true) }
58
+
59
+ it "must initialize #zip" do
60
+ expect(subject.zip).to be_a(Gem::Tasks::Build::Zip)
61
+ end
62
+ end
63
+
64
+ context "when given `zip: false`" do
65
+ subject { described_class.new(zip: false) }
66
+
67
+ it "must not initialize #zip" do
68
+ expect(subject.zip).to be(nil)
69
+ end
70
+ end
71
+ end
72
+ end
data/spec/console_spec.rb CHANGED
@@ -13,24 +13,24 @@ describe Gem::Tasks::Console do
13
13
  let(:custom_options) { %w[-Ivendor -rfoo] }
14
14
 
15
15
  context "defaults" do
16
- context "when project.bundler? == false" do
16
+ context "when the project does not use Bundler" do
17
17
  before do
18
18
  allow(subject.project).to receive(:bundler?).and_return(false)
19
19
  end
20
20
 
21
- it "should run `irb`" do
21
+ it "must run `irb`" do
22
22
  expect(subject).to receive(:run).with('irb',*default_options)
23
23
 
24
24
  subject.console
25
25
  end
26
26
  end
27
27
 
28
- context "when project.bundler? == true" do
28
+ context "when the project does use Bundler" do
29
29
  before do
30
30
  allow(subject.project).to receive(:bundler?).and_return(true)
31
31
  end
32
32
 
33
- it "should use `bundle exec`" do
33
+ it "must use `bundle exec`" do
34
34
  expect(subject).to receive(:run).with(
35
35
  'bundle', 'exec', 'irb', *default_options
36
36
  )
@@ -40,27 +40,27 @@ describe Gem::Tasks::Console do
40
40
  end
41
41
  end
42
42
 
43
- context "with custom command" do
44
- subject { described_class.new(:command => custom_command) }
43
+ context "with a custom command" do
44
+ subject { described_class.new(command: custom_command) }
45
45
 
46
- context "when project.bundler? == false" do
46
+ context "when the project does not use Bundler" do
47
47
  before do
48
48
  allow(subject.project).to receive(:bundler?).and_return(false)
49
49
  end
50
50
 
51
- it "should run the custom console" do
51
+ it "must run the custom console" do
52
52
  expect(subject).to receive(:run).with(custom_command,*default_options)
53
53
 
54
54
  subject.console
55
55
  end
56
56
  end
57
57
 
58
- context "when project.bundler? == true" do
58
+ context "when the project does use Bundler" do
59
59
  before do
60
60
  allow(subject.project).to receive(:bundler?).and_return(true)
61
61
  end
62
62
 
63
- it "should use `bundle exec`" do
63
+ it "must use `bundle exec`" do
64
64
  expect(subject).to receive(:run).with(
65
65
  'bundle', 'exec', custom_command, *default_options
66
66
  )
@@ -71,26 +71,26 @@ describe Gem::Tasks::Console do
71
71
  end
72
72
 
73
73
  context "with custom options" do
74
- subject { described_class.new(:options => custom_options) }
74
+ subject { described_class.new(options: custom_options) }
75
75
 
76
- context "when project.bundler? == false" do
76
+ context "when the project does not use Bundler" do
77
77
  before do
78
78
  allow(subject.project).to receive(:bundler?).and_return(false)
79
79
  end
80
80
 
81
- it "should pass custom options to `irb`" do
81
+ it "must pass custom options to `irb`" do
82
82
  expect(subject).to receive(:run).with('irb', *(default_options + custom_options))
83
83
 
84
84
  subject.console
85
85
  end
86
86
  end
87
87
 
88
- context "when project.bundler? == true" do
88
+ context "when the project does use Bundler" do
89
89
  before do
90
90
  allow(subject.project).to receive(:bundler?).and_return(true)
91
91
  end
92
92
 
93
- it "should use `bundle exec ...`" do
93
+ it "must use `bundle exec ...`" do
94
94
  expect(subject).to receive(:run).with('bundle', 'exec', 'irb', *(default_options + custom_options))
95
95
 
96
96
  subject.console
data/spec/install_spec.rb CHANGED
@@ -7,7 +7,7 @@ describe Gem::Tasks::Install do
7
7
  describe "#install" do
8
8
  let(:path) { 'pkg/foo-1.2.3.gem' }
9
9
 
10
- it "should use `gem install -q`" do
10
+ it "must use `gem install -q`" do
11
11
  if defined?(Bundler)
12
12
  expect(Bundler).to receive(:with_original_env).and_yield()
13
13
  end