-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Launcher save fixed attributes #3784
Changes from 17 commits
0eba218
6df0e0c
f221f5c
a51806e
a38979c
e21b5fb
15e48f4
d90bf55
a2a483b
c464638
e444b4c
485e021
4b2af25
b988ec6
43289e6
27fe98e
91a343b
40d653b
a66184e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,8 +13,9 @@ def self.build_auto_scripts(opts = {}) | |
options = script_options_from_directory(dir) | ||
|
||
static_opts = { | ||
options: options | ||
}.merge(opts.without(:options).to_h) | ||
options: options, | ||
value: default_script_value(opts, options) | ||
}.merge(opts.without(:options, :value).to_h) | ||
|
||
Attributes::AutoScripts.new('auto_scripts', static_opts) | ||
end | ||
|
@@ -26,6 +27,20 @@ def self.script_options_from_directory(dir) | |
[File.basename(file), file] | ||
end.sort_by(&:first) | ||
end | ||
|
||
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 | ||
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 | ||
|
||
(initial_opts[:value] || script_opts.first.last).to_s | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm struggling to understand this. I think because it does 2 things - potentially modifies Can we restructure this so it just has the return value with no modification to the things passed into it? When I was investigating the tests, I came up with this - I also think a simple name change (and type change of the first argument) helped me figure out what it's attempting to do. # called through default_value(opts[:default], options)
def self.default_value(default, scripts)
if scripts.empty?
nil
elsif default.nil? || default.to_s.empty?
scripts.first[1]
elsif scripts.map { |s| s[1] }.include?(default)
default
else
scripts.first[1]
end
end |
||
end | ||
|
||
module Attributes | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you submit the changes to this file in another pull request? I can't just glance at this to see what it is, so I'll need more time to look it over.