Class: ForeignKeyChecker::Utils::BelongsTo::TableLevel
- Inherits:
-
Object
- Object
- ForeignKeyChecker::Utils::BelongsTo::TableLevel
- Defined in:
- lib/foreign_key_checker/utils/belongs_to.rb
Instance Attribute Summary collapse
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#columns_of_table ⇒ Object
readonly
Returns the value of attribute columns_of_table.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#fks ⇒ Object
readonly
Returns the value of attribute fks.
-
#polymorphic_suffixes ⇒ Object
readonly
Returns the value of attribute polymorphic_suffixes.
-
#table ⇒ Object
readonly
Returns the value of attribute table.
Instance Method Summary collapse
- #candidates ⇒ Object
- #foreign_key_suffix ⇒ Object
-
#initialize(connection, table, columns_of_table, polymorphic_suffixes, fks:, on_error: proc { }) ⇒ TableLevel
constructor
A new instance of TableLevel.
Constructor Details
#initialize(connection, table, columns_of_table, polymorphic_suffixes, fks:, on_error: proc { }) ⇒ TableLevel
Returns a new instance of TableLevel.
188 189 190 191 192 193 194 195 196 |
# File 'lib/foreign_key_checker/utils/belongs_to.rb', line 188 def initialize(connection, table, columns_of_table, polymorphic_suffixes, fks:, on_error: proc { } ) @connection = connection @table = table @columns = columns_of_table[table] @columns_of_table = columns_of_table @polymorphic_suffixes = polymorphic_suffixes @on_error = on_error @fks = fks end |
Instance Attribute Details
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
187 188 189 |
# File 'lib/foreign_key_checker/utils/belongs_to.rb', line 187 def columns @columns end |
#columns_of_table ⇒ Object (readonly)
Returns the value of attribute columns_of_table.
187 188 189 |
# File 'lib/foreign_key_checker/utils/belongs_to.rb', line 187 def columns_of_table @columns_of_table end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
187 188 189 |
# File 'lib/foreign_key_checker/utils/belongs_to.rb', line 187 def connection @connection end |
#fks ⇒ Object (readonly)
Returns the value of attribute fks.
187 188 189 |
# File 'lib/foreign_key_checker/utils/belongs_to.rb', line 187 def fks @fks end |
#polymorphic_suffixes ⇒ Object (readonly)
Returns the value of attribute polymorphic_suffixes.
187 188 189 |
# File 'lib/foreign_key_checker/utils/belongs_to.rb', line 187 def polymorphic_suffixes @polymorphic_suffixes end |
#table ⇒ Object (readonly)
Returns the value of attribute table.
187 188 189 |
# File 'lib/foreign_key_checker/utils/belongs_to.rb', line 187 def table @table end |
Instance Method Details
#candidates ⇒ Object
202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/foreign_key_checker/utils/belongs_to.rb', line 202 def candidates columns.select { |column| column.name.ends_with?(foreign_key_suffix) }.each_with_object([]) do |column, object| level = ColumnLevel.new(self, column) level.errors.each(&@on_error) [level.association].compact.each do |ass| next if fks.find { |fk| ass.conflict_with_fk?(fk) } object.push(ass) end end end |
#foreign_key_suffix ⇒ Object
198 199 200 |
# File 'lib/foreign_key_checker/utils/belongs_to.rb', line 198 def foreign_key_suffix '_id' end |