Method: DataMapper::Property#assert_valid_options
- Defined in:
- lib/dm-core/property.rb
#assert_valid_options(options) ⇒ Object (protected)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 |
# File 'lib/dm-core/property.rb', line 773 def () keys = .keys if (unknown_keys = keys - self.class.).any? raise ArgumentError, "options #{unknown_keys.map { |key| key.inspect }.join(' and ')} are unknown" end .each do |key, value| boolean_value = value == true || value == false case key when :field assert_kind_of "options[:#{key}]", value, ::String when :default if value.nil? raise ArgumentError, "options[:#{key}] must not be nil" end when :serial, :key, :allow_nil, :allow_blank, :required, :auto_validation unless boolean_value raise ArgumentError, "options[:#{key}] must be either true or false" end if key == :required && (keys.include?(:allow_nil) || keys.include?(:allow_blank)) raise ArgumentError, 'options[:required] cannot be mixed with :allow_nil or :allow_blank' end when :index, :unique_index, :unique, :lazy unless boolean_value || value.kind_of?(Symbol) || (value.kind_of?(Array) && value.any? && value.all? { |val| val.kind_of?(Symbol) }) raise ArgumentError, "options[:#{key}] must be either true, false, a Symbol or an Array of Symbols" end when :length assert_kind_of "options[:#{key}]", value, Range, ::Integer when :size, :precision, :scale assert_kind_of "options[:#{key}]", value, ::Integer when :reader, :writer, :accessor assert_kind_of "options[:#{key}]", value, Symbol unless VISIBILITY_OPTIONS.include?(value) raise ArgumentError, "options[:#{key}] must be #{VISIBILITY_OPTIONS.join(' or ')}" end end end end |