Class: TableWarnings::Size

Inherits:
Object
  • Object
show all
Defined in:
lib/table_warnings/size.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table, approximate_size, options = {}) ⇒ Size

Returns a new instance of Size.



7
8
9
10
11
# File 'lib/table_warnings/size.rb', line 7

def initialize(table, approximate_size, options = {})
  @table = table
  @approximate_size = approximate_size
  @conditions = options[:conditions] || {}
end

Instance Attribute Details

#approximate_sizeObject (readonly)

Returns the value of attribute approximate_size.



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

def approximate_size
  @approximate_size
end

#conditionsObject (readonly)

Returns the value of attribute conditions.



5
6
7
# File 'lib/table_warnings/size.rb', line 5

def conditions
  @conditions
end

#tableObject (readonly)

Returns the value of attribute table.



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

def table
  @table
end

Instance Method Details

#messagesObject



13
14
15
16
17
18
19
20
21
22
# File 'lib/table_warnings/size.rb', line 13

def messages
  current_count = effective_count
  unless allowed_size.include? current_count
    if conditions.empty?
      "Row count is expected to be #{allowed_size.to_s}, but is #{current_count}"
    else
      "Row count with conditions #{conditions.inspect} is expected to be #{allowed_size.to_s}, but is #{current_count}"
    end
  end
end