class Mv::Core::Validation::Builder::Length

Public Instance Methods

conditions() click to toggle source
# File lib/mv/core/validation/builder/length.rb, line 15
def conditions
  res = apply_in(column_reference) if self.in
  res = apply_within(column_reference) if within
  res = apply_is(column_reference) if self.is
  res = apply_maximum(column_reference) if maximum && !minimum
  res = apply_minimum(column_reference) if minimum && !maximum
  res = apply_minimum_and_maximum(column_reference) if minimum && maximum

  res.collect do |condition|
    { statement: apply_allow_nil_and_blank(condition[:statement]), message: condition[:message] }
  end
end

Protected Instance Methods

apply_in(stmt) click to toggle source
# File lib/mv/core/validation/builder/length.rb, line 38
def apply_in stmt
  [{ statement: self.in.is_a?(Range) ? "LENGTH(#{stmt}) BETWEEN #{self.in.min} AND #{self.in.max}" :
                                       "LENGTH(#{stmt}) IN (#{self.in.join(', ')})",
    message: message }]
end
apply_is(stmt) click to toggle source
# File lib/mv/core/validation/builder/length.rb, line 50
def apply_is stmt
  [{ statement: "LENGTH(#{stmt}) = #{self.is}", message: message }]
end
apply_maximum(stmt) click to toggle source
# File lib/mv/core/validation/builder/length.rb, line 54
def apply_maximum stmt
  [{ statement: "LENGTH(#{stmt}) <= #{maximum}", message: too_long || message }]
end
apply_minimum(stmt) click to toggle source
# File lib/mv/core/validation/builder/length.rb, line 58
def apply_minimum stmt
  [{ statement: "LENGTH(#{stmt}) >= #{minimum}", message: too_short || message }]
end
apply_minimum_and_maximum(stmt) click to toggle source
# File lib/mv/core/validation/builder/length.rb, line 62
def apply_minimum_and_maximum stmt
  if too_long == too_short
    [{ statement: "LENGTH(#{stmt}) BETWEEN #{minimum} AND #{maximum}",
      message: message }]
  else
    [apply_minimum(stmt), apply_maximum(stmt)].flatten
  end
end
apply_within(stmt) click to toggle source
# File lib/mv/core/validation/builder/length.rb, line 44
def apply_within stmt
  [{ statement: within.is_a?(Range) ? "LENGTH(#{stmt}) BETWEEN #{within.min} AND #{within.max}" :
                                      "LENGTH(#{stmt}) IN (#{within.join(', ')})",
    message: message }]
end
too_long() click to toggle source
# File lib/mv/core/validation/builder/length.rb, line 34
def too_long
  validation.full_too_long
end
too_short() click to toggle source
# File lib/mv/core/validation/builder/length.rb, line 30
def too_short
  validation.full_too_short
end