Class: TableWarnings::Range

Inherits:
Exclusive show all
Defined in:
lib/table_warnings/range.rb

Instance Attribute Summary collapse

Attributes inherited from Exclusive

#conditions, #scout, #table

Instance Method Summary collapse

Methods inherited from Exclusive

#covers, #exclusives, #matches, #messages

Constructor Details

#initialize(table, matcher, options = {}) ⇒ Range

Returns a new instance of Range.



6
7
8
9
10
11
12
13
14
# File 'lib/table_warnings/range.rb', line 6

def initialize(table, matcher, options = {})
  super
  @min = options[:min]
  @max = options[:max]
  @allow_null_query = options[:allow_null]
  if min and max and min > max
    raise ArgumentError, "Min #{min.inspect} must be less than max #{max.inspect}"
  end
end

Instance Attribute Details

#maxObject (readonly)

Returns the value of attribute max.



3
4
5
# File 'lib/table_warnings/range.rb', line 3

def max
  @max
end

#minObject (readonly)

Returns the value of attribute min.



4
5
6
# File 'lib/table_warnings/range.rb', line 4

def min
  @min
end

Instance Method Details

#message(column) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/table_warnings/range.rb', line 16

def message(column)
  if column.values_outside?(min, max, conditions) or (not allow_null? and column.nulls?(conditions))
    if conditions.empty?
      "Unexpected range for #{column.name.inspect}. Min: #{column.min.inspect} (expected #{min.inspect}) Max: #{column.max.inspect} (expected #{max.inspect})"
    else
      "Unexpected range for #{column.name.inspect} in #{conditions.inspect}. Min: #{column.min.inspect} (expected #{min.inspect}) Max: #{column.max.inspect} (expected #{max.expect})"
    end
  end
end