Skip to content

Commit

Permalink
Refactor patch to make the replication works
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagopradi committed Oct 31, 2017
1 parent ee7e86a commit 382c099
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
1 change: 1 addition & 0 deletions lib/octopus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ def self.fully_replicated(&_block)
require 'octopus/shard_tracking/dynamic'

require 'octopus/model'
require 'octopus/result_patch'
require 'octopus/migration'
require 'octopus/association'
require 'octopus/collection_association'
Expand Down
20 changes: 0 additions & 20 deletions lib/octopus/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,23 +208,3 @@ def octopus_set_table_name(value = nil)
end

ActiveRecord::Base.extend(Octopus::Model)

module SampleFoooBar
attr_accessor :current_shard

private

def hash_rows
if current_shard.blank?
super
else
foo = super
foo.each { |f| f.merge!('current_shard' => current_shard) }
foo
end
end
end

class ActiveRecord::Result
prepend SampleFoooBar
end
19 changes: 19 additions & 0 deletions lib/octopus/result_patch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module Octopus::ResultPatch
attr_accessor :current_shard

private

def hash_rows
if current_shard.blank?
super
else
foo = super
foo.each { |f| f.merge!('current_shard' => current_shard) }
foo
end
end
end

class ActiveRecord::Result
prepend Octopus::ResultPatch
end

0 comments on commit 382c099

Please sign in to comment.