Created
September 27, 2011 17:25
-
-
Save dasch/1245684 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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