Class: ForeignKeyChecker::ForeignKeyResult

Inherits:
Result
  • Object
show all
Defined in:
lib/foreign_key_checker.rb

Instance Attribute Summary collapse

Attributes inherited from Result

#association, #model

Instance Method Summary collapse

Methods inherited from Result

#from_column, #from_table, #human_relation, #initialize, #inspect, #nullable?, #to_column, #to_table

Constructor Details

This class inherits a constructor from ForeignKeyChecker::Result

Instance Attribute Details

#scopeObject (readonly)

Returns the value of attribute scope.



46
47
48
# File 'lib/foreign_key_checker.rb', line 46

def scope
  @scope
end

Instance Method Details

#messageObject



47
48
49
# File 'lib/foreign_key_checker.rb', line 47

def message
  "There is no foreign_key for relation #{human_relation}\n"
end

#migrationObject



51
52
53
54
55
56
57
# File 'lib/foreign_key_checker.rb', line 51

def migration
  "add_foreign_key :#{from_table}, :#{to_table}#{
    ", column: :#{from_column}" if from_column.to_s != "#{to_table.singularize}_id"
  }#{
    ", primary_key: :#{to_column}" if to_column.to_s != 'id'
  }"
end

#to_zombieObject



59
60
61
# File 'lib/foreign_key_checker.rb', line 59

def to_zombie
  ZombieResult.new(scope: scope, model: model, association: association)
end