class Mongomatic::Expectations::OfLength

Public Class Methods

name() click to toggle source
# File lib/mongomatic/expectations/of_length.rb, line 4
def self.name
  "of_length"
end

Public Instance Methods

to_be() click to toggle source
# File lib/mongomatic/expectations/of_length.rb, line 8
def to_be
  return true if opts[:allow_nil] && value.nil?
    
  length = (value) ? value.size : value.to_s.size
  add_error_msg if opts[:minimum] && length < opts[:minimum]
  add_error_msg if opts[:maximum] && length > opts[:maximum]
  if opts[:range]
    add_error_msg unless opts[:range].include?(length)
  end  
end