Module: TableWarnings

Defined in:
lib/table_warnings.rb,
lib/table_warnings/config.rb,
lib/table_warnings/version.rb,
lib/table_warnings/warning.rb,
lib/table_warnings/warning/size.rb,
lib/table_warnings/warning/blank.rb,
lib/table_warnings/warning/arbitrary.rb

Defined Under Namespace

Classes: Config, Warning

Constant Summary collapse

VERSION =
"0.0.6"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.configObject

:nodoc: all



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

def self.config #:nodoc: all
  Config.instance
end

Instance Method Details

#table_warningsObject

Get current warnings on the table.



12
13
14
# File 'lib/table_warnings.rb', line 12

def table_warnings
  ::TableWarnings.config.warnings[self].map { |w| w.messages }.flatten.compact.sort
end

#warn(&blk) ⇒ Object

An arbitrary warning.



42
43
44
45
# File 'lib/table_warnings.rb', line 42

def warn(&blk)
  warning = ::TableWarnings::Warning::Arbitrary.new :table => self, :blk => blk
  ::TableWarnings.config.warnings[self].add warning
end

#warn_if_any_blanksObject

Warn if there are blanks in ANY column.

Blank includes both NULL and “” (empty string)



27
28
29
30
# File 'lib/table_warnings.rb', line 27

def warn_if_any_blanks
  warning = ::TableWarnings::Warning::Blank.new :table => self
  ::TableWarnings.config.warnings[self].add warning
end

#warn_if_blanks_in(column_name) ⇒ Object

Warn if there are blanks in a certain column.

Blank includes both NULL and “” (empty string)



19
20
21
22
# File 'lib/table_warnings.rb', line 19

def warn_if_blanks_in(column_name)
  warning = ::TableWarnings::Warning::Blank.new :table => self, :column_name => column_name
  ::TableWarnings.config.warnings[self].add warning
end

#warn_unless_size_is(approximate_size) ⇒ Object

Warn if the number of records falls out of an (approximate) range.

Approximations: :few, :tens, :dozens, :hundreds, :thousands, :hundreds_of_thousands, :millions Exact: pass a Range or a Numeric



36
37
38
39
# File 'lib/table_warnings.rb', line 36

def warn_unless_size_is(approximate_size)
  warning = ::TableWarnings::Warning::Size.new :table => self, :approximate_size => approximate_size
  ::TableWarnings.config.warnings[self].add warning
end