Module: SuperModel::Associations

Included in:
SuperModel
Defined in:
lib/super_model/associations.rb,
lib/super_model/associations/has_one.rb,
lib/super_model/associations/has_many.rb,
lib/super_model/associations/belongs_to.rb

Overview

SuperModel::Associations adds associations for standard Ruby objects and provides a base for ORMs to add their own association functionality.

This module must be included in a Class.

Defined Under Namespace

Modules: BelongsTo, HasMany, HasOne

Class Method Summary collapse

Class Method Details

.extend_with_associations(receiver) ⇒ Object



29
30
31
32
33
# File 'lib/super_model/associations.rb', line 29

def extend_with_associations(receiver)
  receiver.extend(HasOne)
  receiver.extend(HasMany)
  receiver.extend(BelongsTo)
end

.extended(receiver) ⇒ Object



39
40
41
# File 'lib/super_model/associations.rb', line 39

def extended(receiver)
  extend_with_associations(receiver)
end

.foreign_key_for(resource_name, plurality) ⇒ Object



23
24
25
26
27
# File 'lib/super_model/associations.rb', line 23

def foreign_key_for(resource_name, plurality)
  Error::InvalidPlurality.check(plurality)
  
  "#{resource_name}_id".send("#{ plurality }ize")
end

.included(receiver) ⇒ Object



35
36
37
# File 'lib/super_model/associations.rb', line 35

def included(receiver)
  extend_with_associations(receiver)
end

.sanitize_resource_name(resource_name, plurality) ⇒ Object



17
18
19
20
21
# File 'lib/super_model/associations.rb', line 17

def sanitize_resource_name(resource_name, plurality)
  Error::InvalidPlurality.check(plurality)
  
  resource_name.to_s.send("#{ plurality }ize").underscore
end