Class: Dbee::Model::Relationships::Basic
- Inherits:
-
Object
- Object
- Dbee::Model::Relationships::Basic
- Defined in:
- lib/dbee/model/relationships/basic.rb
Overview
A relationship from one model to another.
Instance Attribute Summary collapse
-
#constraints ⇒ Object
readonly
Returns the value of attribute constraints.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(name:, constraints: [], model: nil) ⇒ Basic
constructor
A new instance of Basic.
- #model_name ⇒ Object
Constructor Details
#initialize(name:, constraints: [], model: nil) ⇒ Basic
Returns a new instance of Basic.
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
#constraints ⇒ Object (readonly)
Returns the value of attribute constraints.
17 18 19 |
# File 'lib/dbee/model/relationships/basic.rb', line 17 def constraints @constraints end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
17 18 19 |
# File 'lib/dbee/model/relationships/basic.rb', line 17 def model @model end |
#name ⇒ Object (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 |
#hash ⇒ Object
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_name ⇒ Object
29 30 31 |
# File 'lib/dbee/model/relationships/basic.rb', line 29 def model_name model || name end |