rake_factory 0.30.0.pre.5 → 0.30.0.pre.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2bc6f45f24a86f52229b2ba36a92c53b7de5f20f86480793224abf7860e5f225
4
- data.tar.gz: e00a0089e63b0fd40909459f995822b8d2a6e46748c977511f2e996b2ee54004
3
+ metadata.gz: 53ae8ca634d2b17634f99bd3262d140cd80036446cca4af6d3400c09ecb3a563
4
+ data.tar.gz: 8e5f4e267242f671e4844bc88c7568dc265aeba64700e2cf647fe30613699839
5
5
  SHA512:
6
- metadata.gz: c8f42d4b1b53bfcefb615ca55a758c0932d42233cfc62a67d6676b2b30e8b594ac7815771e99362cda91b0c92cf93fdd9ad42f925d754496ebd63cac7a6b1482
7
- data.tar.gz: f03a63b6737e1de801573032ee73a3c370cd598f0a831913ccdce635c94cd2361a9726b0d617716baf541ec144d9bbdb2e0c27cb066252bff36587e8ec40787b
6
+ metadata.gz: f0ce4594aa132a37dd28580767978759d779c94358f6a582223d52db2d739f8ba7d187614f2a8889331cf940a8bde1fa75425cba509a3555fc2090ef6d53c8bc
7
+ data.tar.gz: 637f0a19b55dce094ff7f7f4a930df6b346c8ed1040bded85985ec14ed625c0a0fa33977a1049a04b1a8307813c772183267711adee2006ae79c6689a53534b8
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in rake_tasklib.gemspec
data/Gemfile.lock CHANGED
@@ -1,26 +1,27 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rake_factory (0.30.0.pre.5)
4
+ rake_factory (0.30.0.pre.6)
5
5
  activesupport (>= 4)
6
6
  rake (~> 13.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activesupport (7.0.2.3)
11
+ activesupport (7.0.4)
12
12
  concurrent-ruby (~> 1.0, >= 1.0.2)
13
13
  i18n (>= 1.6, < 2)
14
14
  minitest (>= 5.1)
15
15
  tzinfo (~> 2.0)
16
16
  addressable (2.8.0)
17
17
  public_suffix (>= 2.0.2, < 5.0)
18
+ ast (2.4.2)
18
19
  colored2 (3.1.2)
19
- concurrent-ruby (1.1.9)
20
+ concurrent-ruby (1.1.10)
20
21
  diff-lcs (1.5.0)
21
22
  docile (1.4.0)
22
23
  excon (0.92.0)
23
- fakefs (1.4.1)
24
+ fakefs (1.8.0)
24
25
  faraday (1.10.0)
25
26
  faraday-em_http (~> 1.0)
26
27
  faraday-em_synchrony (~> 1.0)
@@ -47,18 +48,22 @@ GEM
47
48
  gem-release (2.2.2)
48
49
  hamster (3.0.0)
49
50
  concurrent-ruby (~> 1.0)
50
- i18n (1.10.0)
51
+ i18n (1.12.0)
51
52
  concurrent-ruby (~> 1.0)
52
53
  lino (3.0.0)
53
54
  hamster (~> 3.0)
54
55
  open4 (~> 1.3)
55
- minitest (5.15.0)
56
+ minitest (5.16.3)
56
57
  multipart-post (2.1.1)
57
58
  octokit (4.22.0)
58
59
  faraday (>= 0.9)
59
60
  sawyer (~> 0.8.0, >= 0.5.3)
60
61
  open4 (1.3.4)
62
+ parallel (1.22.1)
63
+ parser (3.1.1.0)
64
+ ast (~> 2.4.1)
61
65
  public_suffix (4.0.6)
66
+ rainbow (3.1.1)
62
67
  rake (13.0.6)
63
68
  rake_circle_ci (0.9.0)
64
69
  colored2 (~> 3.1)
@@ -77,6 +82,8 @@ GEM
77
82
  colored2 (~> 3.1)
78
83
  rake_factory (~> 0.23)
79
84
  sshkey (~> 2.0)
85
+ regexp_parser (2.2.1)
86
+ rexml (3.2.5)
80
87
  rspec (3.11.0)
81
88
  rspec-core (~> 3.11.0)
82
89
  rspec-expectations (~> 3.11.0)
@@ -90,6 +97,22 @@ GEM
90
97
  diff-lcs (>= 1.2.0, < 2.0)
91
98
  rspec-support (~> 3.11.0)
92
99
  rspec-support (3.11.0)
100
+ rubocop (1.26.1)
101
+ parallel (~> 1.10)
102
+ parser (>= 3.1.0.0)
103
+ rainbow (>= 2.2.2, < 4.0)
104
+ regexp_parser (>= 1.8, < 3.0)
105
+ rexml
106
+ rubocop-ast (>= 1.16.0, < 2.0)
107
+ ruby-progressbar (~> 1.7)
108
+ unicode-display_width (>= 1.4.0, < 3.0)
109
+ rubocop-ast (1.16.0)
110
+ parser (>= 3.1.1.0)
111
+ rubocop-rake (0.6.0)
112
+ rubocop (~> 1.0)
113
+ rubocop-rspec (2.9.0)
114
+ rubocop (~> 1.19)
115
+ ruby-progressbar (1.11.0)
93
116
  ruby2_keywords (0.0.5)
94
117
  ruby_gpg2 (0.8.0)
95
118
  lino (>= 1.5)
@@ -103,8 +126,9 @@ GEM
103
126
  simplecov-html (0.12.3)
104
127
  simplecov_json_formatter (0.1.4)
105
128
  sshkey (2.0.0)
106
- tzinfo (2.0.4)
129
+ tzinfo (2.0.5)
107
130
  concurrent-ruby (~> 1.0)
131
+ unicode-display_width (2.1.0)
108
132
 
109
133
  PLATFORMS
110
134
  ruby
@@ -120,7 +144,10 @@ DEPENDENCIES
120
144
  rake_gpg
121
145
  rake_ssh
122
146
  rspec
147
+ rubocop
148
+ rubocop-rake
149
+ rubocop-rspec
123
150
  simplecov
124
151
 
125
152
  BUNDLED WITH
126
- 2.3.9
153
+ 2.3.22
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'yaml'
2
4
  require 'rake_circle_ci'
3
5
  require 'rake_github'
@@ -5,17 +7,20 @@ require 'rake_ssh'
5
7
  require 'rake_gpg'
6
8
  require 'securerandom'
7
9
  require 'rspec/core/rake_task'
10
+ require 'rubocop/rake_task'
8
11
 
9
- task :default => :spec
10
-
11
- RSpec::Core::RakeTask.new(:spec)
12
+ task default: %i[
13
+ library:fix
14
+ test:unit
15
+ ]
12
16
 
13
17
  namespace :encryption do
14
18
  namespace :passphrase do
19
+ desc 'Generate encryption passphrase for CI GPG key'
15
20
  task :generate do
16
- File.open('config/secrets/ci/encryption.passphrase', 'w') do |f|
17
- f.write(SecureRandom.base64(36))
18
- end
21
+ FileUtils.mkdir_p('config/secrets/ci/')
22
+ File.write('config/secrets/ci/encryption.passphrase',
23
+ SecureRandom.base64(36))
19
24
  end
20
25
  end
21
26
  end
@@ -23,85 +28,102 @@ end
23
28
  namespace :keys do
24
29
  namespace :deploy do
25
30
  RakeSSH.define_key_tasks(
26
- path: 'config/secrets/ci/',
27
- comment: 'maintainers@infrablocks.io')
31
+ path: 'config/secrets/ci/',
32
+ comment: 'maintainers@infrablocks.io'
33
+ )
28
34
  end
