Class: ForeignKeyChecker::Result

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Result

Returns a new instance of Result.



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

def initialize(data)
  data.each do |key, value|
    instance_variable_set("@#{key}", value)
  end
end

Instance Attribute Details

#associationObject (readonly)

Returns the value of attribute association.



6
7
8
# File 'lib/foreign_key_checker.rb', line 6

def association
  @association
end

#modelObject (readonly)

Returns the value of attribute model.



6
7
8
# File 'lib/foreign_key_checker.rb', line 6

def model
  @model
end

Instance Method Details

#from_columnObject



21
22
23
# File 'lib/foreign_key_checker.rb', line 21

def from_column
  association.foreign_key
end

#from_tableObject



13
14
15
# File 'lib/foreign_key_checker.rb', line 13

def from_table
  model.table_name
end

#human_relationObject



29
30
31
# File 'lib/foreign_key_checker.rb', line 29

def human_relation
  "#{from_table} belongs_to #{to_table} (by column #{from_column} to #{to_column})"
end

#inspectObject



35
36
37
# File 'lib/foreign_key_checker.rb', line 35

def inspect
  "#<#{self.class.name}:#{self.object_id} #{message}>"
end

#messageObject



33
# File 'lib/foreign_key_checker.rb', line 33

def message; end

#nullable?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/foreign_key_checker.rb', line 39

def nullable?
  model.columns_hash[from_column.to_s].null
end

#to_columnObject



25
26
27
# File 'lib/foreign_key_checker.rb', line 25

def to_column
  association.klass.primary_key
end

#to_tableObject



17
18
19
# File 'lib/foreign_key_checker.rb', line 17

def to_table
  association.klass.table_name
end