Class: AwardEmojis::CopyService

Inherits:
Object
  • Object
show all
Defined in:
app/services/award_emojis/copy_service.rb

Instance Method Summary collapse

Constructor Details

#initialize(from_awardable, to_awardable) ⇒ CopyService

Returns a new instance of CopyService.

Raises:

  • (ArgumentError)

9
10
11
12
13
14
# File 'app/services/award_emojis/copy_service.rb', line 9

def initialize(from_awardable, to_awardable)
  raise ArgumentError, 'Awardables must be different' if from_awardable == to_awardable

  @from_awardable = from_awardable
  @to_awardable = to_awardable
end

Instance Method Details

#executeObject


16
17
18
19
20
21
22
23
24
# File 'app/services/award_emojis/copy_service.rb', line 16

def execute
  from_awardable.award_emoji.find_each do |award|
    new_award = award.dup
    new_award.awardable = to_awardable
    new_award.save!
  end

  ServiceResponse.success
end