Class: Fixably::CreateHasManyRecord

Inherits:
Object
  • Object
show all
Defined in:
lib/fixably/create_has_many_record.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(record:, collection:) ⇒ CreateHasManyRecord

Returns a new instance of CreateHasManyRecord.



12
13
14
15
# File 'lib/fixably/create_has_many_record.rb', line 12

def initialize(record:, collection:)
  @record = record
  @collection = collection
end

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



10
11
12
# File 'lib/fixably/create_has_many_record.rb', line 10

def collection
  @collection
end

#recordObject (readonly)

Returns the value of attribute record.



9
10
11
# File 'lib/fixably/create_has_many_record.rb', line 9

def record
  @record
end

Class Method Details

.call(record:, collection:) ⇒ Object



5
6
7
# File 'lib/fixably/create_has_many_record.rb', line 5

def self.call(record:, collection:)
  new(record: record, collection: collection).call
end

Instance Method Details

#callObject



17
18
19
20
21
# File 'lib/fixably/create_has_many_record.rb', line 17

def call
  can_append!
  save_record
  collection.elements << record
end