Class: ProblemMerge

Inherits:
Object
  • Object
show all
Defined in:
app/interactors/problem_merge.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*problems) ⇒ ProblemMerge

Returns a new instance of ProblemMerge

Raises:

  • (ArgumentError)

4
5
6
7
8
9
# File 'app/interactors/problem_merge.rb', line 4

def initialize(*problems)
  problems = problems.flatten.uniq
  @merged_problem = problems[0]
  @child_problems = problems[1..-1]
  raise ArgumentError.new("need almost 2 uniq different problems") if @child_problems.empty?
end

Instance Attribute Details

#child_problemsObject (readonly)

Returns the value of attribute child_problems


10
11
12
# File 'app/interactors/problem_merge.rb', line 10

def child_problems
  @child_problems
end

#merged_problemObject (readonly)

Returns the value of attribute merged_problem


10
11
12
# File 'app/interactors/problem_merge.rb', line 10

def merged_problem
  @merged_problem
end

Instance Method Details

#mergeObject


12
13
14
15
16
17
18
19
20
21
# File 'app/interactors/problem_merge.rb', line 12

def merge
  child_problems.each do |problem|
    merged_problem.errs.concat problem.errs
    merged_problem.comments.concat problem.comments
    problem.reload # deference all associate objet to avoid delete him after
    ProblemDestroy.execute(problem)
  end
  reset_cached_attributes
  merged_problem
end