29
35
 
30
36
  namespace :gpg do
31
37
  RakeGPG.define_generate_key_task(
32
- output_directory: 'config/secrets/ci',
33
- name_prefix: 'gpg',
34
- owner_name: 'InfraBlocks Maintainers',
35
- owner_email: 'maintainers@infrablocks.io',
36
- owner_comment: 'rake_factory CI Key')
38
+ output_directory: 'config/secrets/ci',
39
+ name_prefix: 'gpg',
40
+ owner_name: 'InfraBlocks Maintainers',
41
+ owner_email: 'maintainers@infrablocks.io',
42
+ owner_comment: 'rake_factory CI Key'
43
+ )
37
44
  end
38
45
  end
39
46
 
47
+ RuboCop::RakeTask.new
48
+
49
+ namespace :library do
50
+ desc 'Run all checks of the library'
51
+ task check: [:rubocop]
52
+
53
+ desc 'Attempt to automatically fix issues with the library'
54
+ task fix: [:'rubocop:auto_correct']
55
+ end
56
+
57
+ namespace :test do
58
+ RSpec::Core::RakeTask.new(:unit)
59
+ end
60
+
40
61
  RakeCircleCI.define_project_tasks(
41
- namespace: :circle_ci,
42
- project_slug: 'github/infrablocks/rake_factory'
62
+ namespace: :circle_ci,
63
+ project_slug: 'github/infrablocks/rake_factory'
43
64
  ) do |t|
44
65
  circle_ci_config =
45
- YAML.load_file('config/secrets/circle_ci/config.yaml')
66
+ YAML.load_file('config/secrets/circle_ci/config.yaml')
46
67
 
47
- t.api_token = circle_ci_config["circle_ci_api_token"]
68
+ t.api_token = circle_ci_config['circle_ci_api_token']
48
69
  t.environment_variables = {
49
- ENCRYPTION_PASSPHRASE:
50
- File.read('config/secrets/ci/encryption.passphrase')
51
- .chomp
70
+ ENCRYPTION_PASSPHRASE:
71
+ File.read('config/secrets/ci/encryption.passphrase')
72
+ .chomp
52
73
  }
