Skip to content

Commit

Permalink
simplify check for script of the same name
Browse files Browse the repository at this point in the history
  • Loading branch information
ashton22305 committed Sep 26, 2024
1 parent b988ec6 commit 43289e6
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def self.build_auto_scripts(opts = {})

static_opts = {
options: options,
value: default_script_value(opts, options, dir)
value: default_script_value(opts, options)
}.merge(opts.without(:options, :value).to_h)

Attributes::AutoScripts.new('auto_scripts', static_opts)
Expand All @@ -28,13 +28,13 @@ def self.script_options_from_directory(dir)
end.sort_by(&:first)
end

def self.default_script_value(initial_opts, script_opts, dir)
def self.default_script_value(initial_opts, script_opts)
return nil if !initial_opts[:value] || script_opts.empty?

# Replace directory if the script is present in correct directory, otherwise delete value
swapped_dir = "#{dir}/#{File.basename(initial_opts[:value])}"
if script_opts.any?(swapped_dir)
initial_opts[:value] = swapped_dir
valid_opt = script_opts.select { |opt| opt.first == File.basename(initial_opts[:value]) }.first
if valid_opt
initial_opts[:value] = valid_opt.last
elsif script_opts&.none? { |opt| opt.include?(initial_opts[:value]) }
initial_opts.delete(:value)
end
Expand Down

0 comments on commit 43289e6

Please sign in to comment.