Class: TableWarnings::Scout
- Inherits:
-
Object
- Object
- TableWarnings::Scout
- Defined in:
- lib/table_warnings/scout.rb
Instance Attribute Summary collapse
-
#conditions ⇒ Object
readonly
Returns the value of attribute conditions.
-
#matcher ⇒ Object
readonly
Returns the value of attribute matcher.
-
#table ⇒ Object
readonly
Returns the value of attribute table.
Instance Method Summary collapse
- #cover?(column) ⇒ Boolean
- #enable_association_check! ⇒ Object
- #exclusive?(column) ⇒ Boolean
-
#initialize(table, matcher, options = {}) ⇒ Scout
constructor
A new instance of Scout.
- #match?(column) ⇒ Boolean
Constructor Details
#initialize(table, matcher, options = {}) ⇒ Scout
Returns a new instance of Scout.
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/table_warnings/scout.rb', line 7 def initialize(table, matcher, = {}) @table = table @matcher = matcher @positive_query = ([:negative] != true) @conditions_query = case [:conditions] when String true when Hash, Array ![:conditions].empty? else false end end |
Instance Attribute Details
#conditions ⇒ Object (readonly)
Returns the value of attribute conditions.
5 6 7 |
# File 'lib/table_warnings/scout.rb', line 5 def conditions @conditions end |
#matcher ⇒ Object (readonly)
Returns the value of attribute matcher.
4 5 6 |
# File 'lib/table_warnings/scout.rb', line 4 def matcher @matcher end |
#table ⇒ Object (readonly)
Returns the value of attribute table.
3 4 5 |
# File 'lib/table_warnings/scout.rb', line 3 def table @table end |
Instance Method Details
#cover?(column) ⇒ Boolean
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/table_warnings/scout.rb', line 36 def cover?(column) column_name = column.name if association_check? associations.any? do |a| a.foreign_key == column_name end else case matcher when Regexp !!(column_name =~ matcher) else column_name.to_s == matcher.to_s end end end |
#enable_association_check! ⇒ Object
52 53 54 |
# File 'lib/table_warnings/scout.rb', line 52 def enable_association_check! @association_check_query = true end |
#exclusive?(column) ⇒ Boolean
21 22 23 |
# File 'lib/table_warnings/scout.rb', line 21 def exclusive?(column) match?(column) and unambiguous? end |
#match?(column) ⇒ Boolean
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/table_warnings/scout.rb', line 25 def match?(column) if association_check? and not column.association return false end if positive? cover? column else not cover?(column) end end |