Class: Dbee::Model::Constraints::Static

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

Overview

A static constraint is a equality constraint on a child and/or parent column to a static value. It is usually used in conjunction with a ReferenceConstraint, further giving it more scoping.

Instance Attribute Summary collapse

Attributes inherited from Base

#name, #parent

Instance Method Summary collapse

Methods inherited from Base

#<=>

Constructor Details

#initialize(name: '', parent: '', value: nil) ⇒ Static

Returns a new instance of Static.



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

def initialize(name: '', parent: '', value: nil)
  if name.to_s.empty? && parent.to_s.empty?
    raise ArgumentError, "name (#{name}) and/or parent (#{parent}) required"
  end

  super(name: name, parent: parent)

  @value = value

  freeze
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



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

def value
  @value
end

Instance Method Details

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



37
38
39
# File 'lib/dbee/model/constraints/static.rb', line 37

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

#hashObject



33
34
35
# File 'lib/dbee/model/constraints/static.rb', line 33

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