-
-
Notifications
You must be signed in to change notification settings - Fork 229
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
Default settings #2699
Labels
Comments
Possible approaches (none of the code was executed/tested): 1. Merge defaults on boot
BELONGS_TO_DEFAULTS = {
searchable: false,
can_create: true
}
USER_BELONGS_TO_DEFAULTS = {
searchable: true,
can_create: true
}
def initialize(id, **args, &block)
# ...
@searchable = args[:searchable].nil? ? BELONGS_TO_DEFAULTS[:searchable] : args[:searchable]
@can_create = args[:can_create].nil? ? BELONGS_TO_DEFAULTS[:can_create] : args[:can_create]
# ...
end
def initialize(id, **args, &block)
# ...
initialize_option :searchable, args
initialize_option :can_create, args
# ...
end
def initialize_option(option, args)
user_option = args.dig(option)
instance_variable_set(:"@#{option}", user_option.nil? ? BELONGS_TO_DEFAULTS.dig(option) : user_option)
end 2. Check for user default on each initialize
USER_BELONGS_TO_DEFAULTS = {
searchable: true,
can_create: true
}
def initialize(id, **args, &block)
# ...
@searchable = if args[:searchable].nil?
user_default = USER_BELONGS_TO_DEFAULTS[:searchable]
user_default.nil? ? false : user_default
else
args[:searchable]
end
@can_create = if args[:can_create].nil?
user_default = USER_BELONGS_TO_DEFAULTS[:can_create]
user_default.nil? ? true : user_default
else
args[:can_create]
end
# ...
end
def initialize(id, **args, &block)
# ...
initialize_option :searchable, args
initialize_option :can_create, args
# ...
end
def initialize_option(option, args)
user_option = args.dig(option)
value = if user_option.nil?
user_default = USER_BELONGS_TO_DEFAULTS.dig(option)
user_default.nil? ? false : user_default
else
user_option
end
instance_variable_set(:"@#{option}", value)
end Things to have in consideration
|
This issue has been marked as stale because there was no activity for the past 15 days. |
adrianthedev
added
Enhancement
New feature or request
Configuration
Task
Something to get done
and removed
Stale
labels
May 4, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Context
We want to give the ability to developers to set certain settings to a certain value globally.
For example, set all the
belongs_to
fields to have thesearchable
value totrue
.Explorations
The text was updated successfully, but these errors were encountered: