Skip to content

Commit

Permalink
Support a maximum version in pin_modules rake task
Browse files Browse the repository at this point in the history
  • Loading branch information
ekohl committed May 1, 2024
1 parent 24a81c7 commit 5a6e880
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
8 changes: 8 additions & 0 deletions spec/util/fake_puppet_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@
expect { |b| fake.content(&b) }.to yield_with_args("mod 'theforeman/motd', '>= 1.2'")
end

specify 'with a minimum and a maximum' do
expect(PuppetForge::Module).not_to receive(:find)

fake.instance_eval { mod 'theforeman/motd', '>= 1.2', '< 3' }

expect { |b| fake.content(&b) }.to yield_with_args("mod 'theforeman/motd', '>= 1.2', '< 3'")
end

specify 'with a git url' do
expect(PuppetForge::Module).to receive(:find)
.with('theforeman-motd')
Expand Down
14 changes: 7 additions & 7 deletions util/fake_puppet_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ def forge(url)
PuppetForge.host = url
end

def mod(name, options = nil)
if options.is_a?(Hash) && !options.include?(:ref)
def mod(name, *version, **options)
if options.any? && !options.include?(:ref)
release = PuppetForge::Module.find(name.tr('/', '-')).current_release
@new_content << ['mod', name, "~> #{release.version}"]
@new_content << ['mod', name, ["~> #{release.version}"]]
else
@new_content << ['mod', name, options]
@new_content << ['mod', name, version]
end
end

Expand All @@ -28,11 +28,11 @@ def content
yield "forge '#{value}'"
yield ""
elsif type == 'mod'
if options.nil?
if options.empty?
yield "mod '#{value}'"
elsif options.is_a?(String)
elsif options.is_a?(Array)
padding = ' ' * (max_length - value.length)
yield "mod '#{value}', #{padding}'#{options}'"
yield "mod '#{value}', #{padding}#{options.map { |version| "'#{version}'" }.join(', ')}"
else
padding = ' ' * (max_length - value.length)
yield "mod '#{value}', #{padding}#{options.map { |k, v| ":#{k} => '#{v}'" }.join(', ')}"
Expand Down

0 comments on commit 5a6e880

Please sign in to comment.