Class: Copyable::OptionChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/copyable/option_checker.rb

Constant Summary collapse

VALID_OPTIONS =
[:override, :global_override, :skip_validations, :skip_associations]
VALID_PRIVATE_OPTIONS =

for copyable’s internal use only

[:__called_recursively]

Class Method Summary collapse

Class Method Details

.check!(options) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/copyable/option_checker.rb', line 7

def self.check!(options)
  unrecognized_options = options.keys - VALID_OPTIONS - VALID_PRIVATE_OPTIONS
  if unrecognized_options.any?
    message = "Unrecognized options passed to create_copy!:\n"
    unrecognized_options.each do |opt|
      message << "  #{opt.inspect}\n"
    end
    message << "The options passed to create_copy! can only be one of the following:\n"
    VALID_OPTIONS.each do |opt|
      message << "  #{opt.inspect}\n"
    end
    raise CopyableError.new(message)
  end
  # :skip_associations needs to be an array if it's present
  if (options[:skip_associations].present? && !options[:skip_associations].is_a?(Array))
    raise CopyableError.new("When :skip_associations is used, it must be an array")
  end
end