Skip to content

Commit c9f6adf

Browse files
authored
Take advantage of Forwardable module (#214)
1 parent 594b706 commit c9f6adf

File tree

6 files changed

+20
-21
lines changed

6 files changed

+20
-21
lines changed

lib/command/apply_template.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class ApplyTemplate < Base # rubocop:disable Metrics/ClassLength
4343
VALIDATIONS = %w[config templates].freeze
4444

4545
def call # rubocop:disable Metrics/MethodLength
46-
@template_parser = TemplateParser.new(config)
46+
@template_parser = TemplateParser.new(self)
4747
@names_to_filenames = config.args.to_h do |name|
4848
[name, @template_parser.template_filename(name)]
4949
end

lib/command/doctor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def call
2929
validations = config.options[:validations].split(",")
3030
ensure_required_options!(validations)
3131

32-
doctor_service = DoctorService.new(config)
32+
doctor_service = DoctorService.new(self)
3333
doctor_service.run_validations(validations)
3434
end
3535

lib/core/doctor_service.rb

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
class ValidationError < StandardError; end
44

55
class DoctorService
6-
attr_reader :config
6+
extend Forwardable
77

8-
def initialize(config)
9-
@config = config
8+
def_delegators :@command, :config, :progress
9+
10+
def initialize(command)
11+
@command = command
1012
end
1113

1214
def run_validations(validations, silent_if_passing: false) # rubocop:disable Metrics/MethodLength
@@ -37,7 +39,7 @@ def validate_config
3739
end
3840

3941
def validate_templates
40-
@template_parser = TemplateParser.new(config)
42+
@template_parser = TemplateParser.new(@command)
4143
filenames = Dir.glob("#{@template_parser.template_dir}/*.yml")
4244
templates = @template_parser.parse(filenames)
4345

@@ -97,8 +99,4 @@ def warn_deprecated_template_variables
9799
.join("\n")
98100
progress.puts("\n#{Shell.color("DEPRECATED: #{message}", :yellow)}\n#{list}\n\n")
99101
end
100-
101-
def progress
102-
$stderr
103-
end
104102
end

lib/core/maintenance_mode.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# frozen_string_literal: true
22

3-
require "forwardable"
4-
53
class MaintenanceMode
64
extend Forwardable
75

lib/core/template_parser.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
# frozen_string_literal: true
22

33
class TemplateParser
4-
attr_reader :config, :deprecated_variables
4+
extend Forwardable
55

6-
def initialize(config)
7-
@config = config
6+
def_delegators :@command, :config, :cp
7+
8+
attr_reader :deprecated_variables
9+
10+
def initialize(command)
11+
@command = command
812
end
913

1014
def template_dir
@@ -69,8 +73,4 @@ def new_variables
6973
"APP_IMAGE" => "{{APP_IMAGE}}"
7074
}
7175
end
72-
73-
def cp
74-
@cp ||= Controlplane.new(config)
75-
end
7676
end

lib/cpflow.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
require "date"
4+
require "forwardable"
45
require "dotenv/load"
56
require "cgi"
67
require "json"
@@ -226,12 +227,14 @@ def self.process_option_params(params)
226227

227228
Cpflow::Cli.show_info_header(config) if with_info_header
228229

230+
command = command_class.new(config)
231+
229232
if validations.any? && ENV.fetch("DISABLE_VALIDATIONS", nil) != "true"
230-
doctor = DoctorService.new(config)
233+
doctor = DoctorService.new(command)
231234
doctor.run_validations(validations, silent_if_passing: true)
232235
end
233236

234-
command_class.new(config).call
237+
command.call
235238
rescue RuntimeError => e
236239
::Shell.abort(e.message)
237240
end

0 commit comments

Comments
 (0)