Class: Welo::Relationship
- Inherits:
-
Object
- Object
- Welo::Relationship
- Defined in:
- lib/welo/core/relationship.rb
Instance Attribute Summary collapse
-
#kinds ⇒ Object
The kinds of relationship.
-
#klass ⇒ Object
The klass of the related resource.
-
#sym ⇒ Object
The symbol for the method to call to get the related resource.
Class Method Summary collapse
-
.incompatible_kinds?(kinds) ⇒ Boolean
Returns true if the kinds are incompatible current incompatibilities: - :one and :many at the same time.
Instance Method Summary collapse
- #alias? ⇒ Boolean
-
#initialize(sym, klass, kinds) ⇒ Relationship
constructor
creates a new relationship for sym and klass, with all the given kinds providing incompatibles kinds lead to an ArgumentError.
-
#many? ⇒ Boolean
true if at least one of the kinds is :many.
-
#one? ⇒ Boolean
true if at least one of the kinds is :one.
Constructor Details
#initialize(sym, klass, kinds) ⇒ Relationship
creates a new relationship for sym and klass, with all the given kinds providing incompatibles kinds lead to an ArgumentError
23 24 25 26 27 28 |
# File 'lib/welo/core/relationship.rb', line 23 def initialize(sym, klass, kinds) raise ArgumentError, "incompatible kinds" if self.class.incompatible_kinds?(kinds) @sym = sym @klass = klass @kinds = kinds end |
Instance Attribute Details
#kinds ⇒ Object
The kinds of relationship
9 10 11 |
# File 'lib/welo/core/relationship.rb', line 9 def kinds @kinds end |
#klass ⇒ Object
The klass of the related resource
12 13 14 |
# File 'lib/welo/core/relationship.rb', line 12 def klass @klass end |
#sym ⇒ Object
The symbol for the method to call to get the related resource
6 7 8 |
# File 'lib/welo/core/relationship.rb', line 6 def sym @sym end |
Class Method Details
.incompatible_kinds?(kinds) ⇒ Boolean
Returns true if the kinds are incompatible current incompatibilities:
-
:one and :many at the same time
17 18 19 |
# File 'lib/welo/core/relationship.rb', line 17 def self.incompatible_kinds?(kinds) (kinds & [:one, :many]).size == 2 end |
Instance Method Details
#alias? ⇒ Boolean
40 41 42 |
# File 'lib/welo/core/relationship.rb', line 40 def alias? kinds.include?(:alias) end |
#many? ⇒ Boolean
true if at least one of the kinds is :many
36 37 38 |
# File 'lib/welo/core/relationship.rb', line 36 def many? kinds.include?(:many) end |
#one? ⇒ Boolean
true if at least one of the kinds is :one
31 32 33 |
# File 'lib/welo/core/relationship.rb', line 31 def one? kinds.include?(:one) end |