-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Remove safe_yaml. #2397
Remove safe_yaml. #2397
Changes from all commits
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 |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
require 'rails_admin/extensions/history' | ||
require 'rails_admin/support/csv_converter' | ||
require 'rails_admin/support/hash_helper' | ||
require 'yaml' | ||
|
||
module RailsAdmin | ||
# Setup RailsAdmin | ||
|
@@ -33,6 +34,28 @@ def self.config(entity = nil, &block) | |
RailsAdmin::Config | ||
end | ||
end | ||
|
||
# Backwards-compatible with safe_yaml/load when SafeYAML isn't available. | ||
# Evaluates available YAML loaders at boot and creates appropriate method, | ||
# so no conditionals are required at runtime. | ||
begin | ||
require 'safe_yaml/load' | ||
def self.yaml_load(yaml) | ||
SafeYAML.load(yaml) | ||
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. define |
||
rescue LoadError | ||
if YAML.respond_to?(:safe_load) | ||
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. define |
||
def self.yaml_load(yaml) | ||
YAML.safe_load(yaml) | ||
end | ||
else | ||
raise LoadError.new "Safe-loading of YAML is not available. Please install 'safe_yaml' or install Psych 2.0+" | ||
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. Fail with useful warning if user does not have safe_yaml or Psych 2.0+ |
||
end | ||
|
||
def self.yaml_dump(object) | ||
YAML.dump(object) | ||
end | ||
end | ||
|
||
require 'rails_admin/bootstrap-sass' unless defined? Bootstrap |
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.
two conditions for defining
RailsAdmin.yaml_load
depending on available gems. But the nicest part is, that this method can be customized by any end user :)