53
74
  t.checkout_keys = []
54
75
  t.ssh_keys = [
55
- {
56
- hostname: "github.com",
57
- private_key: File.read('config/secrets/ci/ssh.private')
58
- }
76
+ {
77
+ hostname: 'github.com',
78
+ private_key: File.read('config/secrets/ci/ssh.private')
79
+ }
59
80
  ]
60
81
  end
61
82
 
62
83
  RakeGithub.define_repository_tasks(
63
- namespace: :github,
64
- repository: 'infrablocks/rake_factory',
84
+ namespace: :github,
85
+ repository: 'infrablocks/rake_factory'
65
86
  ) do |t, args|
66
87
  github_config =
67
- YAML.load_file('config/secrets/github/config.yaml')
88
+ YAML.load_file('config/secrets/github/config.yaml')
68
89
 
69
- t.access_token = github_config["github_personal_access_token"]
90
+ t.access_token = github_config['github_personal_access_token']
70
91
  t.deploy_keys = [
71
- {
72
- title: 'CircleCI',
73
- public_key: File.read('config/secrets/ci/ssh.public')
74
- }
92
+ {
93
+ title: 'CircleCI',
94
+ public_key: File.read('config/secrets/ci/ssh.public')
95
+ }
75
96
  ]
76
97
  t.branch_name = args.branch_name
77
98
  t.commit_message = args.commit_message
78
99
  end
79
100
 
80
101
  namespace :pipeline do
