Class: Dbee::Model::Constraints::Reference

Inherits:
Base
  • Object
show all
Defined in:
lib/dbee/model/constraints/reference.rb

Overview

A Reference constraint is a constraint between two data models. In DB terms: the name represents the column name on the child and the parent represents the column name on the parent table.

Instance Attribute Summary collapse

Attributes inherited from Base

#name

Instance Method Summary collapse

Constructor Details

#initialize(name:, parent:) ⇒ Reference

Returns a new instance of Reference.

Raises:

  • (ArgumentError)


21
22
23
24
25
26
27
28
29
# File 'lib/dbee/model/constraints/reference.rb', line 21

def initialize(name:, parent:)
  super(name: name)

  raise ArgumentError, 'parent is required' if parent.to_s.empty?

  @parent = parent.to_s

  freeze
end

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent.



19
20
21
# File 'lib/dbee/model/constraints/reference.rb', line 19

def parent
  @parent
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



35
36
37
# File 'lib/dbee/model/constraints/reference.rb', line 35

def ==(other)
  super && other.parent == parent
end

#hashObject



31
32
33
# File 'lib/dbee/model/constraints/reference.rb', line 31

def hash
  "#{super}#{parent}".hash
end