Class: BlockScore::Collection::Member

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/blockscore/collection/member.rb

Overview

Member of a BlockScore::Collection class

Instance Method Summary collapse

Constructor Details

#initialize(parent, instance) ⇒ undefined

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize a new member

Parameters:



13
14
15
16
17
18
# File 'lib/blockscore/collection/member.rb', line 13

def initialize(parent, instance)
  @instance = instance
  @parent = parent

  super(instance)
end

Instance Method Details

#saveObject

Save parent, set parent id, and save instance

Examples:

# saves both unsaved person and unsaved question_set
person = Person.new(attributes)
question_set = QuestionSet.new
Member.new(person, question_set).save

Returns:

  • return value of instance ‘#save`



31
32
33
34
35
36
37
# File 'lib/blockscore/collection/member.rb', line 31

def save
  save_parent
  send(:"#{parent_name}_id=", parent.id)
  result = instance.save
  ids.push(instance.id) unless ids.include?(instance.id)
  result
end