81
- task :prepare => [
82
- :'circle_ci:project:follow',
83
- :'circle_ci:env_vars:ensure',
84
- :'circle_ci:checkout_keys:ensure',
85
- :'circle_ci:ssh_keys:ensure',
86
- :'github:deploy_keys:ensure'
102
+ desc 'Prepare CircleCI Pipeline'
103
+ task prepare: %i[
104
+ circle_ci:project:follow
105
+ circle_ci:env_vars:ensure
106
+ circle_ci:checkout_keys:ensure
107
+ circle_ci:ssh_keys:ensure
108
+ github:deploy_keys:ensure
87
109
  ]
88
110
  end
89
111
 
90
112
  namespace :version do
91
- desc "Bump version for specified type (pre, major, minor, patch)"
113
+ desc 'Bump version for specified type (pre, major, minor, patch)'
92
114
  task :bump, [:type] do |_, args|
93
115
  bump_version_for(args.type)
94
116
  end
95
117
  end
96
118
 
97
- desc "Release gem"
119
+ desc 'Release gem'
98
120
  task :release do
99
- sh "gem release --tag --push"
121
+ sh 'gem release --tag --push'
100
122
  end
101
123
 
102
124
  def bump_version_for(version_type)
103
- sh "gem bump --version #{version_type} " +
104
- "&& bundle install " +
105
- "&& export LAST_MESSAGE=\"$(git log -1 --pretty=%B)\" " +
106
- "&& git commit -a --amend -m \"${LAST_MESSAGE} [ci skip]\""
125
+ sh "gem bump --version #{version_type} " \
126
+ '&& bundle install ' \
127
+ '&& export LAST_MESSAGE="$(git log -1 --pretty=%B)" ' \
128
+ '&& git commit -a --amend -m "${LAST_MESSAGE} [ci skip]"'
107
129
  end
data/bin/console CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "bundler/setup"
4
- require "rake_factory"
4
+ require 'bundler/setup'
5
+ require 'rake_factory'
5
6
 
6
7
  # You can add fixtures and/or initialization code here to make experimenting
7
8
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +11,5 @@ require "rake_factory"
10
11
  # require "pry"
11
12
  # Pry.start
12
13
 
13
- require "irb"
14
+ require 'irb'
14
15
  IRB.start(__FILE__)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RakeFactory
2
4
  module Actions
3
5
  def self.included(base)
@@ -6,7 +8,7 @@ module RakeFactory
6
8
 
7
9
  def invoke_actions(args)
8
10
  self.class.actions.each do |action|
9
- self.instance_exec(*[self, args].slice(0, action.arity), &action)
11
+ instance_exec(*[self, args].slice(0, action.arity), &action)
10
12
  end
11
13
  end
12
14
 
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RakeFactory
2
4
  module Arguments
3
5
  def initialize(*args, &configuration_block)
4
- arity = self.method(:initialize).super_method.arity
6
+ arity = method(:initialize).super_method.arity
5
7
  super(*args.slice(0, arity), &configuration_block)
6
8
  process_arguments(args)
7
9
  end
@@ -14,9 +16,7 @@ module RakeFactory
14
16
  private
15
17
 
16
18
  def set_if_parameter(key, value)
17
- if self.respond_to?("#{key}=")
18
- self.send("#{key}=", value)
19
- end
19
+ send("#{key}=", value) if respond_to?("#{key}=")
20
20
  end
21
21
  end
22
22
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RakeFactory
2
4
  module Configurable
3
5
  def self.included(base)
@@ -7,7 +9,7 @@ module RakeFactory
7
9
  end
8
10
 
9
11
  def initialize(*args, &configuration_block)
10
- arity = self.method(:initialize).super_method.arity
12
+ arity = method(:initialize).super_method.arity
11
13
  super(*args.slice(0, arity), &configuration_block)
12
14
  process_configuration_block(configuration_block)
13
15
  end
@@ -17,19 +19,18 @@ module RakeFactory
17
19
  end
18
20
 
19
21
  def invoke_configuration_block_on(target, args)
20
- if configuration_block
21
- params = args ? [target, args] : [target]
22
- configuration_block.call(
23
- *params.slice(0, configuration_block.arity))
24
- end
22
+ return unless configuration_block
23
+
24
+ params = args ? [target, args] : [target]
25
+ configuration_block.call(
26
+ *params.slice(0, configuration_block.arity)
27
+ )
25
28
  end
26
29
 
27
30
  private
28
31
 
29
32
  def set_if_value_present(key, value)
30
- if self.respond_to?("#{key}=") && !value.nil?
31
- self.send("#{key}=", value)
32
- end
33
+ send("#{key}=", value) if respond_to?("#{key}=") && !value.nil?
33
34
  end
34
35
  end
35
- end
36
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_support'
2
4
  require 'active_support/core_ext/string/inflections'
3
5
 
@@ -15,24 +17,13 @@ module RakeFactory
15
17
  def inherited(inheritor)
16
18
  super(inheritor)
17
19
  inheritor.class_eval do
18
- parameter(:name,
19
- configurable: false,
20
- transform: lambda { |n| n.to_sym })
21
- parameter(:argument_names,
22
- configurable: false,
23
- default: [])
24
- parameter(:prerequisites,
25
- configurable: false,
26
- default: [])
27
- parameter(:order_only_prerequisites,
28
- configurable: false,
29
- default: [])
30
- parameter(:description,
31
- configurable: false)
32
-
33
- unless inheritor.name.nil?
34
- default_name inheritor.name.demodulize.underscore
35
- end
20
+ name_parameter
21
+ argument_names_parameter
22
+ prerequisites_parameter
23
+ order_only_prerequisites_parameter
24
+ description_parameter
25
+
26
+ maybe_set_default_name(inheritor)
36
27
  end
37
28
  end
38
29
 
@@ -50,13 +41,51 @@ module RakeFactory
50
41
 
51
42
  def default_order_only_prerequisites(order_only_prerequisites)
52
43
  parameter_set
53
- .update_default_for(
54
- :order_only_prerequisites, order_only_prerequisites)
44
+ .update_default_for(
45
+ :order_only_prerequisites, order_only_prerequisites
46
+ )
55
47
  end
56
48
 
57
49
  def default_description(description)
58
50
  parameter_set.update_default_for(:description, description)
59
51
  end
52
+
53
+ private
54
+
55
+ def maybe_set_default_name(inheritor)
56
+ return if inheritor.name.nil?
57
+
58
+ default_name inheritor.name.demodulize.underscore
59
+ end
60
+
61
+ def description_parameter
62
+ parameter(:description,
63
+ configurable: false)
64
+ end
65
+
66
+ def order_only_prerequisites_parameter
67
+ parameter(:order_only_prerequisites,
68
+ configurable: false,
69
+ default: [])
70
+ end
71
+
72
+ def prerequisites_parameter
73
+ parameter(:prerequisites,
74
+ configurable: false,
75
+ default: [])
76
+ end
77
+
78
+ def argument_names_parameter
79
+ parameter(:argument_names,
80
+ configurable: false,
81
+ default: [])
82
+ end
83
+
84
+ def name_parameter
85
+ parameter(:name,
86
+ configurable: false,
87
+ transform: ->(n) { n.respond_to?(:to_sym) ? n.to_sym : n })
88
+ end
60
89
  end
61
90
  end
62
- end
91
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RakeFactory
2
4
  module Definable
3
5
  def inherited(inheritor)
@@ -9,4 +11,4 @@ module RakeFactory
9
11
  end
10
12
  end
11
13
  end
12
- end
14
+ end
@@ -1,4 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RakeFactory
2
4
  class RequiredParameterUnset < ::StandardError
3
5
  end
4
- end
6
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'values'
2
4
 
3
5
  module Kernel
@@ -1,20 +1,23 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RakeFactory
2
4
  module Namespaceable
5
+ # rubocop:disable Metrics/MethodLength
3
6
  def self.prepended(base)
4
7
  super(base)
5
8
  base.class_eval do
6
- parameter(:namespace,
7
- transform: lambda { |name|
8
- name = name.to_s if name.kind_of?(Symbol)
9
- name = name.to_str if name.respond_to?(:to_str)
10
- unless name.kind_of?(String) || name.nil?
11
- raise ArgumentError,
12
- "Expected a String or Symbol for a namespace name"
13
- end
14
- name
15
- })
9
+ parameter(:namespace, transform: lambda { |name|
10
+ name = name.to_s if name.is_a?(Symbol)
11
+ name = name.to_str if name.respond_to?(:to_str)
12
+ unless name.is_a?(String) || name.nil?
13
+ raise ArgumentError,
14
+ 'Expected a String or Symbol for a namespace name'
15
+ end
16
+ name
17
+ })
16
18
  end
17
19
  end
20
+ # rubocop:enable Metrics/MethodLength
18
21
 
19
22
  def around_define(application)
20
23
  if namespace
@@ -1,22 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'values'
2
4
 
3
5
  module RakeFactory
4
6
  class Parameter
5
- attr_reader(
6
- :name,
7
- :default,
8
- :required,
9
- :configurable,
10
- :transform)
11
- attr_writer(:default)
7
+ attr_accessor :default
8
+ attr_reader :name, :required, :configurable, :transform
12
9
 
13
10
  def initialize(name, options)
14
11
  @name = name
15
12
  @default = options[:default]
16
13
  @required = options[:required] || false
17
- @transform = options[:transform] || lambda { |x| x }
14
+ @transform = options[:transform] || ->(x) { x }
18
15
  @configurable =
19
- options[:configurable].nil? ? true : !!options[:configurable]
16
+ options[:configurable].nil? ? true : !!options[:configurable]
20
17
  end
21
18
 
22
19
  def writer_method
@@ -35,14 +32,11 @@ module RakeFactory
35
32
  parameter = self
36
33
  klass.class_eval do
37
34
  define_method parameter.writer_method do |value|
38
- instance_variable_set(parameter.instance_variable, value)
35
+ parameter.set(self, value)
39
36
  end
40
37
 
41
38
  define_method parameter.reader_method do
42
- stored_value = instance_variable_get(parameter.instance_variable)
43
- resolved_value = Values.resolve(stored_value).evaluate([self])
44
- transformed_value = parameter.transform.call(resolved_value)
45
- transformed_value
39
+ parameter.get(self)
46
40
  end
47
41
  end
48
42
  end
@@ -66,5 +60,15 @@ module RakeFactory
66
60
  def satisfied_by?(instance)
67
61
  !dissatisfied_by?(instance)
68
62
  end
63
+
64
+ def set(target, value)
65
+ target.instance_variable_set(instance_variable, value)
66
+ end
67
+
68
+ def get(target)
69
+ stored_value = target.instance_variable_get(instance_variable)
70
+ resolved_value = Values.resolve(stored_value).evaluate([target])
71
+ transform.call(resolved_value)
72
+ end
69
73
  end
70
- end
74
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'parameter'
2
4
  require_relative 'exceptions'
3
5
 
@@ -26,7 +28,7 @@ module RakeFactory
26
28
  end
27
29
 
28
30
  def apply_defaults_to(instance)
29
- @parameter_set.values.each do |parameter|
31
+ @parameter_set.each_value do |parameter|
30
32
  parameter.apply_default_to(instance)
31
33
  end
32
34
  end
@@ -35,19 +37,19 @@ module RakeFactory
35
37
  dissatisfied = @parameter_set.values.reject do |parameter|
36
38
  parameter.satisfied_by?(instance)
37
39
  end
38
- unless dissatisfied.empty?
39
- names = dissatisfied.map(&:name)
40
- names_string = names.join(',')
41
- pluralisation_string = names.length > 1 ? 's' : ''
40
+ return if dissatisfied.empty?
41
+
42
+ names = dissatisfied.map(&:name)
43
+ names_string = names.join(',')
44
+ pluralisation_string = names.length > 1 ? 's' : ''
42
45
 
43
- raise RequiredParameterUnset,
46
+ raise RequiredParameterUnset,
44
47
  "Required parameter#{pluralisation_string} #{names_string} unset."
45
- end
46
48
  end
47
49
 
48
50
  def read_from(instance)
49
51
  @parameter_set.reduce({}) do |acc, (key, parameter)|
50
- acc.merge(Hash[key, parameter.read_from(instance)])
52
+ acc.merge({ key => parameter.read_from(instance) })
51
53
  end
52
54
  end
53
55
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'values'
2
4
 
3
5
  module RakeFactory
@@ -5,23 +7,9 @@ module RakeFactory
5
7
  attr_reader(:task)
6
8
 
7
9
  def initialize(target, reader_class, writer_class, runtime_arguments)
8
- self.instance_eval do
9
- reader_class.parameter_set.each do |parameter|
10
- define_singleton_method parameter.reader_method do
11
- target.send(parameter.reader_method)
12
- end
13
- end
14
- writer_class.parameter_set.each do |parameter|
15
- if parameter.configurable?
16
- define_singleton_method parameter.writer_method do |value|
17
- if target.respond_to?(parameter.writer_method)
18
- target.send(
19
- parameter.writer_method,
20
- Values.resolve(value).append_argument(runtime_arguments))
21
- end
22
- end
23
- end
24
- end
10
+ instance_eval do
11
+ define_reader_methods(target, reader_class)
12
+ define_writer_methods(target, writer_class, runtime_arguments)
25
13
  end
26
14
  self.class.instance_eval do
27
15
  define_singleton_method :parameter_set do
@@ -29,5 +17,38 @@ module RakeFactory
29
17
  end
30
18
  end
31
19
  end
20
+
21
+ private
22
+
23
+ def define_reader_methods(target, reader_class)
24
+ reader_class.parameter_set.each do |parameter|
25
+ define_reader_method(target, parameter)
26
+ end
27
+ end
28
+
29
+ def define_reader_method(target, parameter)
30
+ define_singleton_method parameter.reader_method do
31
+ target.send(parameter.reader_method)
32
+ end
33
+ end
34
+
35
+ def define_writer_methods(target, writer_class, runtime_arguments)
36
+ writer_class.parameter_set.each do |parameter|
37
+ define_writer_method(target, parameter, runtime_arguments)
38
+ end
39
+ end
40
+
41
+ def define_writer_method(target, parameter, runtime_arguments)
42
+ return unless parameter.configurable?
43
+
44
+ define_singleton_method parameter.writer_method do |value|
45
+ if target.respond_to?(parameter.writer_method)
46
+ target.send(
47
+ parameter.writer_method,
48
+ Values.resolve(value).append_argument(runtime_arguments)
49
+ )
50
+ end
51
+ end
52
+ end
32
53
  end
33
54
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'parameter_set'
2
4
 
3
5
  module RakeFactory
@@ -7,7 +9,7 @@ module RakeFactory
7
9
  end
8
10
 
9
11
  def initialize(*args, &configuration_block)
10
- arity = self.method(:initialize).super_method.arity
12
+ arity = method(:initialize).super_method.arity
11
13
  super(*args.slice(0, arity), &configuration_block)
12
14
  setup_parameter_defaults
13
15
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rake/tasklib'
2
4
 
3
5
  require_relative 'parameters'
@@ -21,21 +23,9 @@ module RakeFactory
21
23
  def define_on(application)
22
24
  creator = self
23
25
 
24
- @task = application.define_task(
25
- Rake::Task,
26
- name,
27
- argument_names => prerequisites,
28
- order_only: order_only_prerequisites
29
- ) do |_, args|
30
- view = ParameterView.new(self, self.class, self.class, args)
31
- invoke_configuration_block_on(view, args)
32
- check_parameter_requirements
33
- invoke_actions(args)
34
- end
35
- @task.add_description(description)
36
- @task.instance_eval do
37
- define_singleton_method(:creator) { creator }
38
- end
26
+ define_task(application)
27
+ add_description
28
+ add_creator(creator)
39
29
 
40
30
  self
41
31
  end
@@ -47,5 +37,38 @@ module RakeFactory
47
37
  super(method, *args, &block)
48
38
  end
49
39
  end
40
+
41
+ def respond_to_missing?(method, include_private = false)
42
+ @task.respond_to?(method) || super
43
+ end
44
+
45
+ private
46
+
47
+ def parameter_view(args)
48
+ ParameterView.new(self, self.class, self.class, args)
49
+ end
50
+
51
+ def define_task(application)
52
+ @task = application.define_task(
53
+ Rake::Task,
54
+ name,
55
+ argument_names => prerequisites,
56
+ order_only: order_only_prerequisites
57
+ ) do |_, args|
58
+ invoke_configuration_block_on(parameter_view(args), args)
59
+ check_parameter_requirements
60
+ invoke_actions(args)
61
+ end
62
+ end
63
+
64
+ def add_description
65
+ @task.add_description(description)
66
+ end
67
+
68
+ def add_creator(creator)
69
+ @task.instance_eval do
70
+ define_singleton_method(:creator) { creator }
71
+ end
72
+ end
50
73
  end
51
74
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rake/tasklib'
2
4
 
3
5
  require_relative 'values'
@@ -27,19 +29,17 @@ module RakeFactory
27
29
  around_define(application) do
28
30
  self.class.tasks.each do |task_definition|
29
31
  task_definition
30
- .for_task_set(self)
31
- .define_on(application)
32
+ .for_task_set(self)
33
+ .define_on(application)
32
34
  end
33
35
  end
34
36
  self
35
37
  end
36
38
 
37
- def around_define(application)
39
+ def around_define(_application)
38
40
  yield
39
41
  end
40
42
 
41
- private
42
-
43
43
  class TaskArguments
44
44
  attr_reader :arguments, :task_set
45
45
 
@@ -53,21 +53,21 @@ module RakeFactory
53
53
  end
54
54
 
55
55
  def parameter_hash
56
- arguments.first.is_a?(Hash) ?
57
- arguments.first :
58
- {}
56
+ if arguments.first.is_a?(Hash)
57
+ arguments.first
58
+ else
59
+ {}
60
+ end
59
61
  end
60
62
 
61
63
  def resolve
62
- if arguments.empty?
63
- return [parameter_overrides]
64
- end
64
+ return [parameter_overrides] if arguments.empty?
65
65
 
66
66
  if arguments.first.is_a?(Hash)
67
67
  return [
68
- parameter_overrides
69
- .merge(process_parameter_hash(arguments.first)),
70
- *arguments.drop(1)
68
+ parameter_overrides
69
+ .merge(process_parameter_hash(arguments.first)),
70
+ *arguments.drop(1)
71
71
  ]
72
72
  end
73
73
 
@@ -108,9 +108,10 @@ module RakeFactory
108
108
  end
109
109
 
110
110
  def define_on(application)
111
- if should_define?
112
- klass.new(*resolve_arguments, &resolve_block).define_on(application)
113
- end
111
+ return unless should_define?
112
+
113
+ klass.new(*resolve_arguments, &resolve_block)
114
+ .define_on(application)
114
115
  end
115
116
 
116
117
  private
@@ -120,9 +121,11 @@ module RakeFactory
120
121
  end
121
122
 
122
123
  def should_define?
123
- task_arguments.parameter_hash.include?(:define_if) ?
124
- task_arguments.parameter_hash[:define_if].call(task_set) :
125
- true
124
+ if task_arguments.parameter_hash.include?(:define_if)
125
+ task_arguments.parameter_hash[:define_if].call(task_set)
126
+ else
127
+ true
128
+ end
126
129
  end
127
130
 
128
131
  def resolve_arguments
@@ -130,16 +133,24 @@ module RakeFactory
130
133
  end
131
134
 
132
135
  def resolve_block
133
- lambda do |t, args|
134
- if block.respond_to?(:call)
135
- block.call(*[task_set, t, args].slice(0, block.arity))
136
- end
137
- if task_set.configuration_block.respond_to?(:call)
138
- view = ParameterView.new(t, t.class, task_set.class, args)
139
- task_set.invoke_configuration_block_on(view, args)
140
- end
136
+ lambda do |task, args|
137
+ maybe_call_block(task, args)
138
+ maybe_call_configuration_block(task, args)
141
139
  end
142
140
  end
141
+
142
+ def maybe_call_configuration_block(task, args)
143
+ return unless task_set.configuration_block.respond_to?(:call)
144
+
145
+ view = ParameterView.new(task, task.class, task_set.class, args)
146
+ task_set.invoke_configuration_block_on(view, args)
147
+ end
148
+
149
+ def maybe_call_block(task, args)
150
+ return unless block.respond_to?(:call)
151
+
152
+ block.call(*[task_set, task, args].slice(0, block.arity))
153
+ end
143
154
  end
144
155
 
145
156
  private_constant :TaskArguments
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RakeFactory
2
4
  module Values
3
5
  def self.resolve(value)
@@ -28,11 +30,15 @@ module RakeFactory
28
30
  end
29
31
 
30
32
  def prepend_argument(argument)
31
- self.class.new([argument, *@pre_arguments], @post_arguments, &@block)
33
+ self.class.new(
34
+ [argument, *@pre_arguments], @post_arguments, &@block
35
+ )
32
36
  end
33
37
 
34
38
  def append_argument(argument)
35
- self.class.new(@pre_arguments, [*@post_arguments, argument], &@block)
39
+ self.class.new(
40
+ @pre_arguments, [*@post_arguments, argument], &@block
41
+ )
36
42
  end
37
43
 
38
44
  def evaluate(arguments)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RakeFactory
2
- VERSION = '0.30.0.pre.5'
4
+ VERSION = '0.30.0.pre.6'
3
5
  end
data/lib/rake_factory.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rake_factory/version'
2
4
  require 'rake_factory/task'
3
5
  require 'rake_factory/task_set'
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'rake_factory/version'
6
+
7
+ files = %w[
8
+ bin
9
+ lib
10
+ CODE_OF_CONDUCT.md
11
+ rake_factory.gemspec
12
+ Gemfile
13
+ LICENSE.txt
14
+ Rakefile
15
+ README.md
16
+ ]
17
+
18
+ Gem::Specification.new do |spec|
19
+ spec.name = 'rake_factory'
20
+ spec.version = RakeFactory::VERSION
21
+ spec.authors = ['InfraBlocks Maintainers']
22
+ spec.email = ['maintainers@infrablocks.io']
23
+
24
+ spec.summary =
25
+ 'Base classes and modules to aid in creating custom rake tasks.'
26
+ spec.description =
27
+ 'Provides base classes and modules to allow declarative definition of ' \
28
+ 'rake tasks.'
29
+ spec.homepage = 'https://github.com/infrablocks/rake_factory'
30
+ spec.license = 'MIT'
31
+
32
+ spec.files = `git ls-files -z`.split("\x0").select do |f|
33
+ f.match(/^(#{files.map { |g| Regexp.escape(g) }.join('|')})/)
34
+ end
35
+ spec.bindir = 'exe'
36
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
+ spec.require_paths = ['lib']
38
+
39
+ spec.required_ruby_version = '>= 2.7'
40
+
41
+ spec.add_dependency 'activesupport', '>= 4'
42
+ spec.add_dependency 'rake', '~> 13.0'
43
+
44
+ spec.add_development_dependency 'bundler'
45
+ spec.add_development_dependency 'fakefs'
46
+ spec.add_development_dependency 'gem-release'
47
+ spec.add_development_dependency 'rake'
48
+ spec.add_development_dependency 'rake_circle_ci'
49
+ spec.add_development_dependency 'rake_github'
50
+ spec.add_development_dependency 'rake_gpg'
51
+ spec.add_development_dependency 'rake_ssh'
52
+ spec.add_development_dependency 'rspec'
53
+ spec.add_development_dependency 'rubocop'
54
+ spec.add_development_dependency 'rubocop-rake'
55
+ spec.add_development_dependency 'rubocop-rspec'
56
+ spec.add_development_dependency 'simplecov'
57
+
58
+ spec.metadata['rubygems_mfa_required'] = 'false'
59
+ end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rake_factory
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.30.0.pre.5
4
+ version: 0.30.0.pre.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - InfraBlocks Maintainers
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-21 00:00:00.000000000 Z
11
+ date: 2022-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rake
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -25,21 +39,35 @@ dependencies:
25
39
  - !ruby/object:Gem::Version
26
40
  version: '13.0'
27
41
  - !ruby/object:Gem::Dependency
28
- name: activesupport
42
+ name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - ">="
32
46
  - !ruby/object:Gem::Version
33
- version: '4'
34
- type: :runtime
47
+ version: '0'
48
+ type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - ">="
39
53
  - !ruby/object:Gem::Version
40
- version: '4'
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
- name: bundler
56
+ name: fakefs
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: gem-release
43
71
  requirement: !ruby/object:Gem::Requirement
44
72
  requirements:
45
73
  - - ">="
@@ -95,7 +123,7 @@ dependencies:
95
123
  - !ruby/object:Gem::Version
96
124
  version: '0'
97
125
  - !ruby/object:Gem::Dependency
98
- name: rake_ssh
126
+ name: rake_gpg
99
127
  requirement: !ruby/object:Gem::Requirement
100
128
  requirements:
101
129
  - - ">="
@@ -109,7 +137,7 @@ dependencies:
109
137
  - !ruby/object:Gem::Version
110
138
  version: '0'
111
139
  - !ruby/object:Gem::Dependency
112
- name: rake_gpg
140
+ name: rake_ssh
113
141
  requirement: !ruby/object:Gem::Requirement
114
142
  requirements:
115
143
  - - ">="
@@ -137,7 +165,7 @@ dependencies:
137
165
  - !ruby/object:Gem::Version
138
166
  version: '0'
139
167
  - !ruby/object:Gem::Dependency
140
- name: gem-release
168
+ name: rubocop
141
169
  requirement: !ruby/object:Gem::Requirement
142
170
  requirements:
143
171
  - - ">="
@@ -151,7 +179,21 @@ dependencies:
151
179
  - !ruby/object:Gem::Version
152
180
  version: '0'
153
181
  - !ruby/object:Gem::Dependency
154
- name: fakefs
182
+ name: rubocop-rake
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: rubocop-rspec
155
197
  requirement: !ruby/object:Gem::Requirement
156
198
  requirements:
157
199
  - - ">="
@@ -211,10 +253,12 @@ files:
211
253
  - lib/rake_factory/task_set.rb
212
254
  - lib/rake_factory/values.rb
213
255
  - lib/rake_factory/version.rb
256
+ - rake_factory.gemspec
214
257
  homepage: https://github.com/infrablocks/rake_factory
215
258
  licenses:
216
259
  - MIT
217
- metadata: {}
260
+ metadata:
261
+ rubygems_mfa_required: 'false'
218
262
  post_install_message:
219
263
  rdoc_options: []
220
264
  require_paths: