Skip to content

Commit

Permalink
Merge pull request #69 from rmm5t/cleanup
Browse files Browse the repository at this point in the history
Refactor and cleanup option handling
  • Loading branch information
rmm5t authored Jul 17, 2024
2 parents 623010b + d27aee4 commit ee90fbc
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions lib/strip_attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,19 @@ def self.strip_string(value, options = {})
# Necessary because Rails has removed the narrowing of attributes using :only
# and :except on Base#attributes
def self.narrow(attributes, options = {})
if except = options[:except]
except = Array(except).collect { |attribute| attribute.to_s }
if options[:except]
except = Array(options[:except]).map(&:to_s)
attributes.except(*except)
elsif only = options[:only]
only = Array(only).collect { |attribute| attribute.to_s }
elsif options[:only]
only = Array(options[:only]).map(&:to_s)
attributes.slice(*only)
else
attributes
end
end

def self.validate_options(options)
if keys = options.keys
unless (keys - VALID_OPTIONS).empty?
raise ArgumentError, "Options does not specify #{VALID_OPTIONS} (#{options.keys.inspect})"
end
end
return if (options.keys - VALID_OPTIONS).empty?
raise ArgumentError, "Options does not specify #{VALID_OPTIONS} (#{options.keys.inspect})"
end
end

0 comments on commit ee90fbc

Please sign in to comment.