Class: Vericred::Relationships::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/vericred/api_resource/relationships/base.rb

Direct Known Subclasses

BelongsTo, HasMany

Instance Method Summary collapse

Constructor Details

#initialize(owner_klass, type) ⇒ Base

Returns a new instance of Base.



4
5
6
7
# File 'lib/vericred/api_resource/relationships/base.rb', line 4

def initialize(owner_klass, type)
  @owner_klass = owner_klass
  @type = type
end

Instance Method Details

#owned_klassObject



9
10
11
# File 'lib/vericred/api_resource/relationships/base.rb', line 9

def owned_klass
  @owned_klass ||= Vericred.const_get(type.to_s.classify)
end

#plural?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/vericred/api_resource/relationships/base.rb', line 13

def plural?
  !singular?
end

#root_nameObject



21
22
23
# File 'lib/vericred/api_resource/relationships/base.rb', line 21

def root_name
  owned_klass.root_name.pluralize
end

#singular?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/vericred/api_resource/relationships/base.rb', line 17

def singular?
  fail NotImplementedError, 'must implement #singular?'
end