Skip to content

Commit 8553e18

Browse files
committed
Consistent variable naming
1 parent 3c4eec0 commit 8553e18

File tree

2 files changed

+32
-26
lines changed

2 files changed

+32
-26
lines changed

lib/octocatalog-diff/catalog.rb

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ def build(logger = Logger.new(StringIO.new))
9191
@resource_hash = nil
9292

9393
# Invoke the backend's build method, if there is one. There's a stub below in case there's not.
94+
logger.debug "Calling build for object #{self.class}"
9495
build_catalog(logger)
9596

9697
# Perform post-generation processing of the catalog
@@ -99,7 +100,13 @@ def build(logger = Logger.new(StringIO.new))
99100
validate_references
100101
return unless valid?
101102

102-
convert_file_resources(logger)
103+
if supports_compare_file_text?
104+
convert_file_resources(logger)
105+
elsif @options[:compare_file_text]
106+
logger.debug "Disabling --compare-file-text; not supported by #{self.class}"
107+
end
108+
109+
true
103110
end
104111

105112
# Stub method if the backend does not contain a build method.
@@ -137,10 +144,12 @@ def compilation_dir=(dir)
137144
@override_compilation_dir = dir
138145
end
139146

140-
# Stub method for "convert_file_resources" to avoid errors if the backend doesn't support this.
141-
# @return [Boolean] True
142-
def convert_file_resources(logger = Logger.new(StringIO.new))
143-
logger.debug "Disabling --compare-file-text; not supported by #{self.class}"
147+
# Stub method for "convert_file_resources" to raise an error if the backend doesn't support this.
148+
# Getting here is expected to be a bug condition.
149+
def convert_file_resources(_logger = Logger.new(StringIO.new))
150+
# :nocov:
151+
raise "convert_file_resources was called on but is not supported by #{self.class}"
152+
# :nocov:
144153
end
145154

146155
# Retrieve the error message.

lib/octocatalog-diff/catalog/computed.rb

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def initialize(options)
3030
super
3131

3232
raise ArgumentError, 'Node name must be passed to OctocatalogDiff::Catalog::Computed' unless options[:node].is_a?(String)
33+
raise ArgumentError, 'Branch is undefined' unless options[:branch]
3334

3435
# Additional class variables
3536
@pass_env_vars = options.fetch(:pass_env_vars, [])
@@ -41,17 +42,13 @@ def initialize(options)
4142
@retries = nil
4243
@builddir = nil
4344
@facts_terminus = options.fetch(:facts_terminus, 'yaml')
44-
45-
# Pass through the input for other access
46-
@opts = options
47-
raise ArgumentError, 'Branch is undefined' unless @opts[:branch]
4845
end
4946

5047
# Get the Puppet version
5148
# @return [String] Puppet version
5249
def puppet_version
5350
raise ArgumentError, '"puppet_binary" was not passed to OctocatalogDiff::Catalog::Computed' unless @puppet_binary
54-
@puppet_version ||= OctocatalogDiff::Util::PuppetVersion.puppet_version(@puppet_binary, @opts)
51+
@puppet_version ||= OctocatalogDiff::Util::PuppetVersion.puppet_version(@puppet_binary, @options)
5552
end
5653

5754
# Compilation directory
@@ -63,7 +60,7 @@ def compilation_dir
6360

6461
# Environment used to compile catalog
6562
def environment
66-
@opts.fetch(:environment, 'production')
63+
@options.fetch(:environment, 'production')
6764
end
6865

6966
# Convert file source => ... to content => ... if a basedir is given.
@@ -97,29 +94,29 @@ def bootstrap(logger)
9794
return if @builddir
9895

9996
# Fill options for creating and populating the temporary directory
100-
tmphash = @opts.dup
97+
tmphash = @options.dup
10198

10299
# Bootstrap directory if needed
103-
if !@opts[:bootstrapped_dir].nil?
104-
raise Errno::ENOENT, "Invalid dir #{@opts[:bootstrapped_dir]}" unless File.directory?(@opts[:bootstrapped_dir])
105-
tmphash[:basedir] = @opts[:bootstrapped_dir]
106-
elsif @opts[:branch] == '.'
107-
if @opts[:bootstrap_current]
100+
if !@options[:bootstrapped_dir].nil?
101+
raise Errno::ENOENT, "Invalid dir #{@options[:bootstrapped_dir]}" unless File.directory?(@options[:bootstrapped_dir])
102+
tmphash[:basedir] = @options[:bootstrapped_dir]
103+
elsif @options[:branch] == '.'
104+
if @options[:bootstrap_current]
108105
tmphash[:basedir] = Dir.mktmpdir
109106
at_exit { cleanup_checkout_dir(tmphash[:basedir], logger) }
110107

111-
FileUtils.cp_r File.join(@opts[:basedir], '.'), tmphash[:basedir]
108+
FileUtils.cp_r File.join(@options[:basedir], '.'), tmphash[:basedir]
112109

113-
o = @opts.reject { |k, _v| k == :branch }.merge(path: tmphash[:basedir])
110+
o = @options.reject { |k, _v| k == :branch }.merge(path: tmphash[:basedir])
114111
OctocatalogDiff::CatalogUtil::Bootstrap.bootstrap_directory(o, logger)
115112
else
116-
tmphash[:basedir] = @opts[:basedir]
113+
tmphash[:basedir] = @options[:basedir]
117114
end
118115
else
119116
checkout_dir = Dir.mktmpdir
120117
at_exit { cleanup_checkout_dir(checkout_dir, logger) }
121118
tmphash[:basedir] = checkout_dir
122-
OctocatalogDiff::CatalogUtil::Bootstrap.bootstrap_directory(@opts.merge(path: checkout_dir), logger)
119+
OctocatalogDiff::CatalogUtil::Bootstrap.bootstrap_directory(@options.merge(path: checkout_dir), logger)
123120
end
124121

125122
# Create and populate the temporary directory
@@ -130,9 +127,9 @@ def bootstrap(logger)
130127
# @param logger [Logger] Logger object
131128
def build_catalog(logger)
132129
if @facts_terminus != 'facter'
133-
facts_obj = OctocatalogDiff::CatalogUtil::Facts.new(@opts, logger)
130+
facts_obj = OctocatalogDiff::CatalogUtil::Facts.new(@options, logger)
134131
logger.debug "Start retrieving facts for #{@node} from #{self.class}"
135-
@opts[:facts] = facts_obj.facts
132+
@options[:facts] = facts_obj.facts
136133
logger.debug "Success retrieving facts for #{@node} from #{self.class}"
137134
end
138135

@@ -166,10 +163,10 @@ def puppet_command_obj
166163
@puppet_command_obj ||= begin
167164
raise ArgumentError, '"puppet_binary" was not passed to OctocatalogDiff::Catalog::Computed' unless @puppet_binary
168165

169-
command_opts = @opts.merge(
166+
command_opts = @options.merge(
170167
node: @node,
171168
compilation_dir: @builddir.tempdir,
172-
parser: @opts.fetch(:parser, :default),
169+
parser: @options.fetch(:parser, :default),
173170
puppet_binary: @puppet_binary,
174171
fact_file: @builddir.fact_file,
175172
dir: @builddir.tempdir,
@@ -199,7 +196,7 @@ def exec_puppet(logger)
199196
# Set up the ScriptRunner
200197
scriptrunner = OctocatalogDiff::Util::ScriptRunner.new(
201198
default_script: 'puppet/puppet.sh',
202-
override_script_path: @opts[:override_script_path]
199+
override_script_path: @options[:override_script_path]
203200
)
204201

205202
begin

0 commit comments

Comments
 (0)