Skip to content

Instantly share code, notes, and snippets.

@dasch
Created September 27, 2011 17:25
Show Gist options
  • Save dasch/1245684 to your computer and use it in GitHub Desktop.
Save dasch/1245684 to your computer and use it in GitHub Desktop.
class Issue < ActiveRecord::Base
# This is a very simplifed version of the old method.
def merge_issues(sources, options = {})
target = self
comment = options[:comment]
transaction do
sources.each do |source|
source.merge_into(target, :comment => comment)
end
end
end
end
class IssueMerger
# This is where I'd like to go.
def self.merge(options = {})
target = options[:target]
sources = options[:sources]
comment = options[:comment]
# After my original tweet I switched to using a dependency container; I
# set a class variable to ActiveRecord::Base in a Rails initializer. If
# not set, it's a dummy that simply calls the block. This feels slightly
# overengineered, but allows me to stub everything out in my tests.
transaction do
sources.each do |source|
source.merge_into(target, :comment => comment)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment