require "active_patterns" # Declares service object for merging ActiveRecord instances. # # After extending your active record model with the module, # new ::merge_all method is available. # module ActiveMerge extend ActiveSupport::Autoload autoload :SimpleService autoload :Service # Merges instances from the association # # class Lord < ActiveRecord::Base # extend ActiveMerge # end # # Lord.all.merge_all # => merges all the class instances # Lord.where("id > :id", id: 100) # => merges instances with id > 100 # # See details in ActiveMerge::Service#provide documentation. # def merge_all ActiveMerge::Service.new(all).provide end end