Class: Togo::DataMapper::RelationshipManager
- Inherits:
-
Object
- Object
- Togo::DataMapper::RelationshipManager
- Defined in:
- lib/togo/model/relationship_manager/relationship_manager.rb
Class Method Summary collapse
Instance Method Summary collapse
- #find_for_assignment ⇒ Object
-
#initialize(content, relationship, opts = {}) ⇒ RelationshipManager
constructor
A new instance of RelationshipManager.
- #relate ⇒ Object
- #related_model ⇒ Object
- #unset_values ⇒ Object
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_assignment ⇒ Object
34 35 36 |
# File 'lib/togo/model/relationship_manager/relationship_manager.rb', line 34 def find_for_assignment raise NotImplementedError end |
#relate ⇒ Object
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 |
#related_model ⇒ Object
30 31 32 |
# File 'lib/togo/model/relationship_manager/relationship_manager.rb', line 30 def raise NotImplementedError end |
#unset_values ⇒ Object
26 27 28 |
# File 'lib/togo/model/relationship_manager/relationship_manager.rb', line 26 def unset_values raise NotImplementedError end |