Class: Dbee::Model::Relationships::Basic

Inherits:
Object
  • Object
show all
Defined in:
lib/dbee/model/relationships/basic.rb

Overview

A relationship from one model to another.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, constraints: [], model: nil) ⇒ Basic

Returns a new instance of Basic.

Raises:

  • (ArgumentError)


19
20
21
22
23
24
25
26
27
# File 'lib/dbee/model/relationships/basic.rb', line 19

def initialize(name:, constraints: [], model: nil)
  @name = name
  raise ArgumentError, 'name is required' if name.to_s.empty?

  @constraints = Constraints.array(constraints || []).uniq
  @model = model

  freeze
end

Instance Attribute Details

#constraintsObject (readonly)

Returns the value of attribute constraints.



17
18
19
# File 'lib/dbee/model/relationships/basic.rb', line 17

def constraints
  @constraints
end

#modelObject (readonly)

Returns the value of attribute model.



17
18
19
# File 'lib/dbee/model/relationships/basic.rb', line 17

def model
  @model
end

#nameObject (readonly)

Returns the value of attribute name.



17
18
19
# File 'lib/dbee/model/relationships/basic.rb', line 17

def name
  @name
end

Instance Method Details

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



37
38
39
40
41
42
# File 'lib/dbee/model/relationships/basic.rb', line 37

def ==(other)
  other.instance_of?(self.class) &&
    other.name == name &&
    other.constraints == constraints &&
    other.model == model
end

#hashObject



33
34
35
# File 'lib/dbee/model/relationships/basic.rb', line 33

def hash
  [self.class.hash, name.hash, constraints.hash, model.hash].hash
end

#model_nameObject



29
30
31
# File 'lib/dbee/model/relationships/basic.rb', line 29

def model_name
  model || name
end