Class: Togo::DataMapper::RelationshipManager

Inherits:
Object
  • Object
show all
Defined in:
lib/togo/model/relationship_manager/relationship_manager.rb

Direct Known Subclasses

ManyToOne, OneToMany

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content, relationship, opts = {}) ⇒ RelationshipManager

Returns a new instance of RelationshipManager.



14
15
16
17
18
19
# File 'lib/togo/model/relationship_manager/relationship_manager.rb', line 14

def initialize(content, relationship, opts = {})
  @content = content
  @relationship = relationship
  @relationship_name = relationship.name
  @ids = (opts[:ids] || '').split(',').map(&:to_i)
end

Class Method Details

.create(content, relationship, opts = {}) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/togo/model/relationship_manager/relationship_manager.rb', line 5

def self.create(content, relationship, opts = {})
  case relationship
  when ::DataMapper::Associations::ManyToOne::Relationship
    ManyToOne.new(content, relationship, opts)
  when ::DataMapper::Associations::OneToMany::Relationship
    OneToMany.new(content, relationship, opts)
  end
end

Instance Method Details

#find_for_assignmentObject

Raises:

  • (NotImplementedError)


34
35
36
# File 'lib/togo/model/relationship_manager/relationship_manager.rb', line 34

def find_for_assignment
  raise NotImplementedError
end

#relateObject



21
22
23
24
# File 'lib/togo/model/relationship_manager/relationship_manager.rb', line 21

def relate
  @content.send("#{@relationship_name}=", find_for_assignment)
  @content
end

Raises:

  • (NotImplementedError)


30
31
32
# File 'lib/togo/model/relationship_manager/relationship_manager.rb', line 30

def related_model
  raise NotImplementedError
end

#unset_valuesObject

Raises:

  • (NotImplementedError)


26
27
28
# File 'lib/togo/model/relationship_manager/relationship_manager.rb', line 26

def unset_values
  raise NotImplementedError
end