Skip to content

Commit

Permalink
rubocop: autofix
Browse files Browse the repository at this point in the history
  • Loading branch information
bastelfreak committed May 12, 2023
1 parent 679de39 commit dc6448e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
---
inherit_from: .rubocop_todo.yml

# Managed by modulesync - DO NOT EDIT
# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/

Expand Down
18 changes: 18 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2023-05-12 09:54:06 UTC using RuboCop version 1.22.3.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 4
# Configuration parameters: MaximumRangeSize.
Lint/MissingCopEnableDirective:
Exclude:
- 'spec/unit/puppetx/filemapper_spec.rb'

# Offense count: 37
# Configuration parameters: AllowSubject.
RSpec/MultipleMemoizedHelpers:
Max: 15
22 changes: 13 additions & 9 deletions lib/puppetx/filemapper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'puppet/util/filetype'

# Forward declaration
Expand All @@ -9,6 +11,7 @@ module PuppetX::FileMapper
# This method is necessary for the provider to be ensurable
def create
raise Puppet::Error, "#{self.class} is in an error state" if self.class.failed?

@resource.class.validproperties.each do |property|
@property_hash[property] = @resource.should(property) if @resource.should(property)
end
Expand Down Expand Up @@ -106,7 +109,7 @@ def instances
h[:ensure] = :present
new(h)
end
rescue
rescue StandardError
# If something failed while loading instances, mark the provider class
# as failed and pass the exception along
failed!
Expand All @@ -117,7 +120,7 @@ def instances
#
# @raise Puppet::DevError if an expected method is unavailable
def validate_class!
required_class_hooks = [:target_files, :parse_file, :format_file]
required_class_hooks = %i[target_files parse_file format_file]
required_instance_hooks = [:select_file]

required_class_hooks.each do |method|
Expand Down Expand Up @@ -168,10 +171,10 @@ def load_all_providers_from_disk
path = file_attrs[:filetype].path

next unless path.is_a?(Pathname) || path.respond_to?(:to_str)

arr = parse_file(filename, file_attrs[:filetype].read)
unless arr.is_a? Array
raise Puppet::DevError, "expected #{self}.parse_file to return an Array, got a #{arr.class}"
end
raise Puppet::DevError, "expected #{self}.parse_file to return an Array, got a #{arr.class}" unless arr.is_a? Array

provider_hashes.concat arr
end
provider_hashes
Expand Down Expand Up @@ -257,9 +260,7 @@ def flush_file(filename)
return
end

if !@mapped_files[filename][:dirty]
Puppet.debug "#{name} was requested to flush the file #{filename}, but it was not marked as dirty - doing nothing."
else
if @mapped_files[filename][:dirty]
# Collect all providers that should be present and pass them to the
# including class for formatting.
target_providers = collect_providers_for_file(filename)
Expand All @@ -275,8 +276,10 @@ def flush_file(filename)
ensure
post_flush_hook(filename) if respond_to? :post_flush_hook
end
else
Puppet.debug "#{name} was requested to flush the file #{filename}, but it was not marked as dirty - doing nothing."
end
rescue
rescue StandardError
# If something failed during the flush process, mark the provider as failed. There's not
# much we can do about any file that's already been flushed but we can stop smashing things.
@failed = true
Expand All @@ -300,6 +303,7 @@ def perform_write(filename, contents)
# @param [String] filename The file to remove
def remove_empty_file(filename)
return unless File.exist? filename

@mapped_files[filename][:filetype] ||= Puppet::Util::FileType.filetype(filetype).new(filename)
filetype = @mapped_files[filename][:filetype]

Expand Down
4 changes: 3 additions & 1 deletion spec/unit/puppetx/filemapper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'spec_helper'
require 'puppetx/filemapper'

Expand Down Expand Up @@ -273,7 +275,7 @@ def select_file
{ name: 'yay', dummy_property: 'baz' },
{ name: 'whee', dummy_property: 'wat' }
].each do |values|
it "should match hash values to provider properties for #{values[:name]}" do
it "matches hash values to provider properties for #{values[:name]}" do
provs = subject.instances
prov = provs.find { |foundprov| foundprov.name == values[:name] }
values.each_pair { |property, value| expect(prov.send(property)).to eq(value) }
Expand Down

0 comments on commit dc6448e

Please sign in to comment.