Class: Welo::Relationship

Inherits:
Object
  • Object
show all
Defined in:
lib/welo/core/relationship.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

Raises:

  • (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

#kindsObject

The kinds of relationship



9
10
11
# File 'lib/welo/core/relationship.rb', line 9

def kinds
  @kinds
end

#klassObject

The klass of the related resource



12
13
14
# File 'lib/welo/core/relationship.rb', line 12

def klass
  @klass
end

#symObject

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

Returns:

  • (Boolean)


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

Returns:

  • (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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


31
32
33
# File 'lib/welo/core/relationship.rb', line 31

def one?
  kinds.include?(:one)
end