Sha256: 62517d0466e9dbbabddc1fc8f3472c59d3ee1acbeb3e5d94476884d46ad84f14

Contents?: true

Size: 1016 Bytes

Versions: 3

Compression:

Stored size: 1016 Bytes

Contents

module Copyable
  class OptionChecker

    VALID_OPTIONS = [:override, :skip_validations, :skip_associations]
    VALID_PRIVATE_OPTIONS = [:__called_recursively]  # for copyable's internal use only

    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

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
copyable-0.1.2 lib/copyable/option_checker.rb
copyable-0.1.1 lib/copyable/option_checker.rb
copyable-0.1.0 lib/copyable/option_checker